首页 > 代码库 > 暑假项目总结(三)

暑假项目总结(三)

注解中一些问题

 

一、实体类注解,加入@Entity等,注意@Column中name和数据库中一致,如下图:

package cn.edu.cqu.cqzy.entity;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Table(name="music_user",catalog="music")public class User implements java.io.Serializable{        private static final long serialVersionUID = 12222222222L;        @Id    @GeneratedValue(strategy=GenerationType.AUTO)    @Column(name="userId")    private int userId;    @Column(name="username")    private String username;    @Column(name="pwd")    private String pwd;    @Column(name="email")    private String email;    @Column(name="score")    private int score = 0;      @Column(name="authority")    private int authority = 1;          各种get(),set().....    }

2.服务层 + @Service, 数据访问层 + @Repository、@Transactional, 逻辑控制层 + @Controller (数据层和控制层中的接口,无需要注解), 各层中使用的其它资源用@Resource.

*3.数据实现类若继承HibernateDaoSupport, 需要实现setSessionFactory0(),并加上注解@Autowired

public class AdminDaoImpl extends HibernateDaoSupport implements AdminDao{     @Autowired    public void setSessionFactory0(SessionFactory sessionFactory) {        super.setSessionFactory(sessionFactory);    }    

 

暑假项目总结(三)