mybatis xml语法

xml里面的语法

https://www.cnblogs.com/ljsh/p/10928106.html (这个里面有增删改查)

https://www.cnblogs.com/ivin/p/13672530.html

里面也有个for循环。我下面自己有实战记录

 

 

 

怎么调用

https://www.cnblogs.com/coder-Fish/p/15076830.html

 

for循环插入数据

https://blog.csdn.net/xiaoxiaole0313/article/details/109912820

 

for循环实战

xxx_channel

@NoArgsConstructor
@AllArgsConstructor
@Data
public class xxx_channel {
    private long id;
    private long sourceId;      ----这里注意又踩坑 数据库表字段为 source_id 这里要去掉下划线且驼峰写的,超哥说有地方配置的

Lkb_DataCopy

public interface Lkb_DataCopy {//同步渠道表
//    获取目标文件的数据
    @DS("test01")
    List<xxx_channel> xxx_channel_get();

//同步渠道数据
    void c_tbl_xxxx_copy(List<xxx_channel> item);     ---------传了对象 
}

 Dw_Lkb_Server

@Service
public class Dw_Lkb_Server {

    @Autowired
    private Lkb_DataCopy Lkb_DataCopy;

    
    //同步数据edu_dw.cx x xl数据
    public void copyBegin_c_tbl_xxx() {
        //获取表的数据
        List<xxx_channel> aa = Lkb_DataCopy.xxx_channel_get();     //aa为[xxx_channel(id=1, sourceId=10), xxx_channel(id=4, sourceId=10)]
//写入c_tbl_channel  Lkb_DataCopy.c_tbl_xxx_copy(aa); } }

 

xml文件        -----------------这里有批量插入的写法

<insert id="c_tbl_channel_copy">
        INSERT INTO `c_xxx_channel` (`id`, `source_id`) VALUES
        <foreach collection="list" item="item" separator=",">        -----------------这里java对象----格式为 [xxx_channel(id=1, sourceId=10), xxx_channel(id=4, sourceId=10)]
            (#{item.id},#{item.sourceId})                          ----------------注意取的字段要和实体类里面的一致!!!! 踩坑了
        </foreach>
</insert>

 

 

另外一篇实战 https://www.cnblogs.com/kaibindirver/p/15047034.html

 

 

include 引用相同sql块的方法

posted @ 2021-09-08 02:32  凯宾斯基  阅读(328)  评论(0编辑  收藏  举报