@Controller
public class TestController {
//普通传值方式
@RequestMapping("/test1")
public String test1(String username,String password){
System.out.println("username="+username);
System.out.println("password="+password);
return "test";
}
//对象传值方式
@RequestMapping("/test2")
public String test2(User user){
System.out.println("username="+user.getUsername());
System.out.println("password="+user.getPassword());
return "test";
}
//复杂传值测试
@RequestMapping("/test3")
public String test3(String username, String sex, @RequestParam("hobby") List<String> hobby, String school, String introduce){
System.out.println("文本框username="+username);
System.out.println("单选钮sex="+sex);
System.out.println("多选框hobby="+hobby);
System.out.println("下拉框school="+school);
System.out.println("文本域introduce="+introduce);
return "test";
}
//restful传值方式
@RequestMapping("/test4/{username}/{password}")
public String test4(@PathVariable String username, @PathVariable String password){
System.out.println("username="+username);
System.out.println("password="+password);
return "/test";
}
}
MVC 接参的几种方式
最新推荐文章于 2024-05-02 22:50:48 发布