首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring Annotation注脚:易错点

2012-11-26 
Spring Annotation注解:易错点用注解以来,发现经常漏配置,所以在这把所有需要写注解的地方都列出来。Action

Spring Annotation注解:易错点
   用注解以来,发现经常漏配置,所以在这把所有需要写注解的地方都列出来。
   Action层:
       @Component
       @Scope("prototype")
        public class SendMsgAction extends BaseAction{
private int[] ids;
private SendMsg sendMsg;
@Resource
private SendMsgService sendMsgService;
  Dao层:接口并不需要配注解。但是实现层须有如下配置:
      1、 public class BaseDaoImpl<T>  implements BaseDao<T> {
protected Class clazz;
@Resource
private HibernateTemplate  hibernateTemplate;

     2、  @Component
       public class SendMsgDaoImpl extends BaseDaoImpl<SendMsg> implements       SendMsgDao {

  Po层:实体类。在这有mappedBy下面细说。
        @Entity
        @Table(name="t_user")
        public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String name;
private String pwd;
private String phone;
@OneToMany(mappedBy="user")
private Set<SendMsg> sendMsgs=new HashSet<SendMsg>();//本人发送多份邮件
@OneToMany(mappedBy="receiver")
private Set<ReceiveMsg> receiveMsgs=new HashSet<ReceiveMsg>();
   Service层:接口也不需要配注解,实现类须有一下配置:
        @Component
        public class SendMsgServiceImpl implements SendMsgService {
@Resource
private SendMsgDao smdao;

       关于mappedBy属性:一般mappedBy放哪,哪边就生成外键。
       凡是加了@Resource的元素,都要有get,set方法

热点排行