在开发过程中,我们需要统一返回前端json格式的数据,但有些接口的返回值存在 null或者""这种没有意义的字段.以上不仅影响理解,还浪费带宽,这时我们可以统一做一下处理:不返回空字段,或者把NULL转成“”. 要做要以上,经过网上寻找资料,发现很多文章都是相互拷贝,于是从网上自己寻找资料,对他们进行整理,记录,同时可以对返回的null字段进行灵活配置. spring 内置的json处理框架是Jackson.我们可以对它配置一下达到目的,具体代码如下. @Configuration p
Spring MVC中Controller的处理方法的参数可以是Integer,String,自定义对象,ServletRequest,ServletResponse,ModelAndView等等,非常灵活.本文将分析SpringMVC是如何对这些参数进行处理的,使读者能够处理自定义的一些参数. 先来看几个示例: @Controller public class UserController { @RequestMapping(value = "/user/testRequestBody&quo
一.SpringMVC 使用 ModelAndView 来处理返回值问题. 1.ModelAndView 官方描述: Holder for both Model and View in the web MVC framework.Note that these are entirely distinct. This class merely holdsboth to make it possible for a controller to return both modeland view in