<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
@RequestMapping(value = "/add")//, method = RequestMethod.POST public ModelAndView zsUserAdd(ModelAndView mode) { mode.setViewName("zsUser/user_addOrEdit"); mode.addObject("userinfo", "添加用户"); ZsUserInfo zsUserInfo = new ZsUserInfo(); zsUserInfo.setStatus("adduser"); mode.addObject("zsUserInfo",zsUserInfo); return mode; }
<form class="form-horizontal" th:action="@{/zsUser/save}" th:method="post" th:object="${zsUserInfo}" id="submit_user_info" enctype="multipart/form-data" style="display: block"> <div class="box-body"> <h4 class="box-title">基本信息</h4> <!-- 判断界面是新增仍是编辑界面 start--> <input type="hidden" class="form-control" id="status" name="status" th:field="*{status}" > <!-- 判断界面是新增仍是编辑界面 end--> <div class="form-group"> <label class="col-sm-1 control-label">用户名</label> <div class="col-sm-3"> <input type="text" class="form-control" name="userName" th:field="*{userName}" > <input type="hidden" class="form-control" id="userId" name="userId" value="" > </div> <label class="col-sm-1 control-label">昵称</label> <div class="col-sm-3"> <input type="text" name="nickName" id="nickName" class="form-control" value="" th:field="*{nickName}" > </div> </div> </form>
后续完善html
# ================================================ # Thymeleaf配置 # ================================================ # 是否启用thymeleaf模板解析 spring.thymeleaf.enabled=true # 是否开启模板缓存(建议:开发环境下设置为false,生产环境设置为true) spring.thymeleaf.cache=false # Check that the templates location exists. spring.thymeleaf.check-template-location=true # 模板的媒体类型设置,默认为text/html spring.thymeleaf.content-type=text/html # 模板的编码设置,默认UTF-8 spring.thymeleaf.encoding=UTF-8 # 设置能够被解析的视图,以逗号,分隔 #spring.thymeleaf.view-names= # 排除不须要被解析视图,以逗号,分隔 #spring.thymeleaf.excluded-view-names= # 模板模式设置,默认为HTML5 #spring.thymeleaf.mode=HTML5 # 前缀设置,SpringBoot默认模板放置在classpath:/template/目录下 spring.thymeleaf.prefix=classpath:/templates/ # 后缀设置,默认为.html spring.thymeleaf.suffix=.html # 模板在模板链中被解析的顺序 #spring.thymeleaf.template-resolver-order=