<?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">
//对应的userinfodao
<mapper namespace="com.croe.dao.UserInfoDAO">
//62行返回结果resultMap="usermap"
<resultMap type="UserInfo" id="usermap">
<id column="USER_ID" property="USER_ID" />
//数据库字段 实体类字段
<result column="USER_NAME" property="USER_NAME" />
<result column="USER_SEX" property="USER_SEX" />
<result column="USER_PHONE" property="USER_PHONE" />
<result column="USER_PASSWORD" property="USER_PASSWORD" />
<result column="USER_TYPE" property="USER_TYPE" />
</resultMap>
<insert id="add" parameterType="UserInfo" >
insert into user_info
//数据库字段
(USER_NAME,USER_SEX,USER_PHONE,USER_PASSWORD,USER_TYPE)
//实体类字段
values(#{USER_NAME},#{USER_SEX},#{USER_PHONE},#{USER_PASSWORD},#{USER_TYPE})
</insert>
UserInfoDAO对应定义的方法
<delete id="delete" parameterType="UserInfo">
// 数据库 实体类
delete from user_info where USER_ID=#{USER_ID}
</delete>
<delete id="deleteAll" parameterType="UserInfo">
delete from
user_info where
USER_ID =
#{deleteAll}
</delete>
<update id="update" parameterType="UserInfo">
update user_info
<set>
//实体类字段
<if test="USER_NAME!=null">
USER_NAME=#{USER_NAME},
</if>
<if test="USER_SEX!=null">
USER_SEX=#{USER_SEX},
</if>
<if test="USER_PHONE!=null">
USER_PHONE=#{USER_PHONE},
</if>
<if test="USER_PASSWORD!=null">
USER_PASSWORD=#{USER_PASSWORD},
</if>
<if test="USER_TYPE!=null">
USER_TYPE=#{USER_TYPE},
</if>
</set>
where USER_ID=#{USER_ID}
</update>
<select id="getUserList" parameterType="UserInfo" resultMap="usermap">
select * from user_info
<where>
<if test="USER_TYPE!=null and USER_TYPE!=''">
and USER_TYPE =#{USER_TYPE}
</if>
<if test="USER_NAME!=null and USER_NAME!=''">
and USER_NAME like #{USER_NAME}
</if>
</where>
// 分页,第多少条开始,多少条为一页
limit #{start},#{length}
</select>
<select id="getcount" parameterType="UserInfo" resultType="long">
select count(1) as total from user_info
<where>
<if test="USER_NAME!=null and USER_NAME!=''">
USER_NAME like #{USER_NAME}
</if>
</where>
</select>
<select id="getUserInfo" parameterType="UserInfo" resultMap="usermap">
select * from user_info
<where>
<if test="USER_ID !=null and USER_ID!=''">
and USER_ID=#{USER_ID}
</if>
<if test="USER_PHONE !=null">
and USER_PHONE=#{USER_PHONE}
</if>
</where>
</select>
</mapper>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
//对应的userinfodao
<mapper namespace="com.croe.dao.UserInfoDAO">
//62行返回结果resultMap="usermap"
<resultMap type="UserInfo" id="usermap">
<id column="USER_ID" property="USER_ID" />
//数据库字段 实体类字段
<result column="USER_NAME" property="USER_NAME" />
<result column="USER_SEX" property="USER_SEX" />
<result column="USER_PHONE" property="USER_PHONE" />
<result column="USER_PASSWORD" property="USER_PASSWORD" />
<result column="USER_TYPE" property="USER_TYPE" />
</resultMap>
<insert id="add" parameterType="UserInfo" >
insert into user_info
//数据库字段
(USER_NAME,USER_SEX,USER_PHONE,USER_PASSWORD,USER_TYPE)
//实体类字段
values(#{USER_NAME},#{USER_SEX},#{USER_PHONE},#{USER_PASSWORD},#{USER_TYPE})
</insert>
UserInfoDAO对应定义的方法
<delete id="delete" parameterType="UserInfo">
// 数据库 实体类
delete from user_info where USER_ID=#{USER_ID}
</delete>
<delete id="deleteAll" parameterType="UserInfo">
delete from
user_info where
USER_ID =
#{deleteAll}
</delete>
<update id="update" parameterType="UserInfo">
update user_info
<set>
//实体类字段
<if test="USER_NAME!=null">
USER_NAME=#{USER_NAME},
</if>
<if test="USER_SEX!=null">
USER_SEX=#{USER_SEX},
</if>
<if test="USER_PHONE!=null">
USER_PHONE=#{USER_PHONE},
</if>
<if test="USER_PASSWORD!=null">
USER_PASSWORD=#{USER_PASSWORD},
</if>
<if test="USER_TYPE!=null">
USER_TYPE=#{USER_TYPE},
</if>
</set>
where USER_ID=#{USER_ID}
</update>
<select id="getUserList" parameterType="UserInfo" resultMap="usermap">
select * from user_info
<where>
<if test="USER_TYPE!=null and USER_TYPE!=''">
and USER_TYPE =#{USER_TYPE}
</if>
<if test="USER_NAME!=null and USER_NAME!=''">
and USER_NAME like #{USER_NAME}
</if>
</where>
// 分页,第多少条开始,多少条为一页
limit #{start},#{length}
</select>
<select id="getcount" parameterType="UserInfo" resultType="long">
select count(1) as total from user_info
<where>
<if test="USER_NAME!=null and USER_NAME!=''">
USER_NAME like #{USER_NAME}
</if>
</where>
</select>
<select id="getUserInfo" parameterType="UserInfo" resultMap="usermap">
select * from user_info
<where>
<if test="USER_ID !=null and USER_ID!=''">
and USER_ID=#{USER_ID}
</if>
<if test="USER_PHONE !=null">
and USER_PHONE=#{USER_PHONE}
</if>
</where>
</select>
</mapper>