diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java index a9fe51e33..c09051423 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/FieldHelper.java @@ -181,6 +181,7 @@ private List _getFields(Class entityClass, List fie return fieldList; } Field[] fields = entityClass.getDeclaredFields(); + Arrays.sort(fields, Comparator.comparing(Field::getName)); int index = 0; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java index 1ecd948f0..edfba3400 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/ComplexEntityTest.java @@ -152,19 +152,19 @@ public void test() { sqlBuilder.append(SqlHelper.fromTable(entityClass, entityTable.getName())); sqlBuilder.append(SqlHelper.whereAllIfColumns(entityClass, config.isNotEmpty())); final String sql = sqlBuilder.toString(); - Assert.assertEquals("SELECT id,user_name,address,state FROM user " + + Assert.assertEquals("SELECT address,id,state,user_name FROM user " + "" + - " AND id = #{id}" + - " AND user_name = #{userName}" + " AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest$AddressHandler}" + - " AND state = #{state}", sql); + " AND id = #{id}" + + " AND state = #{state}" + + " AND user_name = #{userName}", sql); final ResultMap resultMap = entityTable.getResultMap(configuration); final List resultMappings = resultMap.getResultMappings(); - final ResultMapping idMapping = resultMappings.get(0); - final ResultMapping userNameMapping = resultMappings.get(1); - final ResultMapping addressMapping = resultMappings.get(2); - final ResultMapping stateMapping = resultMappings.get(3); + final ResultMapping addressMapping = resultMappings.get(0); + final ResultMapping idMapping = resultMappings.get(1); + final ResultMapping stateMapping = resultMappings.get(2); + final ResultMapping userNameMapping = resultMappings.get(3); Assert.assertEquals("id", idMapping.getColumn()); Assert.assertEquals("id", idMapping.getProperty()); diff --git a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java index 78308e53a..1589e20de 100644 --- a/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java +++ b/core/src/test/java/tk/mybatis/mapper/mapperhelper/SqlHelperTest.java @@ -35,7 +35,7 @@ public void testLogicDeleteSql() { Assert.assertEquals(" AND is_valid = 1", notLogicDeletedColumn); String updateSetColumns = SqlHelper.updateSetColumns(User.class, null, false, false); - Assert.assertEquals("username = #{username},is_valid = 1,", updateSetColumns); + Assert.assertEquals("is_valid = 1,username = #{username},", updateSetColumns); } }