Mybatis之@Select注解

Mybatis之@Select注解

@Select注解基本用法
@Select注解的目的是为了取代xml中的select标签,只作用于方法上面。
抛弃了传统的xml形式

例如(简单的sql)

public interface UserMapper {@Select("SELECT id, name, age FROM user WHERE id = #{userId}")User getUserById(int userId);
}

如果要想实现复杂的逻辑判断(比如if判断、for循环),则必须需要使用<script>标签,如下所示:
但是在<script> 和</script>内不能用>、<=、<、<=等判断语句要用gt;和lt;等转义字符,
具体字符自行百度查看。
以下使用的@Results是为了做出参的映射(xml形式里面也是有这个操作的)

//查询的例子
@Select({"<script>","SELECT T.*," +"        T2.HOLDER_TYPE," +"        T2.HOLDER_ID_TYPE," +"        T2.HOLDER_ID," +"        T2.HOLDER_NAME," +"        T2.LEGAL_REPRESENTATIVE," +"        T2.CONTACT_ID," +"        T2.CONTACT_NAME," +"        T2.CONTACT_PHONE" +"        FROM MATERIAL_INSTANCE T LEFT JOIN MATERIAL_HOLDER T2 ON (T.HOLDER_UNID=T2.UNID)" +"WHERE DELETE_FLAG = 'N'" +"<if test='unid != null and unid !=\"\" '>" +"and T.UNID=#{unid}" +"</if>" +"<if test='unids != null and unids !=\"\" '>" +"and T.UNID IN" +"<foreach collection='unids' item='unid' open='(' separator=',' close=')'> " +"'#{unid}'" +"</foreach>" +"</if>" +"<if test='materialName != null and materialName!=\"\" '>" +"and T.MATERIAL_NAME LIKE CONCAT('%',#{materialName},'%')" +"</if>" +"<if test='licenseNum != null and licenseNum!=\"\" '>" +"and T1.CONTACT_ID=#{licenseNum}" +"</if>" +"<if test='projId != null and projId !=\"\" '>" +"and T.PROJ_ID LIKE CONCAT('%',#{projId},'%')" +"</if>" +"<if test='bizFromSystem != null and bizFromSystem!=\"\" '>" +"and T.BIZ_FROM_SYSTEM=#{bizFromSystem}" +"</if>" +"<if test='catalogCode != null and catalogCode!=\"\" '>" +"and T.CATALOG_CODE LIKE CONCAT('%',#{catalogCode},'%')" +"</if>" +"<if test='materialUnid != null and materialUnid!=\"\" '>" +"and T.MATERIAL_UNID=#{materialUnid}" +"</if>" +"<if test='holderId != null and holderId!=\"\" '>" +"and T2.HOLDER_ID like CONCAT('%',#{holderId},'%')" +"</if>" +"<if test='level != null and level!=\"\" '>" +"and T.LEVEL=#{level}" +"</if>" +"<if test='labels != null and labels!=\"\" '>" +"and T.LABELS=#{labels}" +"</if>" +"<if test='holderName != null and holderName!=\"\" '>" +"and T2.HOLDER_NAME LIKE CONCAT('%',#{holderName},'%')" +"</if>" +"<if test='catalogName != null and catalogName!=\"\" '>" +"and T.CATALOG_NAME LIKE CONCAT('%',#{catalogName},'%')" +"</if>" +"ORDER BY T.CREATE_TIME DESC" +"<if test='limitStartNum != null'>" +"limit ${limitStartNum}, ${countPerPage}" +"</if>","</script>"})@Results({@Result(column = "UNID", property = "unid"),@Result(column = "HOLDER_UNID", property = "holderUnid"),@Result(column = "CATALOG_CODE", property = "catalogCode"),@Result(column = "CATALOG_NAME", property = "catalogName"),@Result(column = "PROJ_ID", property = "projId"),@Result(column = "SERVICE_UNID", property = "serviceUnid"),@Result(column = "SERVICE_CODE", property = "serviceCode"),@Result(column = "MATERIAL_SRC_TYPE", property = "materialSrcType"),@Result(column = "MATERIAL_NAME", property = "materialName"),@Result(column = "MATERIAL_TYPE", property = "materialType"),@Result(column = "VALID_TERM", property = "validTerm"),@Result(column = "FILE_UNID", property = "fileUnid"),@Result(column = "STATUS", property = "status"),@Result(column = "BIZ_FROM_SYSTEM_CODE", property = "bizFromSystemCode"),@Result(column = "BIZ_FROM_SYSTEM", property = "bizFromSystem"),@Result(column = "BIZ_AREA", property = "bizArea"),@Result(column = "RESOURCE_DIR_CODE", property = "resourceDirCode"),@Result(column = "APPLY_ROLE", property = "applyRole"),@Result(column = "REUSE_ENABLE_FLAG", property = "reuseEnableFlag"),@Result(column = "MATERIAL_UNID", property = "materialUnid"),@Result(column = "INSTANCE_MATERIAL_UNID", property = "instanceMaterialUnid"),@Result(column = "HOLDER_TYPE", property = "holderType"),@Result(column = "HOLDER_ID_TYPE", property = "holderIdType"),@Result(column = "HOLDER_ID", property = "holderId"),@Result(column = "HOLDER_NAME", property = "holderName"),@Result(column = "LEGAL_REPRESENTATIVE", property = "legalRepresentative"),@Result(column = "CONTACT_ID", property = "contactId"),@Result(column = "CONTACT_NAME", property = "contactName"),@Result(column = "CONTACT_PHONE", property = "contactPhone"),@Result(column = "LEVEL", property = "level"),@Result(column = "labels", property = "labels"),@Result(column = "CREATE_TIME", property = "createTime"),@Result(column = "RECEIVE_TIME", property = "receiveTime"),@Result(column = "SERVICE_NAME", property = "serviceName"),@Result(column = "MTC_SOURCE_ID", property = "mtcSourceId"),@Result(column = "MATERIAL_FORM", property = "materialForm"),@Result(column = "LABELS", property = "labels"),@Result(column = "EXPAND1", property = "expand1"),@Result(column = "EXPAND2", property = "expand2"),@Result(column = "EXPAND3", property = "expand3"),@Result(column = "EXPAND4", property = "expand4"),@Result(column = "EXPAND5", property = "expand5"),})List<MaterialInstanceCfgFoshanDO> queryForConfig(Map<String, Object> params);
//插入的例子
@Insert({"<script>","insert into material_instance (" +"          UNID," +"          HOLDER_UNID," +"          CATALOG_CODE," +"          CATALOG_NAME," +"          PROJ_ID," +"          SERVICE_UNID," +"          SERVICE_CODE," +"          MATERIAL_SRC_TYPE," +"          MATERIAL_NAME," +"          MATERIAL_TYPE," +"          VALID_TERM," +"          FILE_UNID," +"          STATUS," +"          BIZ_FROM_SYSTEM," +"          BIZ_AREA," +"          RESOURCE_DIR_CODE," +"          APPLY_ROLE," +"          REUSE_ENABLE_FLAG," +"          CREATE_TIME," +"          MATERIAL_UNID," +"        INSTANCE_MATERIAL_UNID," +"        MODIFY_TIME," +"        FINISH_DATE," +"        LEVEL," +"        FROM_FLAG," +"        RECEIVE_TIME," +"        SERVICE_NAME," +"        MTC_SOURCE_ID," +"        HOLDER_ID," +"        VERSION," +"        MATERIAL_FORM," +"        LABELS," +"  EXPAND1," +"  EXPAND2," +"  EXPAND3," +"  EXPAND4," +"  EXPAND5" +")" +"    values (" +"  #{params.unid,jdbcType=VARCHAR}," +"  #{params.holderUnid,jdbcType=VARCHAR}," +"  #{params.catalogCode,jdbcType=VARCHAR}," +"  #{params.catalogName,jdbcType=VARCHAR}," +"  #{params.projId,jdbcType=VARCHAR}," +"  #{params.serviceUnid,jdbcType=VARCHAR}," +"  #{params.serviceCode,jdbcType=VARCHAR}," +"  #{params.materialSrcType,jdbcType=VARCHAR}," +"  #{params.materialName,jdbcType=VARCHAR}," +"  #{params.materialType,jdbcType=CHAR}," +"  #{params.validTerm,jdbcType=INTEGER}," +"  #{params.fileUnid,jdbcType=LONGVARCHAR}," +"  #{params.status,jdbcType=CHAR}," +"  #{params.bizFromSystem,jdbcType=VARCHAR}," +"  #{params.bizArea,jdbcType=VARCHAR}," +"  #{params.resourceDirCode,jdbcType=VARCHAR}," +"  #{params.applyRole,jdbcType=CHAR}," +"  #{params.reuseEnableFlag,jdbcType=CHAR}," +"          #{params.createTime,jdbcType=VARCHAR}," +"          #{params.materialUnid,jdbcType=VARCHAR}," +"          #{params.instanceMaterialUnid,jdbcType=VARCHAR}," +"          #{params.modifyTime,jdbcType=VARCHAR}," +"          #{params.finishDate,jdbcType=VARCHAR}," +"          #{params.level,jdbcType=INTEGER}," +"          #{params.fromFlag,jdbcType=VARCHAR}," +"          #{params.receiveTime,jdbcType=VARCHAR}," +"          #{params.serviceName,jdbcType=VARCHAR}," +"          #{params.mtcSourceId,jdbcType=VARCHAR}," +"          #{params.holderId,jdbcType=VARCHAR}," +"          #{params.version,jdbcType=INTEGER}," +"          #{params.materialForm,jdbcType=VARCHAR}," +"          #{params.labels,jdbcType=VARCHAR}," +"          #{params.expand1,jdbcType=VARCHAR}," +"          #{params.expand2,jdbcType=VARCHAR}," +"          #{params.expand3,jdbcType=VARCHAR}," +"          #{params.expand4,jdbcType=VARCHAR}," +"          #{params.expand5,jdbcType=VARCHAR}" +"    )","</script>"})int insertInstance(@Param("params") MaterialInstanceFoshanDO params);

参考
【1】
https://blog.csdn.net/qq_23126581/article/details/127995866?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-4-127995866-blog-106617681.235v39pc_relevant_yljh&spm=1001.2101.3001.4242.3&utm_relevant_index=7
【2】
https://blog.csdn.net/qq_34134299/article/details/117651500?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117651500-blog-124945028.235%5Ev39%5Epc_relevant_yljh&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117651500-blog-124945028.235%5Ev39%5Epc_relevant_yljh&utm_relevant_index=2

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/216616.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python中import mysql.connector出错无模块,且是已经pip install mysql-connector情况下

已经安装了mysql-connector和mysql-connector-python&#xff0c;使用python连接数据库&#xff0c;导入import mysql.connector仍报错&#xff1a; import mysql.connector# Connect to server cnx mysql.connector.connect(host"127.0.0.1",port3306,user"a…

加班、效率和价值

效率不等于单位时间单位人干的活&#xff0c;而是等于单位时间单位人产出的价值&#xff0c;衡量工作量的难度很大&#xff0c;而如何选择工作重点&#xff0c;挖掘工作价值难度更大。 加班的不可持续在于两点&#xff0c;第一点是对身体和精神的损害&#xff0c;降低内在动力…

视频剪辑进阶指南:批量置入视频封面,增加视频吸引力

在视频剪辑的进阶阶段&#xff0c;除了掌握基本的剪辑技巧和特效处理&#xff0c;还要尝试一些创新的方法来增加视频的吸引力。批量置入视频封面就是一种有效的方式。通过置入吸引的封面&#xff0c;能吸引观众点击视频并提高观看量。下面详细介绍云炫AI智剪如何批量置入视频封…

pandas按行值筛选

之前都没有意识到这个问题&#xff0c;就是pandas取某一行的值的问题 测试代码如下 import pandas as pd import numpy as np df pd.DataFrame({A: foo bar foo bar foo bar foo foo.split(),B: one one two three two two one three.split(),C: np.arange(8), D: np.arange…

Go (一) 基础部分4 -- 文件处理

一、文件基本介绍 1.1、打开一个文件 基本介绍&#xff1a;打开一个文件用于读取&#xff0c;如果操作成功&#xff0c;返回的文件对象的方法可用于读取文件数据。如果出错&#xff0c;错误底层类型是"*.PathError" func Open(name string) (*File, error) name stri…

GO闭包实现原理(汇编级讲解)

go语言闭包实现原理(汇编层解析) 1.起因 今天开始学习go语言,在学到go闭包时候,原本以为go闭包的实现方式就是类似于如下cpp lambda value通过值传递,mutable修饰可以让value可以修改,但是地址不可能一样value通过引用传递,但是在其他地方调用时,这个value局部变量早就释放,…

Tessy — 嵌入式软件单元测试/ 集成测试工具学习

Tessy — 嵌入式软件单元测试/ 集成测试工具 本文章向大家介绍Tessy — 嵌入式软件单元测试/ 集成测试工具,主要包括Tessy — 嵌入式软件单元测试/ 集成测试工具使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。 Tessy 源自…

数据结构第六课 -----排序

作者前言 &#x1f382; ✨✨✨✨✨✨&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f382; ​&#x1f382; 作者介绍&#xff1a; &#x1f382;&#x1f382; &#x1f382; &#x1f389;&#x1f389;&#x1f389…

【Canvas】记录一次从0到1绘制风场空间分布图的过程

前言 &#x1f4eb; 大家好&#xff0c;我是南木元元&#xff0c;热衷分享有趣实用的文章&#xff0c;希望大家多多支持&#xff0c;一起进步&#xff01; &#x1f345; 个人主页&#xff1a;南木元元 目录 背景 前置知识 风场数据 绘制风场 准备工作 生成二维网格 获取…

【BI】FineBI功能学习路径-20231211

FineBI功能学习路径 https://help.fanruan.com/finebi/doc-view-1757.html 编辑数据概述 1.1 调整数据结构 1.2 简化数据 2.1上下合并 2.2其他表添加列 2.3左右合并 新增分析指标 函数参考 https://help.fanruan.com/finereport/doc-view-1897.html 数值函数 日期函数 文…

GeoTools学习笔记

Feature要素&#xff1a; 例子&#xff1a;Csv2Shape.java 创建要素&#xff0c;先创建FeatureType&#xff0c;再创建Feature 根据FeatureCollection&#xff0c;可以创建shapefile https://docs.geotools.org/latest/userguide/library/main/data.html API详解&#xff1a;…

MySql数据库全量备份脚本

#!/bin/bash# 设置数据库连接信息 DB_HOST"localhost" DB_USER"root" DB_PASS"密码" DB_NAMES("db1" "db2" "db3" "db4")# 设置备份目录 BACKUP_DIR"/home/mysql/mysql-back/everyday" # 每天…

【unity小技巧】FPS游戏后坐力制作思路

参考原视频链接 &#xff1a;https://www.bilibili.com/video/BV1j44y1S7fX/ 注意&#xff1a;本文为学习笔记记录&#xff0c;推荐支持原作者&#xff0c;去看原视频自己手敲代码理解更加深入 免责声明&#xff1a;向宇的博客免责声明 文章目录 前言不加后座力效果简单添加后座…

如何在Cloudflare创建自己的反向代理

大家在使用Cloudflare做反向代理的时候会遇到一个问题&#xff0c;命名已经配置好了&#xff0c;但是还是访问不了&#xff0c;是因为Cloudflare的workers.dev域名在中国大陆区域已经被污染无法访问&#xff0c;所以需要自有域名进行解析。 本文的主要内容有以下三部分 1、域…

Linux系统编程:高级IO总结

非阻塞IO基本概念 高级IO核心就一个概念&#xff1a;非阻塞IO。 与该概念相对的&#xff0c;就是我们之前学习过的阻塞IO。 非阻塞IO&#xff08;Non-blocking I/O&#xff09;是一种IO模型&#xff0c;用于实现异步IO操作&#xff0c;使应用程序能够在等待IO操作完成的同时…

C语言-------动物实验

医学部一共进行了 N 场动物实验。 共有三种小动物可用来实验&#xff0c;分别是青蛙、老鼠和兔子。 每次实验都会选取其中一种动物来参与实验&#xff0c;选取数量若干。 现在请你统计一下医学部一共用了多少小动物&#xff0c;每种分别用了多少&#xff0c;每种动物使用数量…

洛谷 P8802 [蓝桥杯 2022 国 B] 出差

文章目录 [蓝桥杯 2022 国 B] 出差题目链接题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1 提示 思路解析CODE [蓝桥杯 2022 国 B] 出差 题目链接 https://www.luogu.com.cn/problem/P8802 题目描述 A \mathrm{A} A 国有 N N N 个城市&#xff0c;编号为 1 … N …

数据库范式(详细介绍)

目录 第一范式&#xff08;原子性&#xff09; 第二范式&#xff08;主键唯一性&#xff09; 第三范式&#xff08;原子性主键唯一性&#xff09; BC范式(3NFplus) 第一范式&#xff08;原子性&#xff09; 确保每列保证原子性&#xff0c;保证这个属性&#xff08;字段&am…

SpringBoot AOP切面实现对自定义注解的属性动态修改

文章目录 需求问题解决方案示例代码 需求 项目中共用了一个redis&#xff0c;而项目中部分代码使用了JetCache的Cached注解。所以需要给Cached动态配置area属性值&#xff0c;用来区分dev和test环境。 问题 自定义注解的属性值需要常量值&#xff0c;即static final修饰&…

升级jdk1.8u391后,加解密部分报错解决

因为修复漏洞,把原来服务器上的jdk1.8进行版本升级,升级后相关的RSA加解密部分报错如下&#xff1a; java.lang.Exception: JCE cannot authenticate the provider BC 修复&#xff1a; 去下载对应jar包 https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18o…