数据处理模型
来源:互联网 发布:有什么聊天软件 编辑:程序博客网 时间:2024/06/06 18:57
数据处理模型:http://www.mamicode.com/info-detail-1142041.html
* springmvc中Model相关对象 是处理和数据相关的对象
* @ModelAttribute 重命名 参数数据
* Model(ModelMap|Map)传递数据到视图(相当于request.setAttribute)
* ModelAndView 绑定数据到视图 (ModelMap用于传递数据 View对象用于跳转)
@SessionAttributes("user")
@Controller
public class SessionController {
@RequestMapping(value="/case",method=RequestMethod.GET)
public String case1(Map map) throws Exception{
map.put("sex", "girl");
return "/lesson03/res.jsp";
}
@RequestMapping(value="/case2",method=RequestMethod.GET)
public ModelAndView case2() throws Exception{
//ModelAndView mav=new ModelAndView("/lesson03/res.jsp");
ModelAndView mav=new ModelAndView();
mav.setViewName("/lesson03/res.jsp");
mav.addObject("sex", "boy");
return mav;
}
@ModelAttribute("user")
public User getUser() {
User user = new User();
return user;
}
/**
* http://localhost:8080/s/session?id=1
* 请求转发 forward: 不需要任何处理
*
* 请求重定向 redirect:
* 使用SessionAttribute方式 用于在重定向中传至 将值存储在session中 【用完记住清除】
* @param map
* @return
* @throws Exception
*/
@RequestMapping(value = "/session", method = RequestMethod.GET)
public String case1(@ModelAttribute("user") User user) throws Exception {
return "redirect:/session2";
}
@RequestMapping(value = "/session2", method = RequestMethod.GET)
public String case2(Map map, HttpServletResponse res,SessionStatus sessionStatus) throws Exception {
User user = (User) map.get("user");
res.getWriter().println(user.getId());
sessionStatus.setComplete();
return null;
}
}
* springmvc中Model相关对象 是处理和数据相关的对象
* @ModelAttribute 重命名 参数数据
* Model(ModelMap|Map)传递数据到视图(相当于request.setAttribute)
* ModelAndView 绑定数据到视图 (ModelMap用于传递数据 View对象用于跳转)
@SessionAttributes("user")
@Controller
public class SessionController {
@RequestMapping(value="/case",method=RequestMethod.GET)
public String case1(Map map) throws Exception{
map.put("sex", "girl");
return "/lesson03/res.jsp";
}
@RequestMapping(value="/case2",method=RequestMethod.GET)
public ModelAndView case2() throws Exception{
//ModelAndView mav=new ModelAndView("/lesson03/res.jsp");
ModelAndView mav=new ModelAndView();
mav.setViewName("/lesson03/res.jsp");
mav.addObject("sex", "boy");
return mav;
}
@ModelAttribute("user")
public User getUser() {
User user = new User();
return user;
}
/**
* http://localhost:8080/s/session?id=1
* 请求转发 forward: 不需要任何处理
*
* 请求重定向 redirect:
* 使用SessionAttribute方式 用于在重定向中传至 将值存储在session中 【用完记住清除】
* @param map
* @return
* @throws Exception
*/
@RequestMapping(value = "/session", method = RequestMethod.GET)
public String case1(@ModelAttribute("user") User user) throws Exception {
return "redirect:/session2";
}
@RequestMapping(value = "/session2", method = RequestMethod.GET)
public String case2(Map map, HttpServletResponse res,SessionStatus sessionStatus) throws Exception {
User user = (User) map.get("user");
res.getWriter().println(user.getId());
sessionStatus.setComplete();
return null;
}
}
阅读全文
0 0
- 数据处理模型
- Spring MVC 模型数据处理
- java与单板机通信使用数据处理模型
- 交互式大数据处理模型-Google Dremel
- 流式数据处理的计算模型
- 交互式大数据处理模型-Google Dremel
- 流式数据处理的计算模型
- iOS数据处理之字典转模型
- 数据处理与模型选择的一些注释
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 数据处理
- 第12周项目3-Dijkstra算法的验证
- 图解CSS3核心技术与案例实践(第五章CSS3文本)
- 防止sql注入
- Ubuntu14源码编译安装Xen4.6
- 微信内置浏览器缓存清理方法
- 数据处理模型
- ESlint-airbnb配置
- 对xine结构的了解
- remove mysql
- 让地址栏显示返回实际jsp的的实际位置
- JQuery警告:Duplicated jQuery selector
- 自定义View基础(一)——追根溯源,透过源码认识ViewRoot,DecorView和performTraversals方法
- Mac使用技巧-Mac OSX 使用rz、sz 远程上传、下载文件
- 我要开始在csdn胡扯了