yangyang12138

导航

< 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

统计

mybatis

1.ognl表达式

  $表示引用,#表示取值,%表示取传入字符串的值,@表示执行静态方法,去集合中数据 list[0],定义list {1,2,3,4,5},去map中数据 map[key], 定义map {"a":"1"}

  基本四则运算和比较运算

  投射

复制代码
Person p1 = new Person(1, "11");
Person p2 = new Person(2, "22");
Person p3 = new Person(3, "33");

ArrayList<Person> list = new ArrayList<Person>();
list.add(p1);
list.add(p2);
list.add(p3);

#list.{id}
// [1,2,3]
#list.{name}
// ["11","22","33"]
#list.{? #this.id > 2}
// [{3,"33"}]
#list.{^ #this.id > 1} //id>1的第一个
// [{2,"22"}]
#list.{$ #this.id > 1} //id>1的最后一个
// [{3,"33"}]
复制代码

  创建对象 new 全类名()

2.标签

  if 判断,true则执行其中内容

  

<if test="id != null">
        and id=#{id}
</if>

  choose when otherwise

  choose 的使用很像 Java 中的 switch 语法,当满足第一个 when 条件时,就不去看后续的条件,如果条件都不满足,则执行 otherwise

 trim

  

复制代码
select * from user
    <trim prefix="where" prefixOverrides="or">
        <if test="a != null">
            or a=#{a}
        </if>
        <if test="b != null">
            or b=#{b}
        </if>
    </trim>
复制代码

  where

  

复制代码
<select id="demo">
    select * from tb
    <where>
        <if test="a != null">
            and a=#{a}
        </if>
        <if test="b != null">
            and b=#{b}
        </if>
    </where>
</select>
复制代码

 会自动去除where条件内第一个 and 或者or

set功能与where类似,但是set是在开头加上set关键字

 

foreach 循环

 

posted on   杨杨09265  阅读(15)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2020-03-30 角色标注
点击右上角即可分享
微信分享提示