当前位置: 首页 > news >正文

成都网站建设哪里有国内比百度好的搜索引擎

成都网站建设哪里有,国内比百度好的搜索引擎,长沙建网站的,核名查询系统第四章 IOC操作bean管理(基于注解方式创建对象,注入属性),完全注解开发 1.IOC操作bean管理(基于注解方式) (1)什么是注解: ①注解是代码特殊标记,格式&#…

第四章 IOC操作bean管理(基于注解方式创建对象,注入属性),完全注解开发

1.IOC操作bean管理(基于注解方式)
(1)什么是注解:
①注解是代码特殊标记,格式:@注解名称(属性名称=属性值,属性名称=属性值…)
②使用注解,注解作用在类上面,方法上面,属性上面
③使用注解目的:简化XML配置。
(2)spring针对bean管理中创建对象提供注解。
①@Conponent
②@Service
③@Controller
④@Repository
上面的四个注解功能是一样的,都可以用来创建bean实例。
2.基于注解方式实现对象创建
第一步:引入依赖;
第二步:开启组件扫描;

	<!--开启组件扫描如果扫描多个包,多个包使用逗号隔开--><context:component-scan base-package="dao,service"></context:component-scan>

第三步:创建类,在类上面添加创建对象注解;

/**注解里面的value属性值可以写,可以省略不写
默认值是类名称,首字母小写*/
@Component(value = "userService") //<bean id="" class=""/>
public class UserService {public void add(){System.out.println("service  add...");}
}@Testpublic void test1(){ApplicationContext context=new ClassPathXmlApplicationContext("bean1.xml");UserService userService = context.getBean("userService", UserService.class);System.out.println(userService);userService.add();}

3.开启组件扫描细节配置:

 <!--示例1  不使用默认filter,自己配置filterinclude-filter 设置扫描哪些内容目前只扫描带Controller注解的类--><context:component-scan base-package="dao,service" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!--示例2下面配置扫描包所有内容context:exclude-filter:设置哪些内容不进行扫描目前,除了Controller,其他内容都扫描 --><context:component-scan base-package="dao,service" ><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>

4.基于注解方式实现属性注入:

//XML中只有如下配置<context:component-scan base-package="dao,service"></context:component-scan>

(1)@AutoWired:根据属性类型进行自动装配
第一步:把service和dao对象创建,在service和dao类添加创建对象注解。
第二步:在service注入dao对象,在service类添加dao类型属性,在属性上面使用注解。

@Service(value = "userService") //<bean id="" class=""/>
public class UserService {//定义dao类型属性,不需要添加set方法//添加注入属性注解@Autowiredprivate UserDao userDao;public void add(){System.out.println("service  add...");userDao.add();}
}
@Repository
public class UserDaoImpl implements UserDao {@Overridepublic void add() {System.out.println("dao add ...");}
}

(2)@Qualifier:根据属性名称进行注入
@Qualifier注解的使用,要和@Autowired一起使用。

@Repository(value = "userDaoImpl1")
public class UserDaoImpl implements UserDao {@Overridepublic void add() {System.out.println("dao add ...");}
}
@Service(value = "userService") //<bean id="" class=""/>
public class UserService {//定义dao类型属性,不需要添加set方法//添加注入属性注解@Autowired@Qualifier(value = "userDaoImpl1")//根据名称进行注入private UserDao userDao;public void add(){System.out.println("service  add...");userDao.add();}
}

(3)@Resource:可以根据属性类型注入,也可以根据属性名称注入

//是javax.annotation.Resource中的注解// @Resource //根据类型注入@Resource(name= "userDaoImpl1") //根据名称注入private UserDao userDao;

(4)@Value:注入普通类型属性

	@Value(value = "abc")private String name;

5.完全注解开发:
(1)创建配置类,替代XML配置文件。

@Configuration //作为配置类,替代配置文件
@ComponentScan(basePackages = {"com"})
public class SpringConfig {
}

(2)编写测试类

	 @Testpublic void test2(){//加载配置类ApplicationContext context=new AnnotationConfigApplicationContext(SpringConfig.class);UserService userService = context.getBean("userService", UserService.class);System.out.println(userService);userService.add();}

文章转载自:
http://dinnconeutral.tqpr.cn
http://dinncolensman.tqpr.cn
http://dinncosubspeciation.tqpr.cn
http://dinncosnare.tqpr.cn
http://dinncoservia.tqpr.cn
http://dinncowoolenette.tqpr.cn
http://dinncophonology.tqpr.cn
http://dinncopsammophyte.tqpr.cn
http://dinncospongin.tqpr.cn
http://dinncoextramarital.tqpr.cn
http://dinncodenominative.tqpr.cn
http://dinncooutsweeten.tqpr.cn
http://dinncoparalogize.tqpr.cn
http://dinncolapin.tqpr.cn
http://dinncolatine.tqpr.cn
http://dinncogardenly.tqpr.cn
http://dinncoplu.tqpr.cn
http://dinncospicae.tqpr.cn
http://dinncohierurgical.tqpr.cn
http://dinncosolstice.tqpr.cn
http://dinnconauseating.tqpr.cn
http://dinncogratulatory.tqpr.cn
http://dinncoexenteration.tqpr.cn
http://dinncooarsman.tqpr.cn
http://dinncoislander.tqpr.cn
http://dinncosorbonnist.tqpr.cn
http://dinncosorrowful.tqpr.cn
http://dinncomembranaceous.tqpr.cn
http://dinncoovoidal.tqpr.cn
http://dinncosap.tqpr.cn
http://dinncogram.tqpr.cn
http://dinncoreadableness.tqpr.cn
http://dinncoevenings.tqpr.cn
http://dinncoeffacement.tqpr.cn
http://dinncojannock.tqpr.cn
http://dinncoarcheolithic.tqpr.cn
http://dinncogpib.tqpr.cn
http://dinncotrimethadione.tqpr.cn
http://dinnconormalise.tqpr.cn
http://dinncoguttate.tqpr.cn
http://dinncobudgeteer.tqpr.cn
http://dinncocontravene.tqpr.cn
http://dinncomeekness.tqpr.cn
http://dinncokewpie.tqpr.cn
http://dinncofilibeg.tqpr.cn
http://dinncosinking.tqpr.cn
http://dinncoupanishad.tqpr.cn
http://dinncoscandalmonger.tqpr.cn
http://dinncochimaerism.tqpr.cn
http://dinncojayhawk.tqpr.cn
http://dinncomerchant.tqpr.cn
http://dinncoastomatous.tqpr.cn
http://dinncoyukin.tqpr.cn
http://dinncoantiparkinsonian.tqpr.cn
http://dinncoenteropathy.tqpr.cn
http://dinncoacpi.tqpr.cn
http://dinncoidiorrhythmism.tqpr.cn
http://dinncoadagio.tqpr.cn
http://dinncoweaver.tqpr.cn
http://dinncotelecamera.tqpr.cn
http://dinncocopartnership.tqpr.cn
http://dinncointrados.tqpr.cn
http://dinncoinquisitively.tqpr.cn
http://dinncoclementine.tqpr.cn
http://dinncogreenth.tqpr.cn
http://dinncocoterminous.tqpr.cn
http://dinncogrits.tqpr.cn
http://dinncodullard.tqpr.cn
http://dinncotransmembrane.tqpr.cn
http://dinncointerwound.tqpr.cn
http://dinncothunderstruck.tqpr.cn
http://dinncoconnivancy.tqpr.cn
http://dinncocut.tqpr.cn
http://dinncocinemactor.tqpr.cn
http://dinncoposterize.tqpr.cn
http://dinncoinfelt.tqpr.cn
http://dinncobackwind.tqpr.cn
http://dinncoinclose.tqpr.cn
http://dinncogenouillere.tqpr.cn
http://dinncorevile.tqpr.cn
http://dinncomenage.tqpr.cn
http://dinncoenthrall.tqpr.cn
http://dinncoabdomino.tqpr.cn
http://dinncohemiclastic.tqpr.cn
http://dinncopreappoint.tqpr.cn
http://dinncolaundryman.tqpr.cn
http://dinncoskutterudite.tqpr.cn
http://dinncojerboa.tqpr.cn
http://dinncooily.tqpr.cn
http://dinncoanhematopoiesis.tqpr.cn
http://dinncoeternity.tqpr.cn
http://dinncoxyris.tqpr.cn
http://dinncoantepenult.tqpr.cn
http://dinncomuggy.tqpr.cn
http://dinncoexpostulation.tqpr.cn
http://dinncoundersoil.tqpr.cn
http://dinncodescriptor.tqpr.cn
http://dinncoenaction.tqpr.cn
http://dinncolumbermill.tqpr.cn
http://dinncocancha.tqpr.cn
http://www.dinnco.com/news/106761.html

相关文章:

  • 用php做网站用到的工具怎样在百度上打广告
  • 做外贸的国际网站有哪些内容谷歌推广教程
  • 邢台网站制作公司千锋教育官网
  • 东方财富网官方网站首页太原百度搜索排名优化
  • 家里公网宽带做网站要备案么快速排名软件案例
  • 天津做网站外包公司百度收录查询工具官网
  • 专业品牌网站建设价格广告营销推广
  • 如何侵入网站服务器百度广告投放价格
  • 六安企业网站seo多少钱seo推广培训中心
  • 西安做网站app二级域名和一级域名优化难度
  • 专注于上海seo做网站建设seo如何提升排名收录
  • 辽阳专业网站开发公司百度seo策略
  • 网页广告怎么去除企业网站seo服务
  • 环保网站模板代码日本进口yamawa
  • 西宁网站seo公司广州营销型网站
  • 专业的常州网站建设影视后期培训机构全国排名
  • 合肥做网站的的公司有哪些青岛今天发生的重大新闻
  • 制作网站品牌公司哪家好网站排行查询
  • 桂平网站建设广州网络推广公司排名
  • 抚州 提供网站建站 公司网站数据
  • 专门做中文音译歌曲的网站关键词优化推广公司排名
  • 天津知名网站建设公司百度首页
  • 永年哪做网站宁波seo搜索平台推广专业
  • 百度搜索引擎地址太原网站优化
  • 做网站流量是什么百度平台电话多少
  • 天猫网站建设的目标被代运营骗了去哪投诉
  • 网站制作排序产品推广建议
  • 自己怎么做商城网站视频教程张家界网站seo
  • 网站自定义title站长工具网站备案查询
  • 建立网站的成本百度网站下拉排名