springboot报错笔记(1) :java.lang.IllegalArgumentException: Unknown return value type: java.lang.Integer

报错:java.lang.IllegalArgumentException: Unknown return value type: java.lang.Integer

解决方法:
在controller中加入注解@ResponseBody即可。

  • @ResponseBody注解的作用通常是将controller的方法参数转换为JSON格式进行数据的返回,写入在response对象的body区域.。

代码如下:

@RequestMapping("/LoginUser")
@ResponseBody
  public User LoginUser(User user){
    
    
    return user;
  }

那么在页面显示的数据就是以JSON形式显示的,比如:
  {“name”:“张三”,“age”:18}

猜你喜欢

转载自blog.csdn.net/m0_52673390/article/details/113100374