1.在mybatis中查询的时候遇到一些问题,就是有一部分的值是为null,然后其他的是正确的,后来看到那写出问题的变量都是xxx_xxx类型的,那些查出的值都是没有那个"_"的变量,而且查询一条的没有问题,查询多条的就没有问题了,主要是因为查询多条时用的是<select id="selectAll" resultMap="BaseResultMap" >
resultMap可以接受那种类型的变量的转换,而查询一条用的是<select id="findByAreaId" resultType="com.swpu.entity.Area">
resultType对于那种变化不敏感,后来就发现配置一下那个mybatis的配置文件就好了。
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>
<!--使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
<setting name="useGeneratedKeys" value="true"/>
<!--使用标签替换列名 默认:true -->
<setting name="useColumnLabel" value="true"/>
<!--开启驼峰命名转换:Table(create_time) ->Entity(createTime) -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
然后在工程的pom.xml文件中配置一下文件就可以了,这样就可以成功查询了