Spring Mvc 表单数据与Controller中模型(Model)的映射
来源:互联网 发布:电子书下载 知乎 编辑:程序博客网 时间:2024/06/12 20:54
Controller方法中配置的Model中包含了在Controller方法中自定义的参数,此参数在Model中的key等于类名首字母小写。
thymeleafFacmily.html
......<form th:action="@{/thymeleafFamily}" th:object="${family}" method="post" style="border: 1px solid greenyellow"><span th:text="#{family.name}"></span> <input type="text" th:field="*{name}" /><br/> <span th:text="#{family.totalZiChan}"></span><input type="text" th:field="*{totalZiChan}" /><br/> <span th:text="#{family.createDate}"></span><input type="text" th:field="*{createDate}" th:errorclass="fielderror_box" />......<input type="submit" id="btnAddID" name="btnAdd" value="ADD" /></form>......
ThymeleafController.java
......@RequestMapping(path = "/thymeleafFamily", params = {"btnAdd"}) public String thymeleafFamilyAdd( ModelMap model, Family familySubmit , BindingResult bindingResult, RedirectAttributes redirectAttributes){ if(bindingResult.hasErrors()){ return "thymeleafFamily"; } Family family = (Family) model.get("family"); familyService.addFamily(familySubmit); model.clear(); return "redirect:thymeleafFamily"; } ......
从上图中可以看到前端submit的数据转换成了类Family,映射在model.key=’family’以及contoller对应的参数familySubmit映射,且二者指向的都是同一个实例。
结论
Controller中指定了模型就不需要在指定单独的映射参数。
阅读全文
0 0
- Spring Mvc 表单数据与Controller中模型(Model)的映射
- Spring MVC 表单与控制器间model对象映射的一些注意事项
- spring mvc中controller怎么接收页面表单提交的数据
- spring mvc中controller怎么接收页面表单提交的数据
- Spring MVC中Controller如何获取Form表单提交的数据
- Spring mvc中把表单数据当做一个对象提交给controller的实现
- spring mvc中controller怎么接受页面表单提交的数据
- MVC模型(Model+View+Controller)
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- spring mvc 文件上传 controller中接收form表单中提交上来的文件
- MVC中Controller与View之间的数据传递
- spring中实现Controller接口的映射
- Spring MVC Fast Tutorial: Model View Controller
- spring mvc 获取所有的controller和url映射关系
- spring mvc中常用的几个controller
- spring mvc中常见的几个controller
- 贴一个比较实用的maven发布项目到服务器的插件
- 两种不同方法验证-10000以内满足哥德巴赫猜想的数
- HashMap集合中的TreeMap集合
- 修改电话中新通话记录无法立即显示联系人姓名问题
- 正则表达式30分钟入门教程
- Spring Mvc 表单数据与Controller中模型(Model)的映射
- Dockerfile文件详解
- TensoFlow
- ASP.NET MVC4 实体代码连接数据据
- 转:C语言中如何将二维数组作为函数的参数传递
- pycharm和anaconda2和3共存
- Hadoop
- sh里 时间格式的写法
- Hbase1.2.0以后 JavaAPI最新接口调用方法