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

河南做网站优化大数据营销的概念

河南做网站优化,大数据营销的概念,中国室内设计网官网总裁,制作企业网站新闻列表页面网页设计首先我们要了解注解和xml配置的区别#xff1a; 作用一样#xff0c;但是注解写在Bean的上方来代替我们之前在xml文件中所做的bean配置#xff0c;也就是说我们使用了注解的方式#xff0c;就不用再xml里面进行配置了#xff0c;相对来说注解方式更为简便。 IOC获取对象注…首先我们要了解注解和xml配置的区别   作用一样但是注解写在Bean的上方来代替我们之前在xml文件中所做的bean配置也就是说我们使用了注解的方式就不用再xml里面进行配置了相对来说注解方式更为简便。   IOC获取对象注解方式 在我们第二篇IOC容器配置 xml方式总结的基础上做修改 首先我们的applicationContext.xml配置文件要略作修改把beans里面加上绿色背景的配置 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:contexthttp://www.springframework.org/schema/contextxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd !--开启扫描 扫描包com.zy下面的--context:component-scan base-packagecom.zy/context:component-scan /beans 然后我们的JavaBean类加上注解Component Component(bean1) public class Bean1 {public Bean1() {System.out.println(Bean1的无参构造方法);} } 这样就代替了我们之前在applicationContext.xml中配置的 bean idbean1 classcom.zy.IoC.Bean1/bean 测试及运行结果请参照总结第二篇得出的结果是一样的。   Spring 容器还提供Component 等效三个衍生注解 Repository 用于注册DAO持久层 Service 用于注册 Service业务层 Controller 用于注册 Action 表现层 以Repository为例 /*** 测试UserDao接口*/ public interface UserDao {public void getUser(); } /*** UserDao实现类1*/ Repository(userDao) public class UserDaoImpl implements UserDao {public UserDaoImpl() {System.out.println(dao1 构造方法);}Overridepublic void getUser() {System.out.println(UserDao实现类1 获取用户信息...);} } 测试 Testpublic void getUser() throws Exception {//根据spring配置文件 获取spring容器ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml);//使用容器创建UserDao的实现类对象 userDao和配置文件中的 bean的id一致UserDao dao ac.getBean(userDao, UserDao.class);dao.getUser();} 运行结果    DI依赖注入注解方式 注解基本类型属性这个不多做介绍了 // 基本类型属性 Value(#{张学友}) private String name; 注解复杂类型属性   1Spring3.0提供Value注解 // 复杂类型属性// 第一种 Value 结合 spELValue(#{userDao})private UserDao userDao;   2Spring2.0 提供Autowired 注解 结合 Qualifier 注解 // 第二种 Autowired 注解 结合 Qualifier 注解// 如果单独使用Autowired 默认按照类型注入如果有多个同一类型的只能找到一个// 使用 Qualifier 按照名称注入AutowiredQualifier(userDao)private UserDao userDao;   3JSR-250规范 提供 Resource 注解实现注入不推荐使用 // 第三种 JSR-250提供Resource 注解// 不写name属性按照类型注入写了name属性按照名称注入Resource(name userDao)private UserDao userDao;   以把UserDao注入到UserService为例 JavaBean代码 /*** 测试UserDao接口*/ public interface UserDao {public void getUser(); } /*** UserDao实现类1*/ Repository(userDao) public class UserDaoImpl implements UserDao {Overridepublic void getUser() {System.out.println(2 UserDao实现类1 获取用户信息...);} }/*** UserService接口*/ public interface UserService {public void getUser(); } /*** UserService实现类*/ Service(userService) public class UserServiceImpl implements UserService {//AutowiredQualifier的方式//Autowired//Qualifier(userDao)value(#{userDao}) //Value(#{})的方式 使用注解注入,要与dao实现类的注解一致(使用注解 不需要setter方法, 如果没有构造方法,使用xml配置的时候需要setter方法)private UserDao userDao;Overridepublic void getUser() {System.out.println(1 业务层1 获取user对象...);userDao.getUser();} } 测试 Testpublic void getUser() throws Exception {ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml);UserService userService ac.getBean(userService, UserService.class);userService.getUser();} 运行结果   其他注解的使用 生命周期注解 PostConstruct 初始化方法 PreDestroy 销毁方法 //Bean的注解 Component(springLifeCycle) public class SpringLifeCycle {//构造方法public SpringLifeCycle() {System.out.println(SpringLifeCycle 构造...);}//初始化方法的注解PostConstructpublic void init() {System.out.println(SpringLifeCycle 初始化...);}//销毁方法的注解PreDestroypublic void destroy() {System.out.println(SpringLifeCycle 销毁...);}public void helloSpring() {System.out.println(hello spring !);} } 测试 Testpublic void testLifeCycle() {ApplicationContext ac new ClassPathXmlApplicationContext(applicationContext.xml);SpringLifeCycle springLifeCycle (SpringLifeCycle) ac.getBean(springLifeCycle);springLifeCycle.helloSpring();// 调用close(ApplicationContext没有close方法,需要转子类调用close)ClassPathXmlApplicationContext classAc (ClassPathXmlApplicationContext) ac;classAc.close();} 运行结果   Bean的作用域注解 还是上面的JavaBean类 //Bean的注解 Component(springLifeCycle) //作用域注解 prototype为多实例默认为singleton单实例 Scope(prototype) public class SpringLifeCycle { 测试 Testpublic void testScope() throws Exception {ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext.xml);SpringLifeCycle lifeCycleBean1 (SpringLifeCycle) applicationContext.getBean(springLifeCycle);SpringLifeCycle lifeCycleBean2 (SpringLifeCycle) applicationContext.getBean(springLifeCycle);System.out.println(lifeCycleBean1);System.out.println(lifeCycleBean2);// 通过反射 代码调用 close方法Method closeMethod applicationContext.getClass().getMethod(close);closeMethod.invoke(applicationContext);} 运行结果 大家会发现销毁方法没有起作用这里说明一下Bean必须为singleton单实例的时候销毁方法才能执行。 将scope设置成singleton //Bean的注解 Component(springLifeCycle) //作用域注解singleton为默认值可以不写这个注解 Scope(singleton) public class SpringLifeCycle { 执行结果  转载于:https://www.cnblogs.com/blazeZzz/p/9305861.html
http://www.sadfv.cn/news/134016/

