# 为什么Controller层里面传一个类时不需要使用@RequestParam或者@PathVariable
今天复习MyBatis代码的时候突然发现一个问题,
public Boolean addUser(User user){
这里传入的user没有使用注解
@RequestMapping("/All")
public List<User> getAll() {
return userService.queryUserList();
}
@RequestMapping("/one/{id}")
public User getOne(@PathVariable("id") int id) {
return userService.queryDistinctUser(id);
}
@RequestMapping("/add")
public Boolean addUser(User user){
return userService.addUser(user);
// return "controller success";
}
@RequestMapping("/delete/{id}")
public Boolean deleteById(@PathVariable("id") int id){
System.out.println("我是controller");
return userService.deleteById(id);
这里的增删改查分别使用了
public List getAll() ------这里是不需要参数
public User getOne(@PathVariable(“id”) int id)—这里使用了@PathVariable
public Boolean addUser(User user)—这里我就有点晕了,之前用的好好的,现在就有点想不通
public Boolean deleteById(@PathVariable(“id”) int id)------这里使用了@PathVariable
- 最后运行的结果(使用?+属性的方法就能添加成功)

本文探讨了Spring MVC中Controller层如何处理参数传递,特别是在添加用户信息时,未使用@RequestParam或@PathVariable注解的情况下如何实现。文章通过具体示例介绍了不同类型的参数接收方式,并解释了为何可以直接传递对象。
6372

被折叠的 条评论
为什么被折叠?



