Mybatis的动态拼接条件方式
更新时间:2024年02月01日 09:07:05 作者:人月IT
这篇文章主要介绍了Mybatis的动态拼接条件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
Mybatis的动态拼接条件
官网的例子永远是最好的,切记切记!!
拼接条件
<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>总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
mybatis如何使用Criteria的and和or进行联合查询
这篇文章主要介绍了mybatis如何使用Criteria的and和or进行联合查询,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-12-12
如何将java -jar启动的服务设置为systemd服务管理方式
本文详细介绍了如何将Java应用程序配置为由systemd管理的服务,包括创建和配置.service文件的步骤,以及如何启动、停止和查看服务状态2025-01-01
Redis6搭建集群并在SpringBoot中使用RedisTemplate的实现
本文主要介绍了Redis6搭建集群并在SpringBoot中使用RedisTemplate,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2022-04-04
SpringBoot中@Valid对List校验失效问题的有效解决方法
在Spring Boot应用开发中,我们经常需要对传入的请求参数进行校验,以确保数据的合法性和安全性,然而,当我们尝试对列表(List)类型的参数进行校验时,可能会遇到校验失效的问题,本文将详细探讨这一问题的失效原因,并提供有效的解决方法,需要的朋友可以参考下2025-07-07


最新评论