فهرست منبع

add test case for underline & camel mixed entity by using @TableField

yuxiaobin 7 سال پیش
والد
کامیت
ebdcc6c109

+ 0 - 21
D:/com/baomidou/test/controller/AbcController.java

@@ -1,21 +0,0 @@
-package com.baomidou.test.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.stereotype.Controller;
-
-/**
- * <p>
- * VIEW 前端控制器
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-@Controller
-@RequestMapping("/test/abc")
-public class AbcController {
-
-}
-

+ 0 - 21
D:/com/baomidou/test/controller/UserController.java

@@ -1,21 +0,0 @@
-package com.baomidou.test.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.stereotype.Controller;
-
-/**
- * <p>
- * 用户表 前端控制器
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-@Controller
-@RequestMapping("/test/user")
-public class UserController {
-
-}
-

+ 0 - 81
D:/com/baomidou/test/entity/Abc.java

@@ -1,81 +0,0 @@
-package com.baomidou.test.entity;
-
-import java.util.Date;
-import com.baomidou.mybatisplus.annotations.TableField;
-import com.baomidou.mybatisplus.annotations.TableField;
-import com.baomidou.mybatisplus.activerecord.Model;
-import java.io.Serializable;
-
-/**
- * <p>
- * VIEW
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-public class Abc extends Model<Abc> {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 主键
-     */
-    private String id;
-    /**
-     * aa
-     */
-    private Date type;
-    @TableField("abc_aa")
-    private String abcAa;
-    @TableField("A_as")
-    private String as;
-
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public Date getType() {
-        return type;
-    }
-
-    public void setType(Date type) {
-        this.type = type;
-    }
-
-    public String getAbcAa() {
-        return abcAa;
-    }
-
-    public void setAbcAa(String abcAa) {
-        this.abcAa = abcAa;
-    }
-
-    public String getAs() {
-        return as;
-    }
-
-    public void setAs(String as) {
-        this.as = as;
-    }
-
-    @Override
-    protected Serializable pkVal() {
-        return this.id;
-    }
-
-    @Override
-    public String toString() {
-        return "Abc{" +
-        ", id=" + id +
-        ", type=" + type +
-        ", abcAa=" + abcAa +
-        ", as=" + as +
-        "}";
-    }
-}

+ 0 - 87
D:/com/baomidou/test/entity/User.java

@@ -1,87 +0,0 @@
-package com.baomidou.test.entity;
-
-import java.util.Date;
-import com.baomidou.mybatisplus.annotations.TableField;
-import com.baomidou.mybatisplus.activerecord.Model;
-import com.baomidou.mybatisplus.annotations.TableName;
-import java.io.Serializable;
-
-/**
- * <p>
- * 用户表
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-@TableName("mp_user")
-public class User extends Model<User> {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 主键
-     */
-    private String id;
-    /**
-     * 用户名
-     */
-    private String name;
-    /**
-     * 创建时间
-     */
-    private Date ctime;
-    /**
-     * 密码
-     */
-    @TableField("abc_password")
-    private String abcPassword;
-
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public Date getCtime() {
-        return ctime;
-    }
-
-    public void setCtime(Date ctime) {
-        this.ctime = ctime;
-    }
-
-    public String getAbcPassword() {
-        return abcPassword;
-    }
-
-    public void setAbcPassword(String abcPassword) {
-        this.abcPassword = abcPassword;
-    }
-
-    @Override
-    protected Serializable pkVal() {
-        return this.id;
-    }
-
-    @Override
-    public String toString() {
-        return "User{" +
-        ", id=" + id +
-        ", name=" + name +
-        ", ctime=" + ctime +
-        ", abcPassword=" + abcPassword +
-        "}";
-    }
-}

+ 0 - 16
D:/com/baomidou/test/mapper/AbcMapper.java

@@ -1,16 +0,0 @@
-package com.baomidou.test.mapper;
-
-import com.baomidou.test.entity.Abc;
-import com.baomidou.mybatisplus.mapper.BaseMapper;
-
-/**
- * <p>
- * VIEW Mapper 接口
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-public interface AbcMapper extends BaseMapper<Abc> {
-
-}

+ 0 - 16
D:/com/baomidou/test/mapper/UserMapper.java

@@ -1,16 +0,0 @@
-package com.baomidou.test.mapper;
-
-import com.baomidou.test.entity.User;
-import com.baomidou.mybatisplus.mapper.BaseMapper;
-
-/**
- * <p>
- * 用户表 Mapper 接口
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-public interface UserMapper extends BaseMapper<User> {
-
-}

+ 0 - 13
D:/com/baomidou/test/mapper/xml/AbcMapper.xml

@@ -1,13 +0,0 @@
-<?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.baomidou.test.mapper.AbcMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.baomidou.test.entity.Abc">
-        <id column="id" property="id" />
-        <result column="type" property="type" />
-        <result column="abc_aa" property="abcAa" />
-        <result column="A_as" property="as" />
-    </resultMap>
-
-</mapper>

+ 0 - 13
D:/com/baomidou/test/mapper/xml/UserMapper.xml

@@ -1,13 +0,0 @@
-<?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.baomidou.test.mapper.UserMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.baomidou.test.entity.User">
-        <id column="id" property="id" />
-        <result column="name" property="name" />
-        <result column="ctime" property="ctime" />
-        <result column="abc_password" property="abcPassword" />
-    </resultMap>
-
-</mapper>

+ 0 - 16
D:/com/baomidou/test/service/IAbcService.java

@@ -1,16 +0,0 @@
-package com.baomidou.test.service;
-
-import com.baomidou.test.entity.Abc;
-import com.baomidou.mybatisplus.service.IService;
-
-/**
- * <p>
- * VIEW 服务类
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-public interface IAbcService extends IService<Abc> {
-
-}

+ 0 - 16
D:/com/baomidou/test/service/IUserService.java

@@ -1,16 +0,0 @@
-package com.baomidou.test.service;
-
-import com.baomidou.test.entity.User;
-import com.baomidou.mybatisplus.service.IService;
-
-/**
- * <p>
- * 用户表 服务类
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-public interface IUserService extends IService<User> {
-
-}

+ 0 - 20
D:/com/baomidou/test/service/impl/AbcServiceImpl.java

@@ -1,20 +0,0 @@
-package com.baomidou.test.service.impl;
-
-import com.baomidou.test.entity.Abc;
-import com.baomidou.test.mapper.AbcMapper;
-import com.baomidou.test.service.IAbcService;
-import com.baomidou.mybatisplus.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * VIEW 服务实现类
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-@Service
-public class AbcServiceImpl extends ServiceImpl<AbcMapper, Abc> implements IAbcService {
-
-}

+ 0 - 20
D:/com/baomidou/test/service/impl/UserServiceImpl.java

@@ -1,20 +0,0 @@
-package com.baomidou.test.service.impl;
-
-import com.baomidou.test.entity.User;
-import com.baomidou.test.mapper.UserMapper;
-import com.baomidou.test.service.IUserService;
-import com.baomidou.mybatisplus.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * 用户表 服务实现类
- * </p>
- *
- * @author hubin
- * @since 2018-03-20
- */
-@Service
-public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
-
-}

+ 0 - 19
D:/test/my_Abc.java

@@ -1,19 +0,0 @@
-package com.baomidou.test.entity;
-
-
-/**
- * <p>
- * 测试自定义DTO模板  VIEW
- * </p>
- * 测试注入 hubin-mp
- */
-
-// 自定义的查询内容
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2

+ 0 - 19
D:/test/my_User.java

@@ -1,19 +0,0 @@
-package com.baomidou.test.entity;
-
-
-/**
- * <p>
- * 测试自定义DTO模板  用户表
- * </p>
- * 测试注入 hubin-mp
- */
-
-// 自定义的查询内容
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2
-    自定义 abc 内容: 1
-    自定义 def 内容: 2

+ 62 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2HorseCamelUnderMixTest.java

@@ -0,0 +1,62 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.test.h2.base.AbstractH2UserTest;
+import com.baomidou.mybatisplus.test.h2.entity.mapper.H2CamelUnderlineMixMapper;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Horse;
+
+/**
+ * <p>
+ * Mybatis Plus H2 Junit Test
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2-mvc.xml"})
+public class H2HorseCamelUnderMixTest extends AbstractH2UserTest {
+
+    @Autowired
+    H2CamelUnderlineMixMapper camelUnderlineMixMapper;
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2-mvc.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            initData(conn, "horse.ddl.sql", "horse.insert.sql", "h2horse");
+        }
+    }
+
+    @Test
+    public void testInsert() {
+        H2Horse horse = new H2Horse();
+        horse.setTestDate(new Date()).setTestType(3);
+        horse.setName("horse");
+        camelUnderlineMixMapper.insert(horse);
+        List<H2Horse> list = camelUnderlineMixMapper.selectList(new EntityWrapper<H2Horse>());
+        for(H2Horse horse1: list){
+            System.out.println(horse1);
+        }
+    }
+
+}

+ 16 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2CamelUnderlineMixMapper.java

@@ -0,0 +1,16 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2Horse;
+
+/**
+ * <p>
+ * 这里继承自定义父类 SuperMapper
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2CamelUnderlineMixMapper extends SuperMapper<H2Horse> {
+
+
+}

+ 103 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2Horse.java

@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+import com.baomidou.mybatisplus.test.h2.entity.SuperEntityCamel;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author yuxiaobin
+ */
+@Data
+@Accessors(chain = true)
+@TableName("h2horse")
+public class H2Horse extends SuperEntityCamel {
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "testType", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @TableField(value = "test_date")
+	private Date testDate;
+
+    @Version
+    private Integer version;
+
+
+    public H2Horse() {
+
+    }
+
+    public H2Horse(String name) {
+        this.name = name;
+    }
+
+    public H2Horse(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2Horse(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2Horse(Long id, String name) {
+        this.setId(id);
+        this.name = name;
+    }
+
+    public H2Horse(Long id, Integer age) {
+        this.setId(id);
+        this.age = age;
+    }
+
+    public H2Horse(Long id, String name, Integer age, Integer testType) {
+        this.setId(id);
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2Horse(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+}

+ 2 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserLogicDelete.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotations.TableField;
 import com.baomidou.mybatisplus.annotations.TableId;
 import com.baomidou.mybatisplus.annotations.TableLogic;
 import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.enums.FieldFill;
 import com.baomidou.mybatisplus.enums.FieldStrategy;
 import com.baomidou.mybatisplus.enums.IdType;
 
@@ -52,7 +53,7 @@ public class H2UserLogicDelete {
     @TableLogic
     private Integer version;
 
-    @TableField(value = "last_updated_dt")
+    @TableField(value = "last_updated_dt", fill = FieldFill.UPDATE)
     private Timestamp lastUpdatedDt;
 
 }

+ 13 - 0
mybatis-plus-core/src/test/resources/h2/horse.ddl.sql

@@ -0,0 +1,13 @@
+CREATE TABLE IF NOT EXISTS  h2horse (
+	testId BIGINT(20) NOT NULL AUTO_INCREMENT,
+	name VARCHAR(30) NULL DEFAULT NULL ,
+	age INT(11) NULL DEFAULT NULL ,
+	testType INT(11) NULL ,
+	test_date DATETIME NULL DEFAULT NULL,
+	price DECIMAL(10,2) NULL DEFAULT NULL,
+	desc VARCHAR(30) NULL DEFAULT NULL ,
+	version INT(5) NULL DEFAULT NULL,
+	lastUpdatedDt TIMESTAMP NULL,
+	PRIMARY KEY (testId)
+)
+

+ 5 - 0
mybatis-plus-core/src/test/resources/h2/horse.insert.sql

@@ -0,0 +1,5 @@
+insert into h2horse(testId, name, test_date, age, price, testType, version) values (101,'Tomcat', '2017-1-1 1:1:1', 3, 9.99, 1, 1),
+insert into h2horse(testId, name, test_date, age, price, testType, version) values (102,'Jerry', '2017-3-1 1:1:1', 2, 19.99, 2, 2);
+insert into h2horse(testId, name, test_date, age, price, testType, version) values (103,'Bob', '2017-4-1 1:1:1', 13, 99.99, 3, 3);
+insert into h2horse(testId, name, test_date, age, price, testType, version) values (104,'Joe', '2017-2-1 1:1:1', 18, 1.99, 1, 4);
+insert into h2horse(testId, name, test_date, age, price, testType, version) values (105,'Tony', '2017-2-1 1:1:1', 18, 1.99, 1, 5);