This is the 12th day of my participation in the August Text Challenge.More challenges in August
Hello. Hello ah, I am gray little ape, a super will write bug program ape!
I came to fix the BUG again today!!
** Today, when integrating SSM, reading database data and returning JSON string, and transmitting it to front-end interface Ajax for interaction, I sent a request to the background to get the returned JSON data, but there was such an error, the page displayed 500:
HTTP Status 500 – org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.github.pagehelper.PageInfo
I translated it into English.
Request processing failed; Nested exception is Java. Lang. IllegalArgumentException: didn’t find the type of the converter return values: class com. Making. Pagehelper. PageInfo
However, my code that reads data from the database and returns a JSON string looks like this:
* @param pn * @param model * @return */ @requestMapping ("/emps") @responseBody public PageInfo getEmpsWithJson(@RequestParam(value = "pn", DefaultValue = "1") Integer PN) {// The page to be forwarded and the amount of data to display pageHelper. startPage(pn, 5); List<Employee> employees = employeeservice.getall (); System.out.println(" query data: "); System.out.println(employees); Pageinfo page = new PageInfo(employees, 5); System.out.println(" Encapsulate data: "); // System.out.println(page); return page; }Copy the code
I’m using the **@responseBody** annotation, which will automatically wrap the returned data in JSON format. ** But now my foreground can’t receive the wrapped JSON object, and the retrieved data can’t wrap the json object.
At first, I could not find the solution to the problem. I found many similar errors on the Internet, but their answers were ambiguous and could not actually solve the problem.
Json dependency coordinates are automatically generated when using Maven to import json dependency coordinates in pom. XML
- jackson-databind-x.x.x.jar
- jackson-annotations-x.x.x.jar
- jackson-core-x.x.x.jar
If one of these jars is missing, you can import it from the following maven repository:
Mvnrepository.com/artifact/co…
But now it’s almost impossible to say which jar package is missing,
So if you don’t lack jar packages, then we should have the same problem!
Solution:
** For No Converter found for return value of type error, the reason is usually due to a conflict of jar versions. ** For No Converter found for return value of type error, the reason is usually due to a conflict of JAR versions
My Spring JAR package version is 4.3.7, and the JSON version running using 2.8.8 will report the above error.
So the solution is to replace the JAR package of other version of JSON, I suggest to replace the lower version, I replaced the jar package of 2.7.4, and then run it again. If yours does not work, you can try to change the JAR package of other version.
The dependency code for the JAR package importing JSON in POM.xml is:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> The < version > 2.7.4 < / version > < / dependency >Copy the code
Then restart Tomcat and run it again!
If you have other solutions, welcome comments put forward!
I’m Grey Ape, and I’ll see you next time!