springmvc的前后端传值
2021-06-21 05:03
标签:tree arrays test name type val use str ping 一.后端传值给前端 1.ModelAndView 2.map 3.ModelMap 4.model 5.使用servlet Api 二.前端向后台传值 1.pojo的值 2.利用@RequestParam注解参数 3.利用 springmvc的前后端传值 标签:tree arrays test name type val use str ping 原文地址:https://www.cnblogs.com/QYou/p/9685864.html@RequestMapping("/testModelAndView")
public ModelAndView testModelAndView(){
String viewName=SUCCESS;
ModelAndView model = new ModelAndView(viewName);
model.addObject("time", new Date());
return model;
}
@RequestMapping("/testMap")
public String testMap(Map
@RequestMapping("/testModelMap")
public String testModleMap(ModelMap map){
map.addAttribute("modelMapDate", "modelMapDate");
return SUCCESS;
}
@RequestMapping("/testModel")
public String testModel(Model model){
model.addAttribute("modelDate", "modelDate");
return SUCCESS;
}
后端java
@RequestMapping("/testPOJO")
public String testPOJO(User user){
System.out.println(user);
return SUCCESS;
}
前端jsp
@RequestMapping("/testResquestParam")
public String testResquestParam(@RequestParam(value="username") String username,
@RequestParam(value="age",required=false,defaultValue="14") int age,
@RequestParam String email,
double price){
System.out.println("testResquestParam:"+username+" "+age+" "+email+" "+price);
return SUCCESS;
}@ModelAttribute,为对象传值
@RequestMapping("/testModelAttribut")
public String testModelAttribut(@ModelAttribute User user,Map
下一篇:算法学习——递归之排队购票问题