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) 我正在使用spring mvc 4并尝试将一个简单map的函数返回到ajax - 从我的控制器到jsp文件.
控制器:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
Map<String, String> myTest() {
System.out.println("------------------------------------test");
Map<String,String> myMap = new HashMap<String, String>();
myMap.put("a", "1");
myMap.put("b", "2");
return myMap;
}
Run Code Online (Sandbox Code Playgroud)
来自jsp文件的Ajax:
function testAjax() {
$.ajax({
url : '../../ajaxtest.html',
dataType: "json",
contentType: "application/json;charset=utf-8",
success : function(data) {
alert("1");
alert(data);
}
});
}
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何警报,只是错误HTTP/1.1 406 Not Acceptable.
但是,更改代码以返回一个简单的字符串工作正常.控制器:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
String myTest() {
System.out.println("------------------------------------test");
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
阿贾克斯:
function testAjax() …Run Code Online (Sandbox Code Playgroud)