SpringMVC (请求参数的获取及请求细化)

SpringMVC入门:https://blog.csdn.net/young_1004/article/details/82114221

SpringMvc请求参数的获取

1.通过HttpServletRequest获取

@RequestMapping("/deleteUser")

public ModelAndView deleteUser(HttpServletRequest request, HttpServletResponse response) throws IOException {

System.out.println("删除用户..."+request.getParameter("id"));

response.getWriter().write("hello");

return null;

}

2.通过方法的形参获取

@RequestMapping("/deleteUser")

public ModelAndView deleteUser(HttpServletRequest request, HttpServletResponse response,Integer id) throws IOException {

System.out.println("删除用户..."+id);

response.getWriter().write("hello");

return null;

}

请求的细化

@Controller

@RequestMapping("/user")

public class UserController {

@RequestMapping("/find")

public ModelAndView find() {

System.out.println("findUser....");

ModelAndView modelAndView = new ModelAndView();

modelAndView.setViewName("/index.jsp");

modelAndView.addObject("username", "admin111");

return modelAndView;

}

}

猜你喜欢

转载自blog.csdn.net/young_1004/article/details/82116030