SpringMVC 中使用 @ResponseBody 返回Json时,需要手动添加jackson依赖

严重: Servlet.service() for servlet [test] in context with path [/test] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.example.test.entity.User] with root cause

java.lang.IllegalArgumentException: No converter found for return value of type: class com.example.test.entity.User


使用@ResponseBody返回一个实体到页面报错!spring自家的注解还要导入第三方的jar包!

SpringMVC 中使用 @ResponseBody 返回Json时,需要手动添加jackson依赖!Maven添加:

如果你的spring版本过高,那么下面2个jar的版本也要用最新的 ,否则会抛异常

<dependency>
  <groupId>com.fasterxml.jackson.coregroupId>
  <artifactId>jackson-coreartifactId>
  <version>2.8.7version>
dependency>
<dependency>
  <groupId>com.fasterxml.jackson.coregroupId>
  <artifactId>jackson-databindartifactId>
  <version>2.8.7version>
dependency>
实在是 恶心啊

你可能感兴趣的:(java)