mybatis 处理参数List<String[]>mybatis bug
·
使用注解方式:(和xml一样)
@Insert("<script>insert into t_ordersetting values" +
"<if test = 'list !=null and list.size()>0'>" +
"<foreach collection = 'list' index ='index' item='ss' separator=','>" +
"(null,'${ss[0]}','${ss[1]}',0)" +
"</foreach>" +
"</if></script>")
public void addBatch(List<String[]> list);
@Delete("<script>delete from t_ordersetting where " +
"<if test='list!=null and list.size()>0'>" +
"<foreach collection='list' index='index' item='item' open='orderDate in (' close=')' separator=','>" +
"'${item[0]}'" +
"</foreach>" +
"</if></script>")
public void delBatch(@Param("list") List<String[]> list);
需要注意的是:这种参数mybatis好像支持的不太友好,动态拼接sql中,只能使用${}的方式,而不能使用#{},这样就容易有sql注入的隐患,不太建议使用这样参数。如果是这种参数,建议修改为list<map>的形式,或者封装为对象,然后进行相应操作。
mybatis之bug:
不知道这是不是mybatis的bug,xml文件也是这种情况。
其他情况还有 数组和列表,比如:Integer[]和list<Integer>,我同事就不能用list<Integer>而只能用Integer[],而我用这两种格式都ok。
我之前还遇到过一个参数,一般是不用加注解也可以,但是遇到了mybatis报错,没有此参数,加了注解@Param就好了。
还有一个情况是使用dubbo做分布式时,mybatis里不支持各种provider,比如:@SelectProvider。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)