轻量级 ORM 框架 Generic DAO
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); } } ... }
本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!