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。


版权声明:本文为xjx891111原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。