星空网 > 软件开发 > 数据库

mongodb morphia关联查询一例

 1 //...此处省略了import... 2 /** 3  * Created by shenzhigang on 4/15/16. 4 */ 5 public class Main { 6   public static void main(String[] args) { 7     Datastore datastore; 8     final Morphia morphia = new Morphia(); 9     morphia.mapPackage("com.bdb.datatypes.common.po");10     datastore = morphia.createDatastore(new MongoClient("localhost", 27017), "test001");11     datastore.ensureIndexes();12 13     Student student = new Student();14     student.setName("沈志刚");15     student.setAge(30);16 17     School school = new School();18     school.setName("苏州小学");19     school.setAddress("苏州市");20     datastore.save(school);21 22     student.setSchool(school);23     datastore.save(student);24 25     List<Key<School>> schools =datastore.createQuery(School.class).field("name").equal("苏州小学").asKeyList();26     List<Student> studentList = datastore.find(Student.class).field("school").in(schools).asList();27   }28 }29 30 @Entity31 class Student {32   @Id33   private ObjectId objectId ;34   private String name;35   private int age;36   @Reference37   private School school;38   //...此处省略了get set.... 39 }40 41 @Entity42 class School {43   @Id44   private ObjectId objectId;45   private String address;46   private String name;47   //....此处省略了get set...48 }49   

 




原标题:mongodb morphia关联查询一例

关键词:MongoDB

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

获取方法:https://www.goluckyvip.com/tag/5119.html
欧洲变天了:https://www.goluckyvip.com/tag/512.html
好评review:https://www.goluckyvip.com/tag/5120.html
FBA产品标签:https://www.goluckyvip.com/tag/5121.html
FBA最新政策:https://www.goluckyvip.com/tag/5122.html
2022FBA政策:https://www.goluckyvip.com/tag/5123.html
你更喜欢一个人旅行,还是一群人旅行? :https://www.vstour.cn/a/408249.html
延安市区景点都收费吗 延安景点要门票吗:https://www.vstour.cn/a/408250.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流