mybaties 批量更新方法

mxl配置

  
          UPDATE lamp
              
                
                    
                        when gps_num=#{cus.gpsNum} then #{cus.x}
                    
                
                
                    
                        when gps_num=#{cus.gpsNum} then #{cus.y}
                    
                
            
        where gps_num IN
        
            #{item.gpsNum}
        
        

mapper接口

public interface NewLampMapper {
    public void updateLampXY(Map list);
}

测试类

  public void test(){
       ApplicationContext apx = new 
       ClassPathXmlApplicationContext("classpath:spring/applicationContext-
       dao.xml");
        NewLampMapper nl = apx.getBean(NewLampMapper.class);
        String str = "[\n" +
                "{\"x\":115.92734814029478,\"y\":28.70862343857048,\"gpsNum\":\"01005014\"},\n" +
                "{\"x\":115.92774788029477,\"y\":28.708877738570482,\"gpsNum\":\"01005015\"},\n" +
                "{\"x\":115.92806122029478,\"y\":28.709041338570483,\"gpsNum\":\"01005016\"},\n" +
                "{\"x\":115.92823863029479,\"y\":28.708661078570483,\"gpsNum\":\"01054029\"}\n" +
                "]\n";
        List list =  JSON.parseArray(str,JsonBean.class);
        List list1 = new ArrayList();
        Map map = new HashMap();
        for (Object m : list){
            JsonBean bea = (JsonBean)m;
            list1.add(bea);
        }
        map.put("list", list1);
        nl.updateLampXY(map);       

javaBean

public class JsonBean {
    private  double x;
    private  double y;
    private  String  gpsNum;

    public void setX(double x) {
        this.x = x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public void setGpsNum(String gpsNum) {
        this.gpsNum = gpsNum;
    }

    public double getX() {

        return x;
    }

    public double getY() {
        return y;
    }

    public String getGpsNum() {
        return gpsNum;
    }
}

正常执行的完整sql

UPDATE lamp 
    set x=case 
    when gps_num=? then ? 
    when gps_num=? then ?
     when gps_num=? then ? 
    when gps_num=? then ?
     end,
     y=case 
    when  gps_num=? then ?
     when gps_num=? then ?
     when gps_num=? then ?
     when gps_num=? then ?
     end
    where gps_num IN ( ? , ? , ? , ? ) 

你可能感兴趣的:(mybaties 批量更新方法)