ht
parent
0545e638e4
commit
0d24781dfc
|
|
@ -26,19 +26,29 @@ public class Controller extends com.jfinal.core.Controller{
|
|||
renderText("2");
|
||||
}
|
||||
|
||||
@Before(IdInterceptor.class)
|
||||
public void dict() {
|
||||
String id = getPara("id");
|
||||
Map<String, String[]> paraMap = getParaMap();
|
||||
List<Bson> ops = new ArrayList<>();
|
||||
|
||||
paraMap.forEach((key, arr) -> {
|
||||
if ("id".equals(key)) {
|
||||
ops.add(Filters.eq("_id", new ObjectId(arr[0])));
|
||||
} else {
|
||||
ops.add(Filters.eq(key, arr[0]));
|
||||
}
|
||||
});
|
||||
|
||||
MongoCollection<Document> collection = getCollection();
|
||||
Document dict = collection.find(
|
||||
Filters.eq("_id", new ObjectId(id))
|
||||
).limit(1).first();
|
||||
if (dict != null) {
|
||||
renderJson(dict.toJson());
|
||||
} else {
|
||||
renderError(404);
|
||||
}
|
||||
List<Document> documents = new ArrayList<>();
|
||||
collection.find(
|
||||
Filters.and(ops)
|
||||
).into(documents);
|
||||
|
||||
List<String> json = new ArrayList<>();
|
||||
documents.forEach(doc -> {
|
||||
json.add(doc.toJson());
|
||||
});
|
||||
renderText(Arrays.toString(json.toArray()), ContentType.JSON);
|
||||
}
|
||||
|
||||
public void dictList() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
dict (String id required) {
|
||||
return dict json
|
||||
dict (key-value pairs) {
|
||||
return dict list json
|
||||
}
|
||||
dictList (int pageNum default 0, int pageSize default 20) {
|
||||
return dict list json
|
||||
|
|
|
|||
Loading…
Reference in New Issue