SpringMVC开发小结

1. 自动封装返回对象为JSON

  1).在spring配置文件中添加如下配置:

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

  2).在需要进行转化的Controller上添加 @RestController 或method上添加@ResponseBody注解

猜你喜欢

转载自www.cnblogs.com/lmsthoughts/p/8919943.html
今日推荐