MyBatis传入参数的问题
来源:互联网 发布:剑灵龙族男捏脸数据 编辑:程序博客网 时间:2024/05/18 18:55
一、单个参数
1、基本数据类型
(1)直接使用
List<ChargeRuleDO> tests(long id); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{id} #{}中的参数名与方法中的参数名一致 </select>
(2)使用注解
List<ChargeRuleDO> tests(@Param("aid") long bid); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{aid} </select> #{}中的参数名与方法中的@Param()里的参数名一致
2、复杂数据类型(这里主要是指Java实体类)
(1)直接使用
List<ChargeRuleDO> tests(TestQO testQO); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{id} and t.rule_type=#{ruleType} </select> #{}中的参数名与方法中的参数的属性名一致(2)使用注解
List<ChargeRuleDO> tests(@Param("atestQO") TestQO btestQO); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{atestQO.id} and t.rule_type=#{atestQO.ruleType} </select> #{}中的参数名与方法中的@Param()里的参数对应的属性名一致,而且必须写成"#{atestQO.id}"的格式,不能简写成"#{id}".二、多个参数
1、基本数据类型
(1)直接使用
List<ChargeRuleDO> tests(long id,String ruleType); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{0} and t.rule_type=#{1} </select> 这里改用#{index},其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。
(2)使用注解
List<ChargeRuleDO> tests(@Param("id") long id,@Param("ruleType") String ruleType); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{id} and t.rule_type=#{ruleType} </select> #{}中的参数名与方法中的@Param()里的参数名一致
2、复杂数据类型
(1)直接使用
尝试了两种取参数的方法都不行
(2)使用注解
List<ChargeRuleDO> tests(@Param("testQO")TestQO testQO,@Param("testQO2")TestQO2 testQO2); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{testQO.id} and t.rule_type=#{testQO.ruleType} and t.user_id=#{testQO2.uesrId} </select> #{}中的参数名与方法中的@Param()里的参数对应的属性名一致,而且必须写成"#{testQO.id}"的格式,不能简写成"#{id}".3、基本数据类型与复杂数据类型混合使用
因为在多参数的情况下,复杂数据类型不能直接使用,所以这里主要尝试基本数据类型直接使用并且复杂数据类型使用注解这一种情况
List<ChargeRuleDO> tests(long id,String ruleType,@Param("testQO2")TestQO2 testQO2); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id = #{0} and t.rule_type=#{1} and t.user_id=#{testQO2.uesrId} </select>
三、List参数
List<ChargeRuleDO> tests(List<long> list); <select id="tests" resultType="com.xxx.bean.ChargeRuleDO"> select * from t_charge_rule t where t.id in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>
阅读全文
0 0
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- MyBatis传入多个参数的问题
- mybatis 传入多个参数的问题
- MyBatis传入多个参数的问题
- javaScript常用一些方法
- Aladdin and the Flying Carpet 唯一分解定理
- java过滤器——filter的使用和配置
- 单向链表的基本操作
- JavaScript-定时器的使用之无缝滚动
- MyBatis传入参数的问题
- Python Requests Libraries
- 迭代器 生成器
- java迭代器浅析
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂+dp
- 字体图标使用方法——以Iconfont为例
- Lintcode翻转链表
- onclick="function()"和onclick="return function();"区别
- Android OpenGLES2.0(十八)——轻松搞定Blend颜色混合