spring的几个传参方法
2020-11-22 21:27
标签:com http blog style class div img code java c log 1.@PathVariable 通过URI template 样式映射时,使用@PathVariable Controller层接收 有一个地方需要注意的是 id必须是不带符号的字符串,如果是中间带逗号的字符串,后台接收时会出错 通过在url用?挂参数来传参 Controller接收 3.@SessionAttributes 绑定的方法,可以通过model.addAttribute("session",session); 取法可以通过 也可以 HttpServletRequest.getSession.getAttribute("session"); 4.@ModelAttribute 这一种还没怎么用过,应该是被@ModelAttribute注解过的方法会在controller的每个方法执行之前被调用一遍 下面是一个具体解释@ModelAttribute的链接 http://wangwengcn.iteye.com/blog/1677024 spring的几个传参方法,搜素材,soscw.com spring的几个传参方法 标签:com http blog style class div img code java c log 原文地址:http://www.cnblogs.com/singerGodZhu/p/3701207.html
$(‘#setButton‘).click(function() {
$("#removeId").val(spId);
$("#toolBarForm").attr("action","/test/"+$("#id").val());
$("#toolBarForm").submit();
}); @RequestMapping( value = "/test/{id}", method = RequestMethod.POST )
public String test(String removeId,@PathVariable String id,HttpServletRequest request,HttpServletResponse response,Model model) {
return this.listLoad(request, response, model);
}
2.@RequestParam @RequestMapping( value = "/test2", method = RequestMethod.POST )
public String batchSet(String removeId,@RequestParam String id,HttpServletRequest request,HttpServletResponse response,Model model) {
return this.listLoad(request, response, model);
}
通过在controller上加上注解,绑定HttpSession中attribute的值@Controller
@SessionAttributes({"session"})
public class TestController extends BaseController {
}
HttpSession.getAttribute("session");public class HelloWorldController {
@ModelAttribute
public void populateModel(@RequestParam String abc, Model model) {
model.addAttribute("attributeName", abc);
}
@RequestMapping(value = "/helloWorld")
public String helloWorld() {
return "helloWorld";
}