Spring MVC的@ResponseBody回来JSON串

时间:2021-11-21 14:32:03

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过滤器