如何接受日期类型格式的参数?
(1)接受单个日期参数
网页输出:

//后台接受参数为日期类型
    @RequestMapping("toDate.do")
    public String toDate(Date date) {
        System.out.println(date);
        return "index";
    }
使用initBinds 加入到UsersController.java 当你接受的参数日期类型时先经过该方法进行处理
@InitBinder
    public void initBinder(ServletRequestDataBinder binder){
        //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),  true));
    }
(2)接受多个参数时
网页输出:

// 注册页面 register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <a href="users/register.do?name=zs&age=25">链接到list.do</a>
    <form action="users/register.do" method="post">
    姓名:<input type="text" name="unames"/><br>
    密码:<input type="text" name="password"/><br>
    性别:<input type="text" name="sex"/><br>
    年龄:<input type="text" name="age"/><br>
    地址:<input type="text" name="address"/><br>
    手机:<input type="text" name="phone"/><br>
    出生日期:<input type="text" name="birthday"/><br>
    <input type="submit" value="提交"/>
    </form>
</body>
</html>
  //接受多个参数
@RequestMapping("register.do")
public String register(Users users) {
   System.out.println(users);
   return "index";
}
接受多个参数时直接在对应的实体类(bean)中加入

2.1 数据保存到request作用域的方式.
jsp调用:${requestScope.name }
1.使用ModelAndView,那么该方法的返回类型必须是ModelAndView
    //1.可保存到ModelAndView,那么方法的返回类型必须是ModelAndView
    @RequestMapping("index.do")
    public ModelAndView index() {
        ModelAndView mv=new ModelAndView("index");
        mv.addObject("name","张三");
        return mv;
    }
2.使用Model, 方法的返回值还是字符串类型。
    //2.保存到Model中,方法的返回值还可以是字符串
    @RequestMapping("index.do")
    public String index(Model model) {
        model.addAttribute("name","李四");
        return "index";
    }
3.使用Map.方法的返回值还是字符串类型
    //3.保存到Map中
    @RequestMapping("index.do")
    public String index(Map<String,Object> map) {
        map.put("name","王五");
        return "index";
    }
jsp调用:${sessionScope.name }
4.原始的HttpServletRequest对象保存
    //4.原始的HttpServletRequest对象保存
    @RequestMapping("index.do")
    public String index(HttpSession session) {
        session.setAttribute("name","田七");
        return "index";
    }
jsp调用:${applicationScope.name }
2.2 数据保存到session作用域的方式
1.使用原始的HttpSession保存
    //1.使用原始的HttpSession保存。
    @RequestMapping("index.do")
    public String index(Model model,HttpSession session) {
        //session.getServletContext():得到application对象
        session.getServletContext().setAttribute("name","我在application中");
        return "index";
    }
2.使用注解@SessionAttributes(name={key1,key2})



静态资源可以正常的显示


需要在springmvc的配置文件中添加

1.加入jackson的jar包. springmvc
2.在响应的方法上加上@ResponseBody :把java对象转化为json对象
3.方法的返回值可以是对象集合字符串。
 
4.如果ajax返回的为字符串,那么就会出现乱码。
因为:
 
 
 
修改:
 
原文:https://www.cnblogs.com/xg123/p/11456672.html