Mybatis的動態(tài)拼接條件方式
更新時間:2024年02月01日 09:07:05 作者:人月IT
這篇文章主要介紹了Mybatis的動態(tài)拼接條件方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
Mybatis的動態(tài)拼接條件
官網的例子永遠是最好的,切記切記??!
拼接條件
<sql id="select_asset_where"> <if test="accountType != null and accountType.size != 0" > and <foreach collection="accountType" item="param" separator="OR" open="(" close=")"> a.account_type = #{param} </foreach> </if> </sql>
條件查詢
<select id="selectAssetByCondition" parameterType="com.zemcho.controller.asset.dto.AssetConditionDto" resultMap="AssetCondtitionResultMap"> SELECT reg_code, asset_name, asset_type, metering_units, use_info, expect_end_date, regist_man, regist_date, account_type, fee_item, finance_bill_date, user, user_account, keeper, checker, buyer, school_addr, account_book, acquire_way, asset_use_way, write_off_date, asset_status_1, store_place, orginal_value, net_value, number_value FROM tb_asset_regist_d a <if test="assetDepInfo != null" > , cfg_asset_dep_info b </if> <if test="assetTypeInfo != null" > , cfg_asset_type_info c </if> <where> <include refid="select_asset_where"></include> </where> </select>
批量插入
<!-- 批量插入 --> <!-- 批量插入生成的兌換碼 --> <insert id ="insertBulk" parameterType="java.util.List" > <selectKey resultType ="java.lang.Integer" keyProperty= "id" order= "AFTER"> SELECT LAST_INSERT_ID() </selectKey > insert into `tb_basic_treatment_d` (<include refid="Base_Column_List" />,LOAD_TIME) values <foreach collection ="list" item="item" index= "index" separator =","> ( #{item.name}, #{item.teacherNumber}, #{item.idNumber}, #{item.year}, #{item.annualWageIncomeYuan}, #{item.fiveInsuranceAGold}, #{item.loadTime} ) </foreach > </insert >
普通查詢
<select id="selectByReaderNum" parameterType="string" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from tb_library_borrower_d where reader_id = #{num,jdbcType=VARCHAR} limit 1 </select>
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
SpringBoot HikariCP連接池監(jiān)控實現方案
文章介紹了五種監(jiān)控SpringBoot應用程序中HikariCP連接池狀態(tài)和性能的工具和技術,包括SpringBootActuator、Micrometer、Prometheus+Grafana、HikariCP自帶的Metrics以及NewRelic/Datadog等第三方服務,每種方法都有其特點和配置步驟2025-01-01Java中的常用時間日期類總結(Date、DateFormat)
在Java開發(fā)中處理時間和日期是相當常見的任務,無論是計算日期差異、格式化日期顯示、解析日期字符串還是進行日期計算,都需要一些時間和日期處理的技巧,這篇文章主要給大家介紹了關于Java中常用時間日期類(Date、DateFormat)的相關資料,需要的朋友可以參考下2024-08-08