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