在Freemarker中转换Thymeleaf“ th:field”

时间:2018-11-07 18:49:40

标签: java spring thymeleaf freemarker

我将我的项目从Thymeleaf转换为Freemaker。我有一个问题。现在,我将尝试对其进行描述。

在我网站的主页上有供应商列表和一个搜索字段,用于按名称搜索供应商。

在Thymeleaf中看起来像这样-

控制器:

 @GetMapping("/vendors")
public String getAllVendors(Model model,@PageableDefault Pageable pageable){
    Page<Vendors> vendors = vendorRepository.findAll(pageable);
    model.addAttribute("searchVendor",new Foo()); //This is for search field
    model.addAttribute("url","/vendors");
    model.addAttribute("vendors",vendors);

    return "vendors/list";
}

Foo类:

@Getter
@Setter
public class Foo {
    private List<Long> checkedItems; // for checkboxes
    private List<Long> checkedItemsPlus; //for checkboxes
    private String findItem; // to find by the name
    private Long findSupply; // to find by the id
    private String findItemPlus; // to find by the second name
}

胸腺模板(用于搜索字段的表单):

 <form th:action="@{/showVendor}" method="post" class="form-inline">
    <input type="search" class="form-control mr-sm-2" 
      th:field="${searchVendor.findItem}" placeholder="Search By Name"/>
      <button type="submit" class="btn btn-outline-success">
         Search
      </button>
  </form>
  

$ {searchVendor.findItem}-这是输入名称的字符串   被写。

控制器

@PostMapping("/showVendor")
public String getVendorBySearch(Model model,@ModelAttribute("searchVendor") Foo foo){

model.addAttribute("vendors",
      vendorService.getVendorByName(foo.getFindItem()));

return "vendors/show";

}

那与Thymeleaf都可以正常工作。

在Freemaker中,我仅更改了我的百里香模板-

Freemaker模板

 <form action="/showVendor" method="post" class="form-inline">
     <input type="search" class="form-control mr-sm-2" value="${searchVendor.findItem}" id="findItem" name="findItem" placeholder="Search By Name"/>
      <button type="submit" class="btn btn-outline-success my-2 my-sm-0">Search</button>
 </form>
  

我不确定,但是将 th:field 替换为值,ID,名称

     

然后我单击按钮,我遇到此错误-

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Nov 07 21:42:23 MSK 2018
There was an unexpected error (type=Forbidden, status=403).
Forbidden
  

还有我最后的问题。如何将Thymeleaf的th:field替换为   Freemaker?我做对了还是需要做其他事情?为什么会出现此错误?

0 个答案:

没有答案