Mybatis的動(dòng)態(tài)拼接條件方式
更新時(shí)間:2024年02月01日 09:07:05 作者:人月IT
這篇文章主要介紹了Mybatis的動(dòng)態(tài)拼接條件方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
Mybatis的動(dòng)態(tài)拼接條件
官網(wǎng)的例子永遠(yuǎn)是最好的,切記切記?。?/strong>
拼接條件
<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>總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
mybatis如何使用Criteria的and和or進(jìn)行聯(lián)合查詢
這篇文章主要介紹了mybatis如何使用Criteria的and和or進(jìn)行聯(lián)合查詢,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
如何將java -jar啟動(dòng)的服務(wù)設(shè)置為systemd服務(wù)管理方式
本文詳細(xì)介紹了如何將Java應(yīng)用程序配置為由systemd管理的服務(wù),包括創(chuàng)建和配置.service文件的步驟,以及如何啟動(dòng)、停止和查看服務(wù)狀態(tài)2025-01-01
Redis6搭建集群并在SpringBoot中使用RedisTemplate的實(shí)現(xiàn)
本文主要介紹了Redis6搭建集群并在SpringBoot中使用RedisTemplate,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
詳解spring boot容器加載完后執(zhí)行特定操作
這篇文章主要介紹了詳解spring boot容器加載完后執(zhí)行特定操作,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
SpringBoot中@Valid對List校驗(yàn)失效問題的有效解決方法
在Spring Boot應(yīng)用開發(fā)中,我們經(jīng)常需要對傳入的請求參數(shù)進(jìn)行校驗(yàn),以確保數(shù)據(jù)的合法性和安全性,然而,當(dāng)我們嘗試對列表(List)類型的參數(shù)進(jìn)行校驗(yàn)時(shí),可能會(huì)遇到校驗(yàn)失效的問題,本文將詳細(xì)探討這一問題的失效原因,并提供有效的解決方法,需要的朋友可以參考下2025-07-07

