jobob 8 vuotta sitten
vanhempi
commit
b4a1c753d5

+ 3 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/annotations/TableField.java

@@ -48,8 +48,10 @@ public @interface TableField {
 	 */
 	boolean exist() default true;
 
-	/**
+	/*
+	 * <p>
 	 * 当该Field为类对象时, 可使用#{对象.属性}来映射到数据表.
+	 * </p>
 	 */
 	String el() default "";
 }

+ 8 - 16
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/TableFieldInfo.java

@@ -50,54 +50,46 @@ public class TableFieldInfo {
 
 	public TableFieldInfo(boolean related, String column, String property, String el) {
 		this.related = related;
-		this.column = column;
+		this.setColumn(column);
 		this.property = property;
 		this.el = el;
 	}
 
-
-	public TableFieldInfo( boolean related, String column, String property ) {
+	public TableFieldInfo(boolean related, String column, String property) {
 		this.related = related;
-		this.column = DBKeywordsProcessor.convert(column);
+		this.setColumn(column);
 		this.property = property;
 		this.el = property;
 	}
 
-
-	public TableFieldInfo( String column ) {
+	public TableFieldInfo(String column) {
 		this.related = false;
-		this.column = DBKeywordsProcessor.convert(column);
+		this.setColumn(column);
 		this.property = column;
 		this.el = column;
 	}
 
-
 	public boolean isRelated() {
 		return related;
 	}
 
-
-	public void setRelated( boolean related ) {
+	public void setRelated(boolean related) {
 		this.related = related;
 	}
 
-
 	public String getColumn() {
 		return column;
 	}
 
-
-	public void setColumn( String column ) {
+	public void setColumn(String column) {
 		this.column = DBKeywordsProcessor.convert(column);
 	}
 
-
 	public String getProperty() {
 		return property;
 	}
 
-
-	public void setProperty( String property ) {
+	public void setProperty(String property) {
 		this.property = property;
 	}
 

+ 12 - 6
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/TableInfoHelper.java

@@ -121,24 +121,30 @@ public class TableInfoHelper {
 				if (StringUtils.isNotEmpty(tableField.value())) {
 					columnName = tableField.value();
 				}
-				// iTODO 是否能再加点其他判断, 保证传入参数格式正确
+
+				/*
+				 * el 语法支持,可以传入多个参数以逗号分开
+				 */
 				String el = field.getName();
 				if (StringUtils.isNotEmpty(tableField.el())) {
 					el = tableField.el();
 				}
-
-				// iTODO 可以传入多个参数以逗号分开
 				String[] columns = columnName.split(",");
 				String[] els = el.split(",");
-				for (int i = 0; i < columns.length; i++) {
-					fieldList.add(new TableFieldInfo(true, columns[i], field.getName(), els[i]));
+				if (null != columns && null != els && columns.length == els.length) {
+					for (int i = 0; i < columns.length; i++) {
+						fieldList.add(new TableFieldInfo(true, columns[i], field.getName(), els[i]));
+					}
+				} else {
+					String errorMsg = "Class: %s, Field: %s, 'value' 'el' Length must be consistent.";
+					throw new MybatisPlusException(String.format(errorMsg, clazz.getName(), field.getName()));
 				}
 
 				continue;
 			}
 
 			/**
-			 * 字段, 使用camelToUnderline转换驼峰写法为下划线分割法, 如果已制定TableField, 便不会执行这里
+			 * 字段, 使用 camelToUnderline 转换驼峰写法为下划线分割法, 如果已指定 TableField , 便不会执行这里
 			 */
 			if (MybatisConfiguration.DB_COLUMN_UNDERLINE) {
 				/* 开启字段下划线申明 */

+ 5 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/UserMapperTest.java

@@ -42,7 +42,7 @@ import com.baomidou.mybatisplus.toolkit.IdWorker;
  * https://github.com/mybatis/spring/issues/39<br>
  * </p>
  *
- * @author hubin
+ * @author hubin sjy
  * @Date 2016-01-23
  */
 public class UserMapperTest {
@@ -103,10 +103,14 @@ public class UserMapperTest {
         User userA = new User();
         userA.setId(IdWorker.getId());
         userA.setName("junyu_shi");
+        userA.setAge(1);
+        userA.setTestType(1);
         userA.setRole(role);
 
         int rlt = userMapper.insert(userA);
         User whereUser = userMapper.selectOne(userA);
+        print(whereUser);
+        
         userA.setAge(18);
         userMapper.updateById(userA);
         userMapper.deleteSelective(userA);
@@ -192,7 +196,6 @@ public class UserMapperTest {
          * updateById 是从 AutoMapper 中继承而来的,UserMapper.xml中并没有申明改sql
          *
          */
-
         rlt = userMapper.updateSelectiveById(new User(12L, "MybatisPlus"));
         System.err.println("------------------updateSelectiveById---------------------- result=" + rlt + "\n\n");
         sleep();

+ 3 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/Role.java

@@ -7,10 +7,11 @@ import com.baomidou.mybatisplus.annotations.TableName;
 import java.io.Serializable;
 
 /**
- *
+ * <p>
  * 测试角色类
+ * </p>
  *
- * @author springwind
+ * @author sjy
  * @Date 2016-09-09
  */
 @TableName(value = "role")