springmvc前台向后台传值几种方式从简单到
2018-06-22 · 国内最优秀java资源共享平台
关注
展开全部
通过HttpServletRequest
public String toIndex(HttpServletRequest request){
//获得前台name为username的元素的值
System.out.println(request.getParameter("username"));return "index";
}
通过参数名获得
@RequestMapping(value="/index")public String toIndex(String username){ //这里名字要与前端元素名字一致才能获得System.out.println(username);return "index";}
通过@RequestParam注解获得
@RequestMapping(value="/index")public String toIndex(@RequestParam(value="username",required=false)String username111){ //username要与前端一致,在此处可以理解为参数username111的别名System.out.println(username111);return "index";}
SpringMvc还能通过将vo作为参数获得vo的各个属性@RequestMapping(value="/index")public String toIndex(User user){System.out.println(user.getUserName());System.out.println(user.getPassword());return "index";
public String toIndex(HttpServletRequest request){
//获得前台name为username的元素的值
System.out.println(request.getParameter("username"));return "index";
}
通过参数名获得
@RequestMapping(value="/index")public String toIndex(String username){ //这里名字要与前端元素名字一致才能获得System.out.println(username);return "index";}
通过@RequestParam注解获得
@RequestMapping(value="/index")public String toIndex(@RequestParam(value="username",required=false)String username111){ //username要与前端一致,在此处可以理解为参数username111的别名System.out.println(username111);return "index";}
SpringMvc还能通过将vo作为参数获得vo的各个属性@RequestMapping(value="/index")public String toIndex(User user){System.out.println(user.getUserName());System.out.println(user.getPassword());return "index";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询