首页 > 其他分享 >mybatis 常用标签

mybatis 常用标签

时间:2024-04-29 11:12:21浏览次数:14  
标签:常用 标签 SELECT CONCAT mybatis id select user

xml 模板

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper接口全限定名">

</mapper>

if

<!-- 字符串 -->
<if test = "studentName != null and studentName !='' ">     
     
</if> 
<!-- 集合 -->
<if test = "idList != null and idList.size() > 0 ">     
     
</if> 

foreach

<delete id="deleteBatch"> 
	delete from user where id in
	<foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
  		#{id}
	</foreach>
</delete>

where

<select id="getStudentListWhere" parameterType="StudentEntity" resultMap="studentResultMap">     
SELECT * from t_user    
<where>
    <!-- mybatis 会优化,第一个and会被去掉,所以当多个条件时第一个 and 要不要都可以 -->
    <if test="studentName!=null and studentName!='' ">     
   		AND name LIKE CONCAT(CONCAT('%', #{studentName}),'%')      
    </if>     
    <if test="studentSex!= null and studentSex!= '' ">     
    	AND sex = #{studentSex}      
    </if>   
</where> 
</select>

choose

<select id="selectUserByStatus" parameterType="String" resultType="User">
    SELECT * FROM users
    <where>
        <choose>
            <!-- 当传入的状态为 'active' 时,选择此条件 -->
            <when test="status == 'active'">
                and is_active = 1
            </when>
            <!-- 当传入的状态为 'inactive' 时,选择此条件 -->
            <when test="status == 'inactive'">
                and is_active = 0
            </when>
            <!-- 如果没有匹配的 <when> 条件,则执行 <otherwise> 中的内容 -->
            <otherwise>
                and id = -1  <!-- 假设不可能有ID为-1的用户 -->
            </otherwise>
        </choose>
    </where>
</select>

include

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper接口全限定名">
    <!-- 定义标签 -->
    <sql id="sql_count">
            select count(*)
    </sql>
    <sql id="sql_select">
            select *
    </sql>
    
    <!-- 使用标签 -->
    <select id="selectCount" resultType="com.iot.site.module.quote.entity.Quote">
    	<include refid = "sql_count"/> from site_quote
	</select>
</mapper>

标签:常用,标签,SELECT,CONCAT,mybatis,id,select,user
From: https://www.cnblogs.com/hangychn/p/18165245

相关文章

  • git常用命令
    gitinit初始化-在一个文件夹下创建.git隐藏文件(如果子目录存在.git需要先进行删除,否则提示创建失败)gitclone克隆代码库gitpush/pull推代码/拉代码gitbranch--sort=committerdate按提交的时间顺序进行展示分支gitcheckout-b创建并切换分支gitcheckout切......
  • C# Winform常用控件缩写大全
    平常写小工具经常用到Winform编写测试工具,经常忘记控件缩写,所以在网上看了篇文章后,把他记录下来,方便自己查找。标准控件1btnButton2chkCheckBox3cklCheckedListBox4cmbComboBox5dtpDateTimePicker6lblLabel7llbLinkLabel8lstListBox9lvwListView10m......
  • WordPress操作文章类常用的动作钩子
    publish_post:参数一个($post_ID),点击发布文章时就会被触发;save_post:参数一个($post_ID),发布或更新文章时就会被触发;edit_post:参数两个($post_ID,$post),只要编辑已经存在的文章就会被触发;publish_future_post:参数一个($post_ID),到定时发布文章设定的时间点就会被触发,如果设定的时间早于......
  • mybatis乐观锁批量更新和单个更新
    拦截器packagecom.esolution.xreport.config;importcom.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;importcom.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;importorg.springframework.context.annotation.......
  • [转]<a>标签超链接跳转到第三方系统提示:The Http request is not acceptable for the
    原文地址:TheHttprequestisnotacceptablefortherequestedresource.-CSDN博客1.问题描述在做一个点击本系统的一个按钮打开第三方链接并跳转新页面,跳转过去的第三方链接由https://ip地址组成,报以下错:TheHttprequestisnotacceptablefortherequestedresource.2.......
  • SecureCRT常用技巧
    鼠标复制:(常用)options ->globaloptions-> Terminal 钩上Copyonselect,并钩上pasteon【right】button这样在SecureCRT中用鼠标选中一段字符,就可以直接复制到剪切板,按鼠标右键完成粘贴。双击复制并打开新session:(常用)options->globaloptions->Terminal->Tabs......
  • HydroOJ 从入门到入土(15)批量修改题目标签(tag)
    选择还是分支?这是一个problem。好消息:搞到了一批题目!坏消息:题目没有标签好消息:导入的题目有标签!坏消息:题目标签和自己的不一样好消息:标签全部手动改完了!坏消息:还是觉得第一版好一、需求虽然理论上应该是导入之前就把标签全部调整好再导入,但实际上,导入之前调整标签并......
  • 最近常用的几个【行操作】的Pandas函数
    最近在做交易数据的统计分析时,多次用到数据行之间的一些操作,对于其中的细节,简单做了个笔记。1.shfit函数shift函数在策略回测代码中经常出现,计算交易信号,持仓信号以及资金曲线时都有涉及。这个函数的主要作用是将某列的值上下移动。默认情况下,shift函数是向下移动一行,移动后,新......
  • SpringBoot中几种好用的代码生成器(基于Mybatis-plus生成entity、mapper、xml等)
    前言熟悉Spring框架的同学一定都知道MVC开发模式吧,控制器(Controller)、业务类(Service)、持久层(Repository)、数据库映射(Mapper)、各种DO类构成了我们服务端的代码。初学的时候,觉得新鲜手写这些东西不觉得有啥,但是写久了就会觉得很烦。好不容易在数据库中写完了一遍字段,在Java代码又要......
  • Pacemaker常用命令
    crmconfigureshow#查看配置信息 说明:资源组名为zavipg,包含有zatest和vip01两个资源。vip为10.10.206.229,通过systemd监控zabbix_agentd服务,监控周期为3s,超时时间为15s,失败后置为状态standby;通过location配置资源约束,首选运行节点为centos20624,通过#uname识别 pcsstat......