mybatis 常用语句

1. <!--查询id字段的最大值-->  

<select id="queryMaxId" resultType="Integer">  select COALESCE (Max(gid),0) as gid from t25175_grade  </select></mapper>

2.<!--批量删除-->Boolean deleteMany(String[] str);

<delete id="deleteMany">    delete from t25175_student where studentid in

<foreach collection="array" item="studentid" open="(" separator="," close=")">        #{studentid}

</foreach></delete>

3.<!--多条件框模糊查询-->

<select id="findLike" resultMap="BaseResultMap">    select* from t25175_student

<where>        <!--添加if条件如果参数为空则不拼接sql-->

        <if test="studentid != null and studentid != '' ">            studentid like concat('%',#{studentid},'%')

        </if>        <if test="gid != null and gid != '' ">            and gid like concat('%',#{gid},'%')

        </if>        <if test="cid != null and cid.size > 0 ">            and cid in

<foreach item="cid" index="index" collection="cid"

                    open="(" separator="," close=" )">#{cid}

            </foreach>        </if>       

    </where>order by studentid

</select>

4.<!--根据grade和studenclass查找所有的学生信息-->

<select id="selectAllByStudentclass"  resultMap="BaseResultMap">    select* from t25175_student

<where>        <foreach item="grade" index="index" collection="grade"

                separator="or">        <foreach item="studentclass" index="index" collection="studentclass"

                  separator="or" >        (grade=#{grade} and studentclass=#{studentclass})

</foreach>        </foreach>    </where></select>

5.<!--根据cid查找所有的学生信息-->

<select id="selectAllByCid" parameterType="java.util.List"  resultMap="BaseResultMap">    select* from t25175_student

<where>cid in

<foreach item="cid" index="index" collection="list"

            open="(" separator="," close=" )">#{cid}

    </foreach></where></select>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mybatis 1.如何批量插入数据 SQL层面 先复习一下单条/批量插入数据的sql语句怎么写: 1. 单条插入...
    vincent519阅读 4,320评论 0 0
  • 用来循环容器的标签forEach,查看例子 foreach元素的属性主要有item,index,collectio...
    Java面试指南阅读 3,106评论 0 0
  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 4,816评论 0 0
  • MyBatis是一个优秀的持久层框架,它主要是完成对操作数据库的过程进行封装。它以xml或注解的方式将要执行的各种...
    当有和煦微风阅读 1,313评论 0 0
  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 4,979评论 0 7