假设我有一个实体:
@Entity
public class Person {
@Id
private int id;
private String name;
private Date birthdate;
}
我希望有一个方法,它会根据OrderSpecifier
参数为该实体的字段返回String
,该参数将是某个实体字段的名称。
/**
* fieldName - name of field from Person entity
*/
private OrderSpecifier<?> getSortedColumn(Order order, String fieldName){
//how to implement this???
}
答案 0 :(得分:5)
我实际成功地这样做了:
/**
* fieldName - name of field from Person entity
*/
private OrderSpecifier<?> getSortedColumn(Order order, String fieldName){
Path<Object> fieldPath = Expressions.path(Object.class, QPerson.person, fieldName);
return new OrderSpecifier(order, fieldPath);
}