服务器之家

服务器之家 > 正文

mybatis动态插入list传入List参数的实例代码

时间:2021-04-22 13:31     来源/作者:Java教程网

mybatis动态插入list的实例代码如下所述:

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<insert id="saveprpcitemkindlist" parametertype="java.util.list">
insert into prpcitemkind
(riskcode, itemkindno, familyno, familyname, projectcode, clausecode,
clausename,
kindcode, kindname, itemno, itemcode, itemdetailname, groupno, modecode,
modename, startdate,
starthour, enddate, endhour, model, buydate, addressno, calculateflag, currency,
unitamount,
quantity, unit, value, amount, rateperiod, rate, shortrateflag, shortrate,
prepremium, calpremium,
basepremium, benchmarkpremium, discount, adjustrate, unitpremium, premium,
deductiblerate, deductible,
flag, inserttimeforhis, operatetimeforhis, taxrate, taxflag, taxfee,
netpremium, taxfee_gb, taxfee_lb, alltaxfee, allnetpremium,proposalno)
<foreach collection="list" item="item" index="index" separator="union all">
<trim prefix="select" suffix="from dual">
<choose>
<when test="item.riskcode != null">#{item.riskcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemkindno != null">#{item.itemkindno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.familyno != null">#{item.familyno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.familyname != null">#{item.familyname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.projectcode != null">#{item.projectcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.clausecode != null">#{item.clausecode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.clausename != null">#{item.clausename},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.kindcode != null">#{item.kindcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.kindname != null">#{item.kindname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemno != null">#{item.itemno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemcode != null">#{item.itemcode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.itemdetailname != null">#{item.itemdetailname},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.groupno != null">#{item.groupno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.modecode != null">#{item.modecode},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.modename != null">#{item.modename},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.startdate != null">#{item.startdate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.starthour != null">#{item.starthour},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.enddate != null">#{item.enddate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.endhour != null">#{item.endhour},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.model != null">#{item.model},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.buydate != null">#{item.buydate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.addressno != null">#{item.addressno},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.calculateflag != null">#{item.calculateflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.currency != null">#{item.currency},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unitamount != null">#{item.unitamount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.quantity != null">#{item.quantity},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unit != null">#{item.unit},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.value != null">#{item.value},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.amount != null">#{item.amount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.rateperiod != null">#{item.rateperiod},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.rate != null">#{item.rate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.shortrateflag != null">#{item.shortrateflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.shortrate != null">#{item.shortrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.prepremium != null">#{item.prepremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.calpremium != null">#{item.calpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.basepremium != null">#{item.basepremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.benchmarkpremium != null">#{item.benchmarkpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.discount != null">#{item.discount},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.adjustrate != null">#{item.adjustrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.unitpremium != null">#{item.unitpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.premium != null">#{item.premium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.deductiblerate != null">#{item.deductiblerate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.deductible != null">#{item.deductible},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.flag != null">#{item.flag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.inserttimeforhis != null">#{item.inserttimeforhis},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.operatetimeforhis != null">#{item.operatetimeforhis},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxrate != null">#{item.taxrate},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxflag != null">#{item.taxflag},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee != null">#{item.taxfee},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.netpremium != null">#{item.netpremium},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee_gb != null">#{item.taxfee_gb},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.taxfee_lb != null">#{item.taxfee_lb},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.alltaxfee != null">#{item.alltaxfee},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="item.allnetpremium != null">#{item.allnetpremium},</when>
<otherwise>null,</otherwise>
</choose>
#{item.proposalno}
</trim>
</foreach>
 </insert>

mybatis 传入list参数的实例代码如下所述:

java代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//dao 代码 如果传入的参数是数组,也一样
void insertdefaultmsg(@param("idslist") arraylist<string> idslist);
//xml文件
<update id="insertdefaultmsg" parametertype="java.util.list">
    update 
     plf_pur_delivery_plan p 
    set
     p.promise_delivery_amount = p.quantity_req,
     p.promise_delivery_time = p.quantity_time 
    where p.id in
    <foreach item="item" collection="idslist" separator="," open="(" close=")" index=""
     #{item, jdbctype=varchar} 
    </foreach> 
  </update>
//如果传入字符串
//service 代码
map<string, string> map = bean.getdatas().get(0);
    string ids = map.get("ids");
    string[] idsarr = ids.split(",");
    string inid = "";
    for (int i = 0; i < idsarr.length; i++) {
      if (i != idsarr.length - 1) {
        inid += "'" + idsarr[i] + "',";
      } else {
        inid += "'" + idsarr[i] + "'";
      }
    }
    list<map<string, string>> list = purdeliveryplandao
        .getplanlistmanual(inid);
//dao层代码
list<map<string, string>> getplanlistmanual(@param("inid") string inid);
//xml 文件
<select id="getplanlistmanual" parametertype="java.lang.string" resulttype="java.util.map">
    select 
     p.supplier_code,
     p.pur_order_no,
     if(
      p.update_times > 0,
      '修改订单',
      '新订单'
     ) as order_type 
    from
     plf_pur_delivery_plan p 
    where p.is_notice = '0'
     and p.is_delete = '1'
     and p.id in(<![cdata[${inid}]]>)
    group by p.supplier_code,
     p.pur_order_no 
    order by p.supplier_code 
  </select>

总结

以上所述是小编给大家介绍的mybatis动态插入list传入list参数的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
返回顶部