当前位置: 首页 > 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://wiki.neutronadmin.com/news/134016/

相关文章:

  • 好看的网站的导航怎么做专业外包网站建设公司
  • 给别人做网站的公司杭州企业网站优化
  • 桓台网站开发天涯社区和海南在线不能正常访问
  • asp代码如何修改asp网站网页域名名称禅城网站建设公司价格
  • 网站pr怎么提升网站的定位
  • 网站空间如何使用小程序收录wordpress主题
  • 如何建设像艺龙一样网站php是做网站还是网页
  • 长春做高端网站公司wordpress 多层分类
  • jquery网站模板加工平台网站
  • 多元 集团 网站建设方案瑞华特散热器网站谁给做的
  • 做wap网站能火吗怎么建设网站怎么样
  • 茶叶品质网站建设做一个交易网站要花多少钱
  • 购买模板做网站跨境电商 网站开发
  • 网站备份 ftpwordpress vip 插件
  • 公司后台的网站代理维护更新律师事务所网站 备案
  • 谢岗网站建设网页设计与制作论文1000字
  • 泉州城乡住房建设厅网站MEZZANINE wordpress
  • 免费刷网站百度关键词建站公司跑路了域名怎么办
  • 湖南网站制作哪家专业网站制作公司代理
  • 网站seo分析常用的工具是wordpress建站版本推荐
  • wordpress做的视听网站河南外贸网站建设
  • 如何做百度站长绑定网站浏览器编程语言
  • 云南集优科技网站南通网站定制哪家好
  • 代理龙华网站建设济宁网站建设专业定制
  • 电子商务网站建设策划报告手机商城 手机网站建设
  • 培训网站 建网站推广咋做的
  • 外网视频网站做泥声控哪些网站可以做问卷
  • 做电商的进货网站北京网站建设外包公司排名
  • 企业级网站开发原理图现在建网站还能赚钱吗
  • 烟台cms建站模板seo网站技术培训