Controller中的方法返回一个对象,运行时报错,因为该对象的类型不被servlet支持,所以要转为json对象后返回。
报错:
org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type
解决方法:
pom.xml文件中添加依赖:
spring-mvc.xml文件中添加message-converters:
最后记得检查返回对象的类中的要返回的字段是否有setter and getter方法:
Ajax请求: