项目中接口返回参数时,字符串会出现null情况,前端判断比较困难,可以通过后端配置的方式解决。项目中用的是fastJson。
参考地址:https://www.cnblogs.com/zf29506564/p/6669870.html
<!-- 增加返回配置 字符串|数字为Null时返回""|0 -->
<mvc:annotation-driven enable-matrix-variables="true">
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json</value>
<value>application/x-www-form-urlencoded</value>
<value>text/plain</value>
</list>
</property>
<property name="features">
<list>
<value>WriteNullNumberAsZero</value>
<value>WriteNullStringAsEmpty</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>