Spring MVC的@ResponseBody回来JSON串

mac2022-06-30  41

1 406错误

      <mvc:annotation-driven />不用动,请求的时候URL的文件扩展名应为json

      @ResponseBody会根据扩展名,或者Header,或者Parameter来判断要返回的具体格式

<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="favorPathExtension" value="true" /> <property name="favorParameter" value="false" /> <property name="ignoreAcceptHeader" value="true" /> <property name="mediaTypes"> <props> <prop key="json">application/json</prop> </props> </property> </bean>

2 failed to lazily initialize a collection of role

加入OpenSessionInViewFilter过滤器

 

转载于:https://www.cnblogs.com/cuizhf/p/3530873.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)