mybatis学习笔记1

mybatis更新操作:https://blog.csdn.net/zongf0504/article/details/100103927

提醒:<set>会自动删除末尾的逗号

mybatis查询操作:

方式1:

select * from student  where 1=1 <if test="name!=null"> and name=#{name}</if>

方式2:

select * from student

<where>

    <if test="name!=null">

        and name=#{name}

    </if>

</where>

提醒<where>会自动删除开始的and

#和$的区别:http://www.mybatis.cn/archives/70.html    ,https://blog.csdn.net/zhangyong01245/article/details/90768156

#{}在预编译阶段会转化为占位符?

${}直接变量替换,${}容易引发SQL注入,存在安全隐患

提一个$()的使用场景:${}可以进行参数运算

select * from student order by create_time desc limit  ${(startPage-1)*pageSize},#{pageSize}

 mybatis中的如果使用like的话如何进行字符串拼接?

select * from student  where name like concat('%',#{name},'%')

mybatis插入操作:主键id使用自增id,不需要用户插入,使用下面的写法:

<insert id="" parameterType="" useGeneratedKeys="true" keyProperty="id" keyColumn="id">

</insert>

posted on 2022-03-09 19:53  朱古力88  阅读(23)  评论(0编辑  收藏  举报