123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?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">
- <mapper namespace="com.lc.mapper.UserMapper">
- <!--
- 动态sql if 标签
- test="" OGNL 表达式
- select * from t_user where and password = ? sql 问题
- -->
- <select id="getUserByNameAndPass" resultType="user" >
- select * from t_user
- <where>
- <if test="name != null and name != '' ">
- username = #{name}
- </if>
- <if test="pass != null and pass != '' ">
- and password = #{pass}
- </if>
- </where>
- </select>
- <!--
- set 解决 逗号问题
- -->
- <update id="updateUserById">
- UPDATE `db2`.`t_user`
- <set>
- <if test=" username != null and username != '' ">
- `username` = #{username},
- </if>
- <if test=" password != null and password != '' ">
- `password` = #{password},
- </if>
- <if test=" gender != null and gender != '' ">
- `gender` = #{gender},
- </if>
- <if test=" address != null and address != '' ">
- `address` = #{address},
- </if>
- <if test=" deptId != null and deptId != '' ">
- `dept_id` = #{deptId}
- </if>
- </set>
- <where>
- <if test="id != null and id !='' ">
- `id` = #{id} ;
- </if>
- </where>
- </update>
- <!--
- trim
- 属性
- prefix 前缀
- prefixOverrides 覆盖前缀
- suffix 后缀
- suffixOverrides 覆盖后缀
- -->
- <select id="getUserByNameAndPassTrim" resultType="user" >
- select * from t_user
- <trim prefix="where" prefixOverrides="and" >
- <if test="name != null and name != '' ">
- and username = #{name}
- </if>
- <if test="pass != null and pass != '' ">
- and password = #{pass}
- </if>
- </trim>
- </select>
- <!--
- foreach
- collection 集合
- open 开始符号
- close 结尾
- separator 中间符号
- index 索引
- item 每一项
- -->
- <select id="getUserByIds" resultType="user" >
- select
- <include refid="userSql"></include>
- from t_user where id in
- <foreach collection="ids" open="(" item="id" separator="," close=")">
- #{id}
- </foreach>
- </select>
- <!--
- sql 片段
- -->
- <sql id="userSql">
- username , password , gender , address , dept_id
- </sql>
- </mapper>
|