Selaa lähdekoodia

fix: #2220 - github - add test case
GlobalConfiguration.setDbColumnUnderline(false)
db column camel

yuxiaobin 5 vuotta sitten
vanhempi
commit
e32d5ce0a8

+ 80 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/ColumnUnderlineFalseTest.java

@@ -0,0 +1,80 @@
+/**
+ * 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.mysql;
+
+import java.util.List;
+
+import org.apache.ibatis.session.SqlSession;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.entity.GlobalConfiguration;
+import com.baomidou.mybatisplus.test.mysql.entity.TblColumnUnderlineFalse;
+import com.baomidou.mybatisplus.test.mysql.mapper.TblColumnUnderlineFalseMapper;
+
+/**
+ * <p>
+ * 数据库字段驼峰命名,属性也是驼峰
+ * 增加测试用例
+ * </p>
+ *
+ * @author hubin sjy
+ * @Date 2016-01-23
+ */
+public class ColumnUnderlineFalseTest extends CrudTest {
+
+    @Override
+    public GlobalConfiguration globalConfiguration() {
+        GlobalConfiguration gc = super.globalConfiguration();
+        /**
+         * 设置,自定义 元对象填充器,实现公共字段自动写入
+         */
+        gc.setMetaObjectHandler(new MyMetaObjectHandler());
+        // gc.setCapitalMode(true);
+        gc.setDbColumnUnderline(false);
+        return gc;
+    }
+
+    /**
+     * RUN 测试
+     * <p>
+     * <p>
+     * MybatisPlus 加载 SQL 顺序:
+     * </p>
+     * 1、加载XML中的SQL<br>
+     * 2、加载sqlProvider中的SQL<br>
+     * 3、xmlSql 与 sqlProvider不能包含相同的SQL<br>
+     * <br>
+     * 调整后的SQL优先级:xmlSql > sqlProvider > crudSql <br>
+     */
+    @Test
+    public void crudTest() {
+        SqlSession session = this.sqlSessionFactory().openSession();
+        TblColumnUnderlineFalseMapper userMapper = session.getMapper(TblColumnUnderlineFalseMapper.class);
+        List<TblColumnUnderlineFalse> list = userMapper.selectList(null);
+        Assert.assertFalse(list.isEmpty());
+        TblColumnUnderlineFalse user = list.get(0);
+        Assert.assertNotNull(user.getId());
+        Assert.assertNotNull(user.getFirstName());
+        Assert.assertNotNull(user.getLastName());
+        /**
+         * 提交
+         */
+        session.commit();
+    }
+
+
+}

+ 26 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/TblColumnUnderlineFalse.java

@@ -0,0 +1,26 @@
+package com.baomidou.mybatisplus.test.mysql.entity;
+
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+import lombok.Data;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2020/4/17
+ */
+@TableName("tbl_column_underline_false")
+@Data
+public class TblColumnUnderlineFalse {
+
+    @TableId("id")
+    private Long id;
+
+    private String firstName;
+
+    private String lastName;
+
+}

+ 15 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/TblColumnUnderlineFalseMapper.java

@@ -0,0 +1,15 @@
+package com.baomidou.mybatisplus.test.mysql.mapper;
+
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.TblColumnUnderlineFalse;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2020/4/17
+ */
+public interface TblColumnUnderlineFalseMapper extends BaseMapper<TblColumnUnderlineFalse> {
+
+}

+ 11 - 0
mybatis-plus-core/src/test/resources/mysql/mysql.sql

@@ -81,3 +81,14 @@ CREATE TABLE `user` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='用户表';
 
 SET FOREIGN_KEY_CHECKS = 1;
+
+DROP TABLE IF EXISTS `tbl_column_underline_false`;
+CREATE TABLE IF NOT EXISTS `tbl_column_underline_false` (
+  `id` int(11) NOT NULL,
+  `firstName` varchar(50) COLLATE utf8_bin DEFAULT NULL,
+  `lastName` varchar(50) COLLATE utf8_bin DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+INSERT INTO `tbl_column_underline_false` (`id`, `firstName`, `lastName`) VALUES
+	(1, 'yu', 'xiaobin');