You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.6 KiB

<?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">
<!-- 配置Mabatis映射文件 -->
<mapper namespace="com.dao.UsersDAO">
<resultMap type="users" id="usersMap">
<id property="usersid" column="usersid" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="realname" column="realname" />
<result property="sex" column="sex" />
<result property="birthday" column="birthday" />
<result property="contact" column="contact" />
<result property="email" column="email" />
<result property="roomsid" column="roomsid" />
<result property="status" column="status" />
<result property="regdate" column="regdate" />
<result property="roomsname" column="roomsname" />
</resultMap>
<!-- 插入语句 DAO通过id调用此配置 -->
<insert id="insertUsers" parameterType="users">
insert into users(usersid , username , password , realname , sex , birthday , contact , email ,
roomsid , status , regdate ) values(#{usersid} ,
#{username} , #{password} , #{realname} , #{sex} , #{birthday} , #{contact} , #{email} ,
#{roomsid} , #{status} , #{regdate} )
</insert>
<!-- 更新语句 DAO通过id调用此配置 -->
<update id="updateUsers" parameterType="users">
update users set username=#{username} , password=#{password} , realname=#{realname} , sex=#{sex}
, birthday=#{birthday} , contact=#{contact} ,
email=#{email} , roomsid=#{roomsid} , status=#{status} , regdate=#{regdate} where
usersid=#{usersid}
</update>
<!-- 按主键删除 DAO通过id调用此配置 -->
<delete id="deleteUsers" parameterType="String">
delete from users where usersid = #{usersid}
</delete>
<!-- 查询全部信息 DAO通过id调用此配置 -->
<select id="getAllUsers" resultMap="usersMap">
select a.* , b.roomsname from users a , rooms b where a.roomsid = b.roomsid order by usersid
desc
</select>
<!-- 按主键查询 DAO通过id调用此配置 -->
<select id="getUsersById" parameterType="String" resultMap="usersMap">
select a.* , b.roomsname from users a , rooms b where a.roomsid =
b.roomsid
and usersid=#{usersid} order by usersid desc
</select>
<!-- 按条件精确查询 DAO通过id调用此配置 -->
<select id="getUsersByCond" parameterType="users" resultMap="usersMap">
select a.* , b.roomsname from users a , rooms b where a.roomsid = b.roomsid
<if test="username != null and '' != username">
and a.username = #{username}
</if>
<if test="password != null and '' != password">
and a.password = #{password}
</if>
<if test="realname != null and '' != realname">
and a.realname = #{realname}
</if>
<if test="sex != null and '' != sex">
and a.sex = #{sex}
</if>
<if test="birthday != null and '' != birthday">
and a.birthday = #{birthday}
</if>
<if test="contact != null and '' != contact">
and a.contact = #{contact}
</if>
<if test="email != null and '' != email">
and a.email = #{email}
</if>
<if test="roomsid != null and '' != roomsid">
and a.roomsid = #{roomsid}
</if>
<if test="status != null and '' != status">
and a.status = #{status}
</if>
<if test="regdate != null and '' != regdate">
and a.regdate = #{regdate}
</if>
</select>
<!-- 按条件模糊查询 DAO通过id调用此配置 -->
<select id="getUsersByLike" parameterType="users" resultMap="usersMap">
select a.* , b.roomsname from users a , rooms b where a.roomsid = b.roomsid
<if test="username != null and '' != username">
and a.username like CONCAT('%', CONCAT(#{username}, '%'))
</if>
<if test="password != null and '' != password">
and a.password like CONCAT('%', CONCAT(#{password}, '%'))
</if>
<if test="realname != null and '' != realname">
and a.realname like CONCAT('%', CONCAT(#{realname}, '%'))
</if>
<if test="sex != null and '' != sex">
and a.sex like CONCAT('%', CONCAT(#{sex}, '%'))
</if>
<if test="birthday != null and '' != birthday">
and a.birthday like CONCAT('%', CONCAT(#{birthday}, '%'))
</if>
<if test="contact != null and '' != contact">
and a.contact like CONCAT('%', CONCAT(#{contact}, '%'))
</if>
<if test="email != null and '' != email">
and a.email like CONCAT('%', CONCAT(#{email}, '%'))
</if>
<if test="roomsid != null and '' != roomsid">
and b.roomsname like CONCAT('%', CONCAT(#{roomsid}, '%'))
</if>
<if test="status != null and '' != status">
and a.status like CONCAT('%', CONCAT(#{status}, '%'))
</if>
<if test="regdate != null and '' != regdate">
and a.regdate like CONCAT('%', CONCAT(#{regdate}, '%'))
</if>
</select>
</mapper>