MyBatis database column names and attribute names are not the same bean mapping process
When your database column names and bean property names are not the same, this will be reported the following error
org.apache.ibatis.builder.IncompleteElementException: Could not find result map 'com.houpu.mybatis.mapper.UserMapper.base_name' referenced from 'com.houpu.mybatis.mapper.UserMapper.findAll'
the first method
MyBatis is automatically configured to match the bean inside, but he could not find a match appearances bean. Being given
treatment methods: adding Mapper.xml or Dao.xml (generally so named)
<resultMap id="base_name" type="com.houpu.mybatis.bean.User">//id名和查询语句的resultMap相匹配
<!--id代表配置主键-->
<id property="id" column="userId"></id>
<!--result代表配置非主键字段,实际上id可以不用,可以全写为result-->
<result property="name" column="username"></result>
<result property="birth" column="birthday"></result>
<result property="gender" column="sex"></result>
<result property="addr" column="address"></result>
</resultMap>
<select id="findAll" resultMap="base_name">
select * from user
</select>
<ResultMap> </ resultMap> which fill bean and column names match the bean property Fill attribute name, column to fill the column names in the database
The second method
Join field name in the query
, such as
<select id="findAll" resultMap="base_name">
select 数据库列名 as bean属性名, 数据库列名 as bean属性名 from user
</select>