springmvc中进行数据保存以及日期参数的保存过程解析

网友投稿 158 2022-12-28


springmvc中进行数据保存以及日期参数的保存过程解析

1.在ControllerUKLCfbI类中接受传入的日期类型的参数时

日期:

@RequestMapping("todate.do")

public String todate(Date date) {

System.out.println(date);

return "list";

}

@InitBinder

public void initBinder(ServletRequestDataBinder binder){

//只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型

binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),

true));

}

2.当要传入多个参数时

姓名:

密码:

性别:

年龄:

地址:

生日:

@RequestMapping("list2.do")

public String list2(Users users ) {

System.out.println(users);

return "list";

}

@InitBinder

public void initBinder(ServletRequestDataBinder binder){

//只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型

binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),

true));http://

}

Controller数据保存

保存至request里

(1)ModelAndView

@RequestMapping("aaa.do")

public ModelAndView index() {

ModelAndView mv = new ModelAndView();

mv.setViewName("index");

mv.addObject("name","张三");

return mv;

}

(2)Model

@RequestMapping("aaa.do")

public String index(Model model) {

model.addAttribute("name", "李四");

return "index";

}

(3)map

@RequestMapping("aaa.do")

public String index(Map map) {

map.put("nahttp://me", "222");

return "index";

}

(4)request

@RequestMapping("list.do")

public String list(HttpServletRequest request) {

request.setAttribute("name","wang");

return "index2";

}

保存至session里

@RequestMapping("list.do")

public String list(HttpSession session) {

session.setAttribute("name","wang");

return "index2";

}

保存至application里

@RequestMapping("list.do")

public String list(HttpSession session) {

session.getServletContext().setAttribute("name","wang");

return "index2";

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:以下哪些是微服务网关功能(简述终端服务网关的作用)
下一篇:springmvc如何进行异常处理
相关文章

 发表评论

暂时没有评论,来抢沙发吧~