1.常规处理方法(数据库以mysql为例)
IFNULL(m.last_use_time,0) as last_use_time, IFNULL(m.last_lon,0) as last_lon, IFNULL(m.last_lat,0) as last_lat
if判断是否为null,设置一个默认值。
2.前台jsp页面处理,判断是否是等于0的情况,即判断长度值。
<c:if test="${fn:length(mem.lastUseTime) != 1}"> ${mem.lastUseTime} </c:if>
3.通过修改xml配置文件来处理。
<!-- Mybatis的Session工厂 --> <bean id="consoleSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:/conf/mybatis-config.xml" /> <property name="typeAliasesPackage" value="com.autoyolConsole.model" /> </bean>
4.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="callSettersOnNulls" value="true"/> </settings> </configuration>
5.前台jsp页面判断是否为null
<c:if test="${mem.lastUseTime != null}"> <fmt:formatDate value="${mem.lastUseTime}" pattern="yyyy-MM-dd HH:mm"/> </c:if>