1.如果数据库和pojo的属性名都一样的话可以用如下方式:
<select id="getUser" resultType="org.guarx.domain.User" parameterType="java.lang.String">
select * from users where id=#{value}
]]>
</select>
<select id="getUsers" resultType="org.guarx.domain.User">
select * from users
]]>
</select>
2.如果数据库columns name和pojo的属性名称不一样(大多数情况下)
(1)第一种方式:
- <select id="getUsers" resultType="org.guarx.domain.User">
- <![CDATA[
- select t_id as id,t_username as name,t_desc as description from users
- ]]>
- </select>
(2)第二种方式:
- <resultMap type="org.guarx.domain.User" id="userMapper">
- <result column="t_id" property="id"/>
- <result column="t_username" property="username"/>
- <result column="t_desc" property="description"/>
- </resultMap>
- <select id="getAll" resultMap="userMapper">
- <![CDATA[
- select id,username,description from users
- ]]>
- </select>
阅读(1193) | 评论(0) | 转发(0) |