<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qf.Mapper.UserMapper">
<resultMap id="UserVsOrder" type="UserVO">
<id column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="phone" property="phone"/>
<result column="create_time" property="createTime"/>
<result column="money" property="money"/>
<result column="sex" property="sex"/>
<!-- 一对多关联映射使用collection标签 -->
<!-- property是UserVO类中关联的属性 -->
<!-- 不是javaType,是ofType,是指定集合中存储的数据类型 -->
<collection property="orderList" ofType="com.qf.model.Order">
<id column="oid" property="oid"/>
<result column="order_time" property="orderTime"/>
<result column="order_desc" property="orderDesc"/>
<result column="uid" property="uid"/>
</collection>
</resultMap>
<!--为了演示动态sql,foreach-->
<delete id="deleteBathch">
delete from tb_user where id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="FindVSByid" resultMap="UserVsOrder">
select*from tb_user u,tb_order o where u.id=o.uid and u.id=1
</select>
<sql id="userFied">
id,username,password,phone,createTime,money,sex
</sql>
<select id="FindAll" resultType="User">
select * from tb_user where id = #{id}
</select>
<select id="FindByall" resultType="com.qf.model.User">
select
<include refid="userFied"/>
from tb_user
</select>
<select id="FindByLogin" resultType="com.qf.model.User">
<!-- select*from tb_user where username=#{username} and password=#{password}//1-->
select*from tb_user where username=#{param1} and password=#{param2}
</select>
<select id="findUserByLoginMap" resultType="com.qf.model.User">
select*from tb_user where username=#{usernameKey} and password=#{passwordKey}
</select>
<insert id="addUser">
insert into tb_user values(#{id},#{username},#{password},#{phone},#{createTime},#{money},#{sex});
</insert>
<update id="updateUser">
update tb_user
<!-- set标签自动拼接SET关键词 -->
<set>
<!-- 会自动过滤最后一个, -->
<!-- 特别注意,因为判断条件是!=null,基本不可能为null,所以将基本类型变为包装类 -->
<if test="username != null">username = #{username},</if>
<if test="password != null">password = #{password},</if>
<if test="phone != null">phone = #{phone},</if>
<if test="createTime != null">createTime = #{createTime},</if>
<if test="money != null">money = #{money},</if>
<if test="sex != null">sex = #{sex},</if>
</set>
where id = #{id}
</update>
<!-- <update id="updateUser">-->
<!-- update tb_user set username=#{username},password=#{password},-->
<!-- phone= #{phone},createTime=#{createTime},money=#{money},sex=#{sex}-->
<!-- where id = #{id}-->
<!-- </update>-->
<delete id="deleteUser">
delete from tb_user where id=#{id}
</delete>
</mapper>
insert
<insert id="addUser">
insert into tb_user values(#{id},#{username},#{password},#{phone},#{createTime},#{money},#{sex});
</insert>
select
<select id="FindByLogin" resultType="com.qf.model.User">
<!-- select*from tb_user where username=#{username} and password=#{password}//1-->
select*from tb_user where username=#{param1} and password=#{param2}
</select>
<select id="findUserByLoginMap" resultType="com.qf.model.User">
select*from tb_user where username=#{usernameKey} and password=#{passwordKey}
</select>
<?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:命名空间,用于隔离sql,还有一个很重要的作用,后面会讲 -->
<mapper namespace="User">
<!-- 通过Id查询一个用户 -->
<select id="findUserById" parameterType="Integer"
resultType="com.mybatis.entity.User">
select * from user where id = #{id}
</select>
<!-- 根据用户名模糊查询用户列表 -->
<!-- select * from user where username like "%"#{value}"%" -->
<select id="findUserByUsername" parameterType="String"
resultType="com.mybatis.entity.User">
select * from user where username like #{username}
</select>
<!-- 添加用户 -->
<insert id="insertUser"
parameterType="com.mybatis.entity.User">
insert into user (username,birthday,address,sex)
values(#{username},#{birthday},#{address},#{sex})
</insert>
<!-- 更新用户 -->
<update id="updateUser"
parameterType="com.mybatis.entity.User">
update user
set username = #{username},sex =
#{sex},birthday = #{birthday},address = #{address}
where id = #{id}
</update>
<!-- 删除用户 -->
<delete id="deleteUserById" parameterType="Integer">
delete from user
where
id = #{id}
</delete>
</mapper>