1
This commit is contained in:
+40
@@ -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;
|
||||
}
|
||||
+23
@@ -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<KeyTest> {
|
||||
void updateOrsave(@Param("sku_code")String sku_code,@Param("w_code")String w_code,@Param("data")String data);
|
||||
|
||||
void batchSaveOrUpdate(List<KeyTest>list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+13
@@ -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<KeyTest> {
|
||||
|
||||
}
|
||||
+22
@@ -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<KeyTestMapper, KeyTest>
|
||||
implements KeyTestService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.wyl.springbootmybatis.mybatis.mapper.KeyTestMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.wyl.springbootmybatis.mybatis.domain.KeyTest">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="skuCode" column="sku_code" jdbcType="VARCHAR"/>
|
||||
<result property="wCode" column="w_code" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,sku_code,w_code
|
||||
</sql>
|
||||
<update id="updateOrsave">
|
||||
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}
|
||||
</update>
|
||||
|
||||
<insert id="batchSaveOrUpdate" parameterType="java.util.List">
|
||||
insert into key_test (
|
||||
sku_code,
|
||||
w_code,
|
||||
data
|
||||
)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(
|
||||
#{item.skuCode},
|
||||
#{item.wCode},
|
||||
#{item.data}
|
||||
)
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
sku_code = VALUES (sku_code),
|
||||
w_code = VALUES (w_code),
|
||||
data = VALUES (data)
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user