相关文章:

  • 化妆品网站栏目策划微信公众号用什么开发
  • 免费的网站源码去哪下载wordpress更改后台域名后无法访问
  • 开发网站的基本流程五个阶段济源网站建设费用
  • 企业诚信建设网站好玩的网站源码
  • 网站排名下降怎么上去网站开发违约解除合同通知函
  • 广东住房和城乡建设局网站首页找人做网站毕业设计
  • seo网站推广实例wordpress媒体库 不显示图片
  • 手机搭建本地网站多少钱算网站
  • 做网站ps注意事项网站制作高手
  • 建设银行 网站首页移动互联网站建设
  • 新泰网站定制怎么让百度收录自己的网站
  • 网站建设设如何在百度提交网站
  • 华强北做电子网站建设森动网网站建设好吗
  • 企业公司网站源码ui做网站流程
  • 网站托管是什么意思沈阳网站外包
  • 宁波市住房和城乡建设培训中心网站dede鲜花网站模板下载
  • 网站建设发生的成本如何记账最有效的网站推广公司
  • 怎么用微信官方网站做二维码贵州网站制作
  • 网站建设经费申请报告办一家建筑公司怎么样
  • 新建茶叶网站文章内容建设dhl做运单的网站
  • win7系统做网站服务器系统在线设计平台canva可画
  • 2018做技术分享网站有前景吗做网站要ftp信息吗
  • 好学校平台网站模板重庆网络营销渠道
  • 贵阳市住房和城乡建设厅网站合肥市建设工程造价信息网站
  • 医院加强网站建设网络运维与网络安全工程师
  • 基金从业培训网站企业手机网站设计案例
  • 一流专业建设网站工业互联网平台架构图
  • 苍溪规划和建设局网站论坛网站方案
  • 无法登陆建设银行网站深圳制作网站建设推广
  • wordpress搭建漫画站网站要跟换域名怎么做