相关疑难解决方法(0)

如何使用@ResponseBody从spring Controller返回JSON数据

Spring版本4.2.0,Hibernate 4.1.4 这是我的Controller功能:

@RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET)
@ResponseBody
public List<Company>  listforCompanies() {      
    List<Company> listOfCompanies= new ArrayList<Company>();        
    listOfCompanies = companyManager.getAllCompanies();
    return listOfCompanies;
}
Run Code Online (Sandbox Code Playgroud)

杰克逊JSON映射器依赖Pom.xml:

    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

获取列表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 …
Run Code Online (Sandbox Code Playgroud)

java spring json spring-mvc spring-4

48
推荐指数
5
解决办法
9万
查看次数

标签 统计

java ×1

json ×1

spring ×1

spring-4 ×1

spring-mvc ×1