发布时间 : 星期一 文章基于注解的springMVC更新完毕开始阅读49fd8542b307e87101f696e6
的prefix的值+requestMapping返回的值+suffix的值 第二种:返回一个String类型:
/**
* 根据String字符串返回对应的地址 prefix前缀+返回值+suffix后缀组成 * */
@RequestMapping(\) public String string() {
logger.info(\方法调用\); return \; }
第三种:返回一个ModelAndView对象
/**
* spring2.5的方法,返回一个ModelAndView 对象,通过setViewName方法跳转到指定的页面 调用addObject * 相当于调用request.setAttribute方法 * */
@RequestMapping(\)
public ModelAndView view(Model model) { logger.info(\方法调用\);
ModelAndView andView = new ModelAndView(); andView.setViewName(\); return andView; }
第四种返回一个Map集合
/**
* @see 使用map作为返回值的时候 是以prefix前缀+requestMapping的value+suffix后缀组成 返回一个map
* ,map的put方法调用相当于request.setAttribute方法 * */
@RequestMapping(\)
public Map
Map
bean.setUsername(\); bean.setPassword(\); map.put(\, \); map.put(\, bean); return map;
}
使用第四种方法,可以在页面中通过调用JSTL进行取值,如下面jsp代码
<%@ page language=\ pageEncoding=\
Mapa
Map a姓名:${user.username } 密码:${user.password } hello:${hello }
第五种返回一个ModelMap类型:
/**
* @see 返回一个ModelMap类型,返回地址根据以prefix前缀+requestMapping的value+suffix后缀组成
* ModelMap 本身也拥有hashmap的方法,也可以使用addAllAttributes对一个map添加到attribute里面 * */
@RequestMapping(\ public ModelMap map() {
ModelMap map = new ModelMap(); map.addAttribute(\ map.addAllAttributes(temp()); return map; }
/**
*@see 临时类
*@return 返回一个map类型 * */
public Map
Map
UserBean bean = new UserBean(); bean.setId(1);
bean.setUsername(\
bean.setPassword(\ map1.put(\
// map1.put(\ UserBean bean1 = new UserBean(); bean1.setId(2);
bean1.setUsername(\ bean1.setPassword(\ map1.put(\ System.out.println(map1); return map1; }
使用ModelMap可以把一个多个集合存到一个属性中,可以直接在页面调用EL 语言进行读取,jsp代码如下:
<%@ page language=\ pageEncoding=\
Mapa
Map a姓名:${user.username } 密码:${user.password } hello:${hello } aa:${aa }