zoukankan      html  css  js  c++  java
  • SpringMVC-二

    接受参数为时间的两种方法

    方法一

    @InitBinder
        public void initBinder(ServletRequestDataBinder binder){
            //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
            binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
                    true));
        }
    
    @RequestMapping("date.do")
        public String acceptDate(Date date) {
            System.out.println(date);
            return "index";
        }

    方法二

     

    @RequestMapping("test1.do")
        public ModelAndView test1() {
            ModelAndView m=new ModelAndView("test");
            m.addObject("name", "李四");
            return m;
        }
        @RequestMapping("test2.do")
        public String test2(Map<String,String> m) {
            m.put("name", "王五");
            return "test";
        }
        @RequestMapping("test3.do")
        public String test3(Model m) {
            m.addAttribute("name", "赵六");
            return "test";
        }
        @RequestMapping("test4.do")
        public String test4(HttpSession session) {
            session.setAttribute("name", "王八");
            return "test";
        }

    #########################################

     ##############################################

     ##################################

    重定向

    @RequestMapping("test6.do")
        public String test6() {
            
            return "redirect:SpringMVC_02/login.jsp";
        }

    #############################################

    SpringMVC完成ajax

    1. 加入jackson的jar包. springmvc。
    2. 在响应的方法上加上@ResponseBody :把java对象转化为json对象。
    3. 方法的返回值可以是对象集合字符串。

     还会出现中文乱码问题

    默认iso编码

    返回json对象不会乱码(默认编码为utf-8)

     

     解决方法

  • 相关阅读:
    面试十题(4)
    TS中给接口指定的成员?
    TS中定义泛型接口的两种方式
    ts中泛型的使用
    ts中类的属性的封装
    ts中接口的使用
    自定义hook的步骤
    react中如何使用useReducer?
    react中useContext的使用
    react 中useRef的作用
  • 原文地址:https://www.cnblogs.com/accc111/p/11456340.html
Copyright © 2011-2022 走看看