SpringBoot----thymeleaf的修改数据页面简单例子35

📅 发布时间:2026/7/28 14:39:29
SpringBoot----thymeleaf的修改数据页面简单例子35 这里的修改和添加页面是同一个如下简单的html代码为示例form th:action{/emp} methodpost !--需要区分是员工数据-- !-- 1.springMVC中配置了HiddenHttpMethodFilter;(SpringBoot自动配置好的) 2.页面创建一个post表单 3.创建一个input项name_method;值就是我们指定的请求方式。 -- input typehidden name_method th:valueput th:if${emp!null} / input typehidden nameid th:value${emp.id} th:if${emp!null} div classform‐group labelLastName/label input namelastName typetext classform-control placeholder姓名 th:value${emp!null}?${emp.lastName} /div div classform‐group labelEmail/label input nameemail typeemail classform-control placeholder邮箱 th:value${emp!null}?${emp.email} /div div classform‐group labelGender/labelbr/ div classform-check form-check-inline input classform-check-input typeradio namegender value1 th:checked${emp!null}?${emp.gender}1 label classform-check-label男/label /div div classform-check form-check-inline input classform-check-input typeradio namegender value0 th:checked${emp!null}?${emp.gender}0 label classform-check-label女/label /div /div div classform-group labeldepartment/label select classform-control namedepartment.id option th:selected${emp!null}?${de.id}${emp.department.id} th:value${de.id} th:eachde:${departments} th:text${de.departmentName}/option /select /div div classform-group labelBirth/label input namebirth typetext classform-control placeholder生日 th:value${emp!null}?${#dates.format(emp.birth,yyyy-MM-dd HH:mm:ss)} /div button typesubmit classbtn btn-primary th:text${empnull?添加:修改}添加/button /form第一步回显数据,给value属性赋值用checked赋值用selected赋值第二步通过判断对象是否为空来决定是否回显添加页面不回显empnull?第三步点击修改发送put请求1.springMVC中配置了HiddenHttpMethodFilter;(SpringBoot自动配置好的) 2.页面创建一个post表单 3.创建一个input项name_method;值就是我们指定的请求方式。如下注意input项需要在form里面才有用input typehidden name_method th:valueput th:if${emp!null} /第四步添加数据的IDinput typehidden nameid th:value${emp.id} th:if${emp!null}