• mybatis处理查询map列表属性为null的问题,而导致查询map无该key对象


    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>
  • 相关阅读:
    promise 理解
    强化学习的概念
    Ubuntu安装机器学习环境步骤
    jsp文件复制到web项目出错
    jdbc导致的问题
    C#窗体-猜数字
    软件工程结对作业01
    第二阶段冲刺10天 第3天进展报告
    第二阶段冲刺10天 第2天进展报告
    第二阶段冲刺10天 第1天进展报告
  • 原文地址:https://www.cnblogs.com/simpledev/p/3843320.html
Copyright © 2020-2023  润新知