@ModelAttribute有俩个位置,一个是在方法体中,下面这个demo的用意就是每次controller@RequestMapping方法被调用之前都会走这个方法,并向Model中(@RequestMapping函数参数的Model)中添加这个返回值,key的值是返回类的首字母小写,比如这个就是key="sysUserMapping";
 @ModelAttribute
public SysUserMapping get(@RequestParam(required = false) String id) {
SysUserMapping entity = null;
if (StringUtils.isNotBlank(id)) {
entity = sysUserMappingService.get(id);
}
if (entity == null) {
entity = new SysUserMapping();
}
return entity;
} @RequestMapping(value = "form")
public String form(Model model) {
return "platform/usermapping/sysUserMappingForm";
}

  对于form这个函数,即使什么也不做,此时你通过model.containsAttribute(“sysUserMapping”),你将会看到是存在值的。@ModelAttribute还有一个用途就是放在@RequestMapping的函数的参数前面,代表该参数和View绑定的对象做映射,当然前提是当初在获取页面的时候就要在页面中的Model中通过addAttribute进行添加。

Spring RESTful之@ModelAttribute的更多相关文章

  1. cxf spring restful 问题解决(jar包冲突)

    SEVERE: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error ...

  2. Spring MVC 中 @ModelAttribute 注解的妙用

    Spring MVC 中 @ModelAttribute 注解的妙用 Spring MVC 提供的这种基于注释的编程模型,极大的简化了 web 应用的开发.其中 @Controller 和 @Rest ...

  3. 测试必须学spring RESTful Service(上)

    文末我会说说为什么测试必须学spring. REST REST,是指REpresentational State Transfer,有个精辟的解释什么是RESTful, 看url就知道要什么 看met ...

  4. Spring MVC 对于@ModelAttribute 、@SessionAttributes 的详细处理流程

    初学 Spring MVC , 感觉对于 @ModelAttribute 和 @SessionAttributes 是如何被Spring MVC处理的,这一流程不是很清楚, 经过Google资料,有了 ...

  5. Spring RESTFul Client – RestTemplate Example--转载

    原文地址:http://howtodoinjava.com/2015/02/20/spring-restful-client-resttemplate-example/ After learning ...

  6. 002 Spring Restful案例

    1:工程结构 需要注意的是需要额外导入以下三个包: jackson-annotations-2.6.1.jar jackson-core-2.6.1.jar jackson-databind-2.6. ...

  7. 采用CXF+spring+restful创建一个web接口项目

    这篇文章是http://blog.csdn.net/zxnlmj/article/details/28880303下面,加入的基础上的restful特征 1.参加restful必jar包裹 jsr31 ...

  8. spring mvc:注解@ModelAttribute妙用

    在Spring mvc中,注解@ModelAttribute是一个非常常用的注解,其功能主要在两方面: 运用在参数上,会将客户端传递过来的参数按名称注入到指定对象中,并且会将这个对象自动加入Model ...

  9. 实现Spring RESTful服务的SSL

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt386 本文介绍如何让基于Spring的REST服务变得SSL/TSL化. 首 ...

随机推荐

  1. 三重Des对称加密在Android、Ios 和Java 平台的实现

    引言      如今手机app五彩缤纷,确保手机用户的数据安全是开发人员必须掌握的技巧,下面通过实例介绍DES在android.ios.java平台的使用方法: DES加密是目前最常用的对称加密方式, ...

  2. C++多线程2.beginthread

    C++ 多线程2 beginthread 启动线程知识 20131021 Reference: http://blog.csdn.net/laoyang360/article/details/7720 ...

  3. poj3686

    题解: KM算法 把每一个点拆成n个 然后改变编圈 代码: #include<cstdio> #include<cmath> #include<cstring> # ...

  4. zoj1654

    题解: 对于每一联通的x,y 检点 然后交叉的连边 然后二分图 代码: #include<cstdio> #include<cstring> #include<cmath ...

  5. New Concept English Two 33 94

    $课文92  自找麻烦 1016. It must have been about two in the morning when I returned home. 我回到家时,肯定已是凌晨两点左右了 ...

  6. New Concept English three (23)

    31w 45 People become quite illogical when they try to decide what can be eaten and what cannot be ea ...

  7. Linux .o a .so .la .lo的区别

    o: 编译的目标文件a: 静态库,其实就是把若干o文件打了个包so: 动态链接库(共享库) lo: 使用libtool编译出的目标文件,其实就是在o文件中添加了一些信息la: 使用libtool编译出 ...

  8. (转) MapReduce Design Patterns(chapter 2 (part 1))(二)

     CHAPTER 2 .Summarization Patterns 随着每天都有更多的数据加载进系统,数据量变得很庞大.这一章专注于对你的数据顶层的,概括性意见的设计模式,从而使你能扩展思路,但可能 ...

  9. Vim技能修炼教程(15) - 时间和日期相关函数

    Vimscript武器库 前面我们走马观花地将Vimscript的大致语法过了一遍.下面我们开始深入看一下Vimscript都给我们准备了哪些武器.如果只用这些武器就够了,那么就太好了,只用Vimsc ...

  10. matlab linux的安装(第二次)

    1 挂载 2 下载jdk,matlab里面那个不行,缺点东西 3 安装 ./install *** 4 激活,非在线 5 license.lic路径在百度云中有 6 运行路径在你安装过程中的选的路径, ...