[英]String Builder Enum checking
I have collection table in database which have fields: 我在数据库中有字段的收集表:
published,name,descrption and collection_type.
And this collection_type
can be three different String values : Collection,Trend,Occasion
. 这个
collection_type
可以是三个不同的String值: Collection,Trend,Occasion
。
Showing whole elements with this working. 显示整个工作原理。
public List<Collection> list() {
QueryParams queryParams = new QueryParams();
queryParams.setWhere("published = true");
return list(queryParams);
}
But showing specific elements for example Occasions failed. 但是显示特定元素(例如,场合)失败。 How to fix the code to show the elements?
如何修复代码以显示元素?
public List<Collection> occasions() {
QueryParams queryParams = new QueryParams();
final StringBuilder sb = new StringBuilder();
sb.append("published = true ");
sb.append("AND collection_type = '");
sb.append("CollectionType.OCCASION.getName()'");
queryParams.setWhere(sb.toString());
return list(queryParams);
}
public enum CollectionType {
COLLECTION("COLLECTION"), TREND("TREND"), OCCASION("OCCASION");
private String name;
private CollectionType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Suppose, the problem is, that you don't set a ENUM's name, but a "CollectionType.OCCASION.getName()'" string. 假设问题是您没有设置ENUM的名称,而是设置了“ CollectionType.OCCASION.getName()'”字符串。 Try to change your code to:
尝试将您的代码更改为:
public List<Collection> occasions() {
QueryParams queryParams = new QueryParams();
final StringBuilder sb = new StringBuilder();
sb.append("published = true ");
sb.append("AND collection_type = '");
sb.append(CollectionType.OCCASION.getName());
sb.append("'");
queryParams.setWhere(sb.toString());
return list(queryParams);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.