thymeleaf 实例
来源:互联网 发布:淘宝消保30元的条件 编辑:程序博客网 时间:2024/06/05 16:19
package com.nroad.heartserver.model;import org.hibernate.validator.constraints.NotEmpty;import org.hibernate.validator.constraints.Range;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;/** * Created by jiyy on 2017/1/3. */public class AnimalForm { private long id; @NotEmpty(message="动物名: 不能为空") private String oname; @Range(min = 1, message="数量: 必须大于0") @NotNull(message="数量: 不能为空") private int ocount; @Size(max = 10, message="备注: 长度不能超过10个字符") private String memo; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getOname() { return oname; } public void setOname(String oname) { this.oname = oname; } public int getOcount() { return ocount; } public void setOcount(int ocount) { this.ocount = ocount; } public String getMemo() { return memo; } public void setMemo(String memo) { this.memo = memo; }}
package com.nroad.heartserver.controller;import com.nroad.heartserver.model.AnimalForm;import org.springframework.stereotype.Controller;import org.springframework.validation.BindingResult;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import javax.validation.Valid;/** * Created by jiyy on 2017/1/3. */@Controllerpublic class AnimalController { @RequestMapping("/tohtml") public ModelAndView algorithmConfiguration(){ ModelAndView model = new ModelAndView(); model.addObject("animalForm",new AnimalForm()); model.addObject("animalFormU",new AnimalForm()); model.setViewName("/test/zoolist"); return model; } /* @RequestMapping(path = "/list", params = {"save"}, method = RequestMethod.POST) public String doAdd(Model model, @Valid AnimalForm form, BindingResult result){ System.out.println("动物名:" + form.getOname()); System.out.println("数量:" + form.getOcount()); System.out.println("备注:" + form.getMemo()); if(result.hasErrors()){ model.addAttribute("MSG", "出错啦!"); }else{ model.addAttribute("MSG", "提交成功!"); } return "/test/zoolist"; }*/ @RequestMapping(path = "/list", params = {"save"}, method = RequestMethod.POST) public ModelAndView doAdd(@Valid AnimalForm form, BindingResult result){ ModelAndView model = new ModelAndView(); System.out.println("动物名:" + form.getOname()); System.out.println("数量:" + form.getOcount()); System.out.println("备注:" + form.getMemo()); if(result.hasErrors()){ model.addObject("MSG", "出错啦!"); }else{ model.addObject("MSG", "提交成功!"); } model.setViewName("/test/zoolist"); return model; } /*@RequestMapping(path = "/list", params = {"save"}, method = RequestMethod.POST) public ModelAndView doAdd(ModelAndView model, @Valid AnimalForm form, BindingResult result){ System.out.println("动物名:" + form.getOname()); System.out.println("数量:" + form.getOcount()); System.out.println("备注:" + form.getMemo()); if(result.hasErrors()){ model.addObject("MSG", "出错啦!"); }else{ model.addObject("MSG", "提交成功!"); } model.setViewName("/test/zoolist"); return model; } @RequestMapping(path = "/list", params = {"save"}, method = RequestMethod.POST) public String doAdd(@Valid AnimalForm form, BindingResult result){ System.out.println("动物名:" + form.getOname()); System.out.println("数量:" + form.getOcount()); System.out.println("备注:" + form.getMemo()); return "/test/zoolist"; }*/}
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>zoo list</title></head><body><!--<a href='.'>首页</a>->动物列表--><br/><br/><div th:text="${MSG}">这里是信息提示.</div><br/><div th:errors="${animalForm.oname}"></div><div th:errors="${animalForm.ocount}"></div><div th:errors="${animalForm.memo}"></div><br/><form id="iform" th:action="@{/list.html?save}" th:method="post" th:object="${animalForm}"> <table border="1"> <tr> <th>动物名称</th> <th>数量</th> <th>备注</th> <th>Action</th> </tr> <tr> <td><input type="text" name="oname" value="" th:value="*{oname}"/><br/><b th:errors="${animalForm.oname}"/></td> <td><input type="text" name="ocount" value="" th:value="*{ocount}"/><br/><b th:errors="${animalForm.ocount}"/></td> <td><input type="text" name="memo" value="" th:value="*{memo}"/><br/><b th:errors="${animalForm.memo}"/></td> <td><input type="submit" value="添加"/></td> </tr> </table></form><form id="uform" th:action="@{/list.html?save}" th:method="post" th:object="${animalFormU}"> <table border="1"> <tr> <th>动物名称</th> <th>数量</th> <th>备注</th> <th>Action</th> </tr> <tr> <td><input type="text" name="oname" value="" th:value="*{oname}"/><br/><b th:errors="${animalFormU.oname}"/></td> <td><input type="text" name="ocount" value="" th:value="*{ocount}"/><br/><b th:errors="${animalFormU.ocount}"/></td> <td><input type="text" name="memo" value="" th:value="*{memo}"/><br/><b th:errors="${animalFormU.memo}"/></td> <td><input type="submit" value="添加"/></td> </tr> </table></form><hr/><table border="1"> <tr> <th>序号</th> <th>动物名称</th> <th>数量</th> <th>备注</th> </tr> <tr> <td>1</td> <td>大马猴</td> <td>10</td> <td>机灵古怪,俏皮活泼</td> </tr> <tr> <td>2</td> <td>大熊猫</td> <td>80</td> <td>体型笨重,喜欢吃竹子</td> </tr> <tr> <td>3</td> <td>澳洲羊驼</td> <td>13</td> <td>长相奇特,大国人俗称其草泥马</td> </tr> <tr> <td>4</td> <td>峨眉山猴</td> <td>90</td> <td>不怕人,有时候发贱抢游客面包吃</td> </tr></table></body></html>
0 0
- thymeleaf 实例
- SpringBoot Thymeleaf web实例
- SpringBoot + Thymeleaf 整合实例讲解
- Thymeleaf
- thymeleaf
- thymeleaf
- Thymeleaf
- Thymeleaf
- Thymeleaf
- Thymeleaf
- Thymeleaf
- Thymeleaf
- Thymeleaf
- spring Boot 集成 Thymeleaf模板引擎实例
- Thymeleaf 学习笔记-实例demo(中文教程)
- 详解注解配置整合Spring MVC+Thymeleaf整合实例
- Thymeleaf 3.0 自定义标签方言属性,简单实例。快速学习!
- Java集成thymeleaf视图层模板引擎构建web项目实例讲解(附项目源码)
- 2440超详细uboot移植笔记(四)------剪裁uboot
- 解析eclipse控制台
- mysql 5.7 主从同步配置(windows)
- JdbcTemplate中RowMapper的粗浅理解
- Android
- thymeleaf 实例
- Toolbar设置回退箭头的方法
- 455. Assign Cookies
- 数据结构----二分图匹配----KM算法详解
- windows 编译dshow相关程序报错error LNK2001 无法解析外部符号 _IID_IPin
- dfs南阳32题组合数
- bzoj1505: [NOI2004]小H的小屋
- elasticsearch限制内网访问 限制多个ip访问
- Windows Styles