Spring 4.2.0,Hibernate 4.1.4, 这是我的Controller功能:
Controller
@RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET) @ResponseBody public List<Company> listforCompanies() { List<Company> listOfCompanies= new ArrayList<Company>(); listOfCompanies = companyManager.getAllCompanies(); return listOfCompanies; }
Jackson JSON映射器依赖项Pom.xml:
Pom.xml
<!-- Jackson JSON Mapper --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency>
在清单中获取列表ArrayList,但返回时显示以下错误:
ArrayList
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/IrApp] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList] with root cause java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList at org.springframework.util.Assert.isTrue(Assert.java:68) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:124)
将以下依赖项添加到pom.xml中:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.0</version> </dependency>