etComments() {
return comments;
}
public void setComments(Set<Comment> comments) {
this.comments = comments;
}
}
使用SpringSide 3.1.4.3开发Web项目的全过程(上)(8)
时间:2010-12-20 BlogJava 海边沫沫
Comment.java如下:
package personal.youxia.entity.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import personal.youxia.entity.IdEntity;
@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "comments")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Comment extends IdEntity {
private String content;
private Long articleId;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Column(name = "article_id")
public Long getArticleId() {
return articleId;
}
public void setArticleId(Long articleId) {
this.articleId = articleId;
}
}
编写Dao层代码,ArticleDao.java如下:
package personal.youxia.dao;
import org.springside.modules.orm.hibernate.HibernateDao;
import personal.youxia.entity.Article;
public class ArticleDao extends HibernateDao<Article, Long> {
}
CommentDao.java如下:
package personal.youxia.dao;
import org.springside.modules.orm.hibernate.HibernateDao;
import personal.youxia.entity.Comment;
public class CommentDao extends HibernateDao<Comment, Long> {
}
可以看出,以上代码都从HibernateDao继承,得益于泛型支持,基本不需要 编写一行代码。
编写Bussiness层代码,这一层,白衣使用的包名为service,而类名的后缀 都是Manager,我就跟他学算了,懒得改了。
ArticleManager.java如下:
package personal.youxia.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.hibernate.HibernateDao;
import personal.youxia.dao.ArticleDao;
import personal.youxia.entity.Article;
public class ArticleManager extends EntityManager<Article, Long> {
@Autowired
private ArticleDao articleDao;
public void setArticleDao(ArticleDao articleDao) {
this.articleDao = articleDao;
}
@Override
protected HibernateDao<Article, Long> getEntityDao() {
// TODO Auto-generated method stub
return articleDao;
}
}
使用SpringSide 3.1.4.3开发Web项目的全过程(上)(9)
时间:2010-12-20 BlogJava 海边沫沫
CommentManager.java如下:
package personal.youxia.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.hibernate.HibernateDao;
import personal.
|