SpringMVC分頁查詢無法直接將對象轉換成json的解決辦法(報org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type:錯)


在用ajax獲得分頁數據時,無法將獲取的值賦值給input標簽,在修改用戶信息時不顯示用戶已經注冊的信息,百度可知

springmvc處理分頁數據返回的對象時,無法直接將對象轉換成json,會報org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type:錯誤,

需要在springmvc返回前先轉換為json

步驟如下:

1.添加依賴(pom.xml)

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.5</version>
</dependency>
<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.9.5</version>
</dependency>

 2.指定Message對象轉換器(springmvc.xml)

<mvc:annotation-driven>
   <mvc:message-converters>
      <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
      <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
   </mvc:message-converters>
 </mvc:annotation-driven>

完成, 再次訪問可獲得ajax中的數據


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM