package com.test.demo; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class FrontController { @RequestMapping("/test") public String viewTest(@RequestParam String name,HttpServletRequest req) { HttpSession session = req.getSession(); session.setAttribute("name", name); return "test"; } @RequestMapping("/test/{name}") public ModelAndView viewPathTest(@PathVariable String name,HttpServletRequest req) { ModelAndView mv = new ModelAndView(); mv.addObject("name",name); mv.setViewName("test"); return mv; } }