Skip to content

Commit

Permalink
兼容 OrderBy 和 Order 注解,新增的 Order 注解可以直接排序优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed Nov 24, 2018
1 parent 4abde55 commit 06332fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/tk/mybatis/mapper/entity/EntityColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class EntityColumn {
private String generator;
//排序
private String orderBy;
private Integer orderPriority;
private int orderPriority;
//可插入
private boolean insertable = true;
//可更新
Expand Down Expand Up @@ -344,11 +344,11 @@ public void setUseJavaType(boolean useJavaType) {
this.useJavaType = useJavaType;
}

public Integer getOrderPriority() {
public int getOrderPriority() {
return orderPriority;
}

public void setOrderPriority(Integer orderPriority) {
public void setOrderPriority(int orderPriority) {
this.orderPriority = orderPriority;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,26 @@ protected void processField(EntityTable entityTable, EntityField field, Config c
* @param entityColumn
*/
protected void processOrderBy(EntityTable entityTable, EntityField field, EntityColumn entityColumn) {
String orderBy = "";
if(field.isAnnotationPresent(OrderBy.class)){
throw new MapperException(OrderBy.class + " is outdated, use " + Order.class + " instead!");
orderBy = field.getAnnotation(OrderBy.class).value();
if ("".equals(orderBy)) {
orderBy = "ASC";
}
log.warn(OrderBy.class + " is outdated, use " + Order.class + " instead!");
}

if (field.isAnnotationPresent(Order.class)) {
Order order = field.getAnnotation(Order.class);
if ("".equals(order.value())) {
entityColumn.setOrderBy("ASC");
if ("".equals(order.value()) && "".equals(orderBy)) {
orderBy = "ASC";
} else {
entityColumn.setOrderBy(order.value());
orderBy = order.value();
}
entityColumn.setOrderPriority(order.priority());
}
if (StringUtil.isNotEmpty(orderBy)) {
entityColumn.setOrderBy(orderBy);
}
}

/**
Expand Down

0 comments on commit 06332fb

Please sign in to comment.