💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
ModelAndView ~~~ @RequestMapping(value="/test3",method=RequestMethod.GET) public ModelAndView test3() { //跳转到index.jsp ModelAndView mav = new ModelAndView(); mav.addObject("msg", "hello test3"); mav.setViewName("/index.jsp"); //请求转发 return mav; } ~~~ String ~~~ @RequestMapping("/test5") public String test5(HttpServletRequest request) { request.setAttribute("msg", "hello test5"); return "/index.jsp";//请求转发 } ~~~ ~~~ @RequestMapping("/test6") public String test6(HttpSession session) { session.setAttribute("msg", "hello test6"); return "redirect:/index.jsp";//请求重定向 } ~~~ void ~~~ @RequestMapping("/ajax") public void test7(HttpServletResponse response) { response.setContentType("text/json"); response.setCharacterEncoding("utf-8"); try { PrintWriter out = response.getWriter(); out.write("{\"username\":\"feiyy\"}"); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ~~~ 对象类型(第四张ajax讲解) SpringMVC的依赖注入: HttpServletRequest request HttpSession session ServletContext application HttpServletResponse response Model model