zoukankan      html  css  js  c++  java
  • spring注解和jdk注解简单概述

    spring的注解

    @Autowired@Qualifier

    配合applicationContext.xml

    1     <bean id="myNewsAction" class="news.action.NewsAction" scope="prototype"></bean>
    2     
    3     <bean id="myNewsService" class="news.service.NewsServiceImpl" scope="prototype"></bean>
    4     
    5     <bean id="myNewsDao" class="news.dao.NewsDaoImpl" scope="prototype"></bean> 

    完成

    jdk的注解

    @Controller @Service @Repository

    @Controller这个是注入service的实例

    1 @Controller("myNewsAction")
    2 @Scope("prototype")
    3 public class NewsAction extends ActionSupport {
    4     
    5     private NewsService ns;

    @Service是注入dao实例的

    1 @Service("myNewsService")
    2 @Scope("prototype")
    3 public class NewsServiceImpl implements NewsService {
    4 
    5     private NewsDao nd;

    @Repository这个是注入SessionFactory实例的

    1 @Repository("myNewsDao")
    2 @Scope("prototype")    
    3 public class NewsDaoImpl implements NewsDao {
    4     
    5      private SessionFactory sf;

    两种注解都有各的好处,spring的注解可读性强,jdk的注解节省代码,看情况选择

  • 相关阅读:
    2017年9月22日 关于JS数组
    2017年9月20日
    2017年9月19日 JavaScript语法操作
    2017年9月18日
    2017年9月17日 JavaScript简介
    2017年9月16日
    2017年9月15日
    2017年9月14日
    2017年9月12日
    贪吃蛇全文
  • 原文地址:https://www.cnblogs.com/Sosowu/p/5993019.html
Copyright © 2011-2022 走看看