Thymeleaf 实战应用
input 、textarea 赋值
【JAVA】
@RequestMapping(value = {
"formData", "" })
public String list(HttpServletRequest request, ModelMap model) {
Entity entity = xxxService.getEntity();
model.addAttribute("entity", entity);
return "test.html";
}
【HTML】
- input输入框
<input type="text" th:attr="name=${entity.name},required=${entity.propRequired}" placeholder="请输入"/>
- textarea 文本域
<textarea th:text="${entity.remarks=='null'?'':entity.remarks}" placeholder="请输入"></textarea>
复选框 判断选中
【JAVA】
@RequestMapping(value = {
"checkboxValue", "" })
public String list(HttpServletRequest request, ModelMap model) {
Entity entity = xxxService.getEntity();
model.addAttribute("entity", entity);
return "test.html";
}
【HTML】
<input type="checkbox" th:checked="${entity.prop1 eq '1'}"> aaa
<input type="checkbox" th:checked="${entity.prop2 eq '1'}"> bbb
下拉框 动态赋值 与 回显
【JAVA】