随笔 - 81  文章 - 0  评论 - 8  阅读 - 18万

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   朱古力88  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示