Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加别名 #245

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ResultMap getResultMap(Configuration configuration) {
if(matcher.find()){
column = matcher.group(1);
}
ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(), column, entityColumn.getJavaType());
ResultMapping.Builder builder = new ResultMapping.Builder(configuration, entityColumn.getProperty(), entityColumn.getProperty(), entityColumn.getJavaType());
if (entityColumn.getJdbcType() != null) {
builder.jdbcType(entityColumn.getJdbcType());
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/tk/mybatis/mapper/entity/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Example selectProperties(String... properties) {
}
for (String property : properties) {
if (propertyMap.containsKey(property)) {
this.selectColumns.add(propertyMap.get(property).getColumn());
this.selectColumns.add(propertyMap.get(property).getColumn() + " AS " + propertyMap.get(property).getProperty());
} else {
throw new MapperException("类 " + entityClass.getSimpleName() + " 不包含属性 \'" + property + "\',或该属性被@Transient注释!");
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ public Set<String> getSelectColumns() {
selectColumns = new LinkedHashSet<String>(entityColumns.size() - excludeColumns.size());
for (EntityColumn column : entityColumns) {
if (!excludeColumns.contains(column.getColumn())) {
selectColumns.add(column.getColumn());
selectColumns.add(column.getColumn() + " AS " +column.getProperty());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static String getAllColumns(Class<?> entityClass) {
Set<EntityColumn> columnSet = EntityHelper.getColumns(entityClass);
StringBuilder sql = new StringBuilder();
for (EntityColumn entityColumn : columnSet) {
sql.append(entityColumn.getColumn()).append(",");
sql.append(entityColumn.getColumn()).append(" AS ").append(entityColumn.getProperty()).append(",");
}
return sql.substring(0, sql.length() - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public void testColumn(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("user_name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void testColumn(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("user_name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down Expand Up @@ -220,12 +220,12 @@ public void testAll(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("user_name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getColumn());
Assert.assertEquals("name", resultMapping.getProperty());
Assert.assertNotNull(resultMapping.getJdbcType());
Assert.assertEquals(BlobTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public void testCamelhump(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("user_name", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down Expand Up @@ -101,12 +101,12 @@ public void testCamelhumpAndUppercase(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("USER_NAME", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down Expand Up @@ -141,12 +141,12 @@ public void testCamelhumpAndLowercase(){
}

ResultMap resultMap = entityTable.getResultMap(configuration);
Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());
Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("user_name", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down Expand Up @@ -226,7 +226,7 @@ public void testUppercase(){
Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("USERNAME", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down Expand Up @@ -266,7 +266,7 @@ public void testLowercase(){
Assert.assertEquals(1, resultMap.getResultMappings().size());

ResultMapping resultMapping = resultMap.getResultMappings().get(0);
Assert.assertEquals("username", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getColumn());
Assert.assertEquals("userName", resultMapping.getProperty());
Assert.assertNull(resultMapping.getJdbcType());
Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ 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 id AS id,user_name AS userName,address AS address,state AS state FROM user " +
"<where>" +
"<if test=\"id != null\"> AND id = #{id}</if>" +
"<if test=\"userName != null\"> AND user_name = #{userName}</if>" +
Expand All @@ -170,7 +170,7 @@ public void test() {
Assert.assertEquals("id", idMapping.getProperty());
Assert.assertTrue(idMapping.getFlags().contains(ResultFlag.ID));

Assert.assertEquals("user_name", userNameMapping.getColumn());
Assert.assertEquals("userName", userNameMapping.getColumn());
Assert.assertEquals("userName", userNameMapping.getProperty());

Assert.assertEquals("address", addressMapping.getColumn());
Expand Down