当前位置: 首页 > 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.huolong8.cn/news/134016/

相关文章:

  • 域名注册网站有哪些有专门做ppt的网站有哪些
  • 乾县做网站正规的建网站公司
  • 网站建设原创软文温州logo设计公司
  • wordpress的方法seozou是什么意思
  • ios风格网站模板制作公司网站要多少费用呢
  • 网站导航菜单代码医药类网站建设评价
  • 做淘宝这种网站wordpress参考手册
  • 做网站视频存储金螳螂装饰公司国内排名
  • c2c网站架构济宁市任城区建设局网站
  • 做网站建设最好学什么做网站 大文件
  • 自己做头像的网站上海工商网企业查询
  • 汽车4s网站设计网站怎么做网络推广
  • 郑州网站建站模板成立一个做网站的工作室
  • 石家庄网站开发与优化哪个网站建站好500平台
  • 景翔物流网站建设公司wordpress不兼容ie8
  • 怎样做海外淘宝网站网站备案照片要求
  • 企业网站建设方案书模板烟台h5网站制作
  • 济南网站建设 推搜点建设宠物店网站
  • 事业单位考试网站后台网站下载
  • 深圳市工程建设造价网站制作微信小程序要钱吗
  • 个人做信息分类网站需备案吗网页设计模板图片什么软件好用
  • 宜宾网站建设多少钱德州seo
  • 如何有效提高网站排名网站做游戏吗
  • 泉做网站的公司wordpress地址应该填什么意思
  • 网站域名等级吴江seo排名
  • myeclipse怎样做网站wordpress搜索表单
  • 电子产品网站建设策划书响应式机械类网站
  • 网站建设的可行性要求ppt模板免费下载 素材千图网
  • 微信公众号微网站建设一个空间做多个网站
  • dw建设网站网页设计实训报告书