Generic DAO轻量级 ORM 框架

联合创作 · 2023-09-30 03:07

Generic DAO 是一个 Java 的轻量级 ORM 框架,允许开发者为持久化对象编写 DAO 类。

示例代码:

 

public class BlogLogicImpl implements BlogLogic {

   
private BlogWowDaoImpl dao;
   
public void setDao(BlogWowDaoImpl dao) {
     
this.dao = dao;
   
}

   
public BlogWowBlog getBlogByLocationAndUser(String locationId, String userId) {
     
List<BlogWowBlog> l = dao.findBySearch(BlogWowBlog.class, new Search("location", locationId) );

     
if (l.size() <= 0) {
         
// no blog found, create a new one
         
if (canWriteBlog(null, locationId, userId)) {
           
BlogWowBlog blog = new BlogWowBlog(userId, locationId, "Initial title", new Date());
            dao
.save(blog);
           
return blog;
         
}
         
return null;
     
} else if (l.size() >= 1) {
         
// found existing blog
         
return (BlogWowBlog) l.get(0);
     
}
   
}
...
}
浏览 5
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报