diff --git a/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/domain/KeyTest.java b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/domain/KeyTest.java new file mode 100644 index 0000000..7d11064 --- /dev/null +++ b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/domain/KeyTest.java @@ -0,0 +1,40 @@ +package com.wyl.springbootmybatis.mybatis.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import lombok.Data; + +/** + * 联合唯一索引更新测试 + * @TableName key_test + */ +@TableName(value ="key_test") +@Data +public class KeyTest implements Serializable { + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * + */ + @TableField(value = "sku_code") + private String skuCode; + + /** + * + */ + @TableField(value = "w_code") + private String wCode; + + @TableField(value = "data") + private String data; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/mapper/KeyTestMapper.java b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/mapper/KeyTestMapper.java new file mode 100644 index 0000000..068aa8c --- /dev/null +++ b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/mapper/KeyTestMapper.java @@ -0,0 +1,23 @@ +package com.wyl.springbootmybatis.mybatis.mapper; + +import com.wyl.springbootmybatis.mybatis.domain.KeyTest; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** +* @author wyl +* @description 针对表【key_test(联合唯一索引更新测试)】的数据库操作Mapper +* @createDate 2022-05-18 22:54:18 +* @Entity com.wyl.springbootmybatis.mybatis.domain.KeyTest +*/ +public interface KeyTestMapper extends BaseMapper { + void updateOrsave(@Param("sku_code")String sku_code,@Param("w_code")String w_code,@Param("data")String data); + + void batchSaveOrUpdate(Listlist); +} + + + + diff --git a/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/KeyTestService.java b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/KeyTestService.java new file mode 100644 index 0000000..2979a4a --- /dev/null +++ b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/KeyTestService.java @@ -0,0 +1,13 @@ +package com.wyl.springbootmybatis.mybatis.service; + +import com.wyl.springbootmybatis.mybatis.domain.KeyTest; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author wyl +* @description 针对表【key_test(联合唯一索引更新测试)】的数据库操作Service +* @createDate 2022-05-18 22:54:18 +*/ +public interface KeyTestService extends IService { + +} diff --git a/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/impl/KeyTestServiceImpl.java b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/impl/KeyTestServiceImpl.java new file mode 100644 index 0000000..c5d5a11 --- /dev/null +++ b/spring-boot/spring-boot-mybatis/src/main/java/com/wyl/springbootmybatis/mybatis/service/impl/KeyTestServiceImpl.java @@ -0,0 +1,22 @@ +package com.wyl.springbootmybatis.mybatis.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.wyl.springbootmybatis.mybatis.domain.KeyTest; +import com.wyl.springbootmybatis.mybatis.service.KeyTestService; +import com.wyl.springbootmybatis.mybatis.mapper.KeyTestMapper; +import org.springframework.stereotype.Service; + +/** +* @author wyl +* @description 针对表【key_test(联合唯一索引更新测试)】的数据库操作Service实现 +* @createDate 2022-05-18 22:54:18 +*/ +@Service +public class KeyTestServiceImpl extends ServiceImpl + implements KeyTestService{ + +} + + + + diff --git a/spring-boot/spring-boot-mybatis/src/main/resources/mapper/KeyTestMapper.xml b/spring-boot/spring-boot-mybatis/src/main/resources/mapper/KeyTestMapper.xml new file mode 100644 index 0000000..d9b03d9 --- /dev/null +++ b/spring-boot/spring-boot-mybatis/src/main/resources/mapper/KeyTestMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + id + ,sku_code,w_code + + + insert into key_test (key_test, w_code, data) + values (#{sku_code}, #{w_code}, #{data}) on duplicate key + update sku_code =#{sku_code}, + w_code =#{w_code}, + data =#{data} + + + + insert into key_test ( + sku_code, + w_code, + data + ) + values + + ( + #{item.skuCode}, + #{item.wCode}, + #{item.data} + ) + + on duplicate key update + sku_code = VALUES (sku_code), + w_code = VALUES (w_code), + data = VALUES (data) + +