特殊字符
符号![]() |
转译![]() |
描述![]() |
< |
< |
小于 |
<= |
<= |
小于等于 |
> |
> |
大于 |
>= |
>= |
大于等于 |
& |
& |
和 |
' |
' |
单引号 |
" |
" |
双引号 |
IF()
或者if()
| IF(condition, if_true, if_false) |
描述
- condition : 是要检查的条件
- if_true : 是在条件为真时要执行的语句
- if_false : 是在条件为假时要执行的语句
CASE WHEN
| SELECT |
| CASE WHEN STATUS='1' THEN '状态1' |
| WHEN STATUS='2' THEN '状态2' |
| WHEN STATUS='3' THEN '状态3' |
| WHEN STATUS='0' THEN '状态4' |
| ELSE '状态5' END AS '状态' |
| FROM table; |
IFNULL
描述:IFNULL
函数是MySQL控制流函数之一,它接受两个参数,如果不是NULL
,则返回第一个参数。 否则,IFNULL
函数返回第二个参数。
| IFNULL(expression_1,expression_2); |
date(字段)
描述:date()
函数提取日期或日期/时间表达式的日期部分。
| SELECT DATE('2023-9-11 11:02:24') as dateValue |
.jpg)
新增表字段
| ALTER TABLE table ADD column `字段` int(11) DEFAULT NULL COMMENT '字段描述'; |
| ALTER TABLE 表名 ALTER COLUMN 字段名 SET DEFAULT 默认值; |
描述
table
: 表名
字段
:新增字段 例如:project_name
int(11)
: 字段类型
DEFAULT NULL
: 默认为空(NULL)
NOT NULL
: 默认不为空(NULL)
XML参数判空
整型
| <if test="type != null"> |
| </if> |
字符串
| <if test="type != null and type != ''"> |
| </if> |
参数是否相等
整型
| <if test="xxx !=null and xxx !='' or xxx == 0"> |
| </if > |
字符串:方法一
| <if test="params.contractCategory != null and params.contractCategory != '' and params.contractCategory == '2'.toString()"> |
| </if > |
字符串:方法二
| <if test=' delFlag == "2" '> |
| a.del_flag = |
| </if> |
字符串:方法三
| <if test=' delFlag.equals("2") '> |
| a.del_flag = |
| </if> |
CASE WHEN使用
| <choose> |
| <when test="map.userId != null and map.userId != ''"> |
| and register.user_id = #{map.userId} |
| </when> |
| <when test="map.contractCode != null and map.contractCode != ''"> |
| and register.contract_code = #{map.contractCode} |
| </when> |
| <when test="map.entryAuditDate != null and map.entryAuditDate != '' and map.exitAuditDate != null and map.exitAuditDate != '' "> |
| and register.entry_audit_date >= #{map.entryAuditDate} and register.exit_audit_date <= #{map.exitAuditDate} |
| </when> |
| <otherwise> |
| and register.attendance_identification = 0 |
| </otherwise> |
| </choose> |
List使用
| <foreach collection="array" index="index" item="item" open="(" separator="," close=")"> |
| |
| </foreach> |
描述
批量新增
| insert into `tableName`(fieldName1, fieldName2) |
| values |
| <foreach collection="ledgerList" item="ledger" separator=","> |
| ( |
| </foreach> |
描述
- tableName : 表名称
- fieldName1 : 数据库字段(示例 : id)
- fieldName2 : 数据库字段(示例 : user_name)
- ledgerList :List集合
- ledger.fieldName1 :fieldName1 映射实体参数(示例 : id)
- ledger.fieldName2 :fieldName2 映射实体参数(示例 : userName)
List的使用
| <if test="paramsMap.projectIdList != null and paramsMap.projectIdList.size > 0"> |
| AND sfp.project_id in |
| <foreach collection="paramsMap.projectIdList" item="projectId" separator="," open="(" close=")"> |
| |
| </foreach> |
| </if> |
描述
- paramsMap: xml实体别名 示例:@Param("paramsMap")实体类 实体类别名
- projectIdList:List类型集合
List、foreach 、多个参数模糊查询的使用
| <if test="paramsMap.orgLevel != null and paramsMap.orgLevel.size > 0"> |
| AND |
| <foreach collection = "paramsMap.orgLevel" item = "level" open = '(' close = ')' separator = 'OR'> |
| org.level LIKE CONCAT(#{level}, '%') |
| </foreach> |
| </if> |
描述
- paramsMap: 别名 示例:@Param("paramsMap")参数集合 别名
- orgLevel:List类型集合
- paramsMap:Map<String,Object>类型
Integer[]的使用
| <if test="paramsMap.auditStatusList != null and paramsMap.auditStatusList.length > 0"> |
| AND sfp.audit_status in |
| <foreach collection="paramsMap.auditStatusList" item="auditStatus" separator="," open="(" close=")"> |
| |
| </foreach> |
| </if> |
描述
- paramsMap: xml实体别名 示例:@Param("paramsMap")实体类 实体类别名
- auditStatusList:Integer[]类型集合
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理