使用resultMap 构建对应关系
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace用于绑定dao接口的 -->
<mapper namespace="dao.UserDao">
<resultMap type="entity.User" id="User">
<id property="userId" column="user_id"></id>
<result property="userName" column="user_name" />
<result property="email" column="email" />
<result property="phoneNumber" column="phone_number" />
<result property="roleId" column="role_id" />
<result property="password" column="password" />
</resultMap>
<select id="getUsers" resultMap="User">
SELECT * FROM .t_user
</select>
<select id="getUserById" parameterType="Integer" resultMap="User">
SELECT * FROM t_user where user_id = #{id}
</select>
<select id="getUsersCount" resultType="Integer">
SELECT count(*) FROM t_user
</select>
</mapper>
网友评论