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

如何加强精神文明网站建设内容竹子系统做的网站可以优化么

如何加强精神文明网站建设内容,竹子系统做的网站可以优化么,dw网站结构图怎么做,网页设计怎么加入图片Spring为Bean提供了多种实例化方式#xff0c;通常包括4种方式。#xff08;也就是说在Spring中为Bean对象的创建准备了多种方案#xff0c;目的是#xff1a;更加灵活#xff09; 第一种#xff1a;通过构造方法实例化第二种#xff1a;通过简单工厂模式实例化第三种通常包括4种方式。也就是说在Spring中为Bean对象的创建准备了多种方案目的是更加灵活 第一种通过构造方法实例化第二种通过简单工厂模式实例化第三种通过factory-bean实例化第四种通过FactoryBean接口实例化 1.通过构造方法实例化 默认情况下会调用Bean的无参数构造方法。 定义一个Bean package com.powernode.spring6.bean;public class SpringBean {public SpringBean() {System.out.println(SpringBean的无参数构造方法执行);} }Spring配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd!--Spring提供的实例化方式第一种在spring配置文件中直接配置类全路径Spring会自动调用该类的无参数构造方法来实例化Bean--bean idspringBean classcom.powernode.spring6.bean.SpringBean/ /beans测试 package com.powernode.spring6.test;import com.powernode.spring6.bean.SpringBean; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class BeanInstantiationTest {Testpublic void testInstantiation1(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);SpringBean springBean applicationContext.getBean(springBean, SpringBean.class);System.out.println(springBean);} }2.通过简单工厂模式实例化 定义一个Bean package com.powernode.spring6.bean; /*** Bean*/ public class Star {public Star() {System.out.println(Star的无参数构造方法执行);} }编写简单工厂模式当中的工厂类 package com.powernode.spring6.bean; /*** 简单工厂模式中的工厂类角色*/ public class StarFactory {// 工厂类中有一个静态方法public static Star get(){// Star对象最终实际上创建的时候还是我们负责new的对象return new Star();} }在Spring配置文件中指定创建该Bean的方法使用factory-method属性指定 !--Spring提供的实例化方式第二种通过简单工厂模式。你需要在Spring配置文件中告诉Spring框架调用哪个类的哪个方法获取Bean-- !--factory-method 属性指定的是工厂类当中的静态方法。也就是告诉Spring框架调用这个方法可以获取Bean。-- bean idstar classcom.powernode.spring6.bean.StarFactory factory-methodget/编写测试程序 Test public void testInstantiation2(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Star star applicationContext.getBean(star, Star.class);System.out.println(star); }3.通过factory-bean实例化 这种方式本质上是通过工厂方法模式进行实例化。 定义一个Bean package com.powernode.spring6.bean; /*** 工厂方法模式当中的 具体产品角色*/ public class Gun {public Gun() {System.out.println(Gun的无参数构造方法执行);} }定义具体工厂类工厂类中定义实例方法 package com.powernode.spring6.bean; /*** 工厂方法模式中的 具体工厂角色*/ public class GunFactory {// 工厂方法模式中的具体工厂角色中的方法是实例方法public Gun get(){// 实际上new对象还是我们自己new的return new Gun();} }在Spring配置文件中指定factory-bean以及factory-method !--Spring提供的实例化方式第三种通过工厂方法模式。通过 factory-bean属性 factory-method属性来共同完成。-- !--告诉Spring框架调用哪个对象的哪个方法来获取Bean。-- bean idgunFactory classcom.powernode.spring6.bean.GunFactory/ !--factory-bean属性告诉Spring调用哪个对象。factory-method告诉Spring调用该对象的哪个方法。-- bean idgun factory-beangunFactory factory-methodget/编写测试程序 Test public void testInstantiation3(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Gun gun applicationContext.getBean(gun, Gun.class);System.out.println(gun); }4.通过FactoryBean接口实例化 以上的第三种方式中factory-bean是我们自定义的factory-method也是我们自己定义的。 在Spring中当你编写的类直接实现FactoryBean接口之后factory-bean不需要指定了factory-method也不需要指定了。 factory-bean会自动指向实现FactoryBean接口的类factory-method会自动指向getObject()方法。 定义一个Bean package com.powernode.spring6.bean; /*** 普通的Bean*/ public class Person {public Person() {System.out.println(Person的无参数构造方法执行);} }编写一个类实现FactoryBean接口 package com.powernode.spring6.bean;import org.springframework.beans.factory.FactoryBean;public class PersonFactoryBean implements FactoryBeanPerson {// PersonFactoryBean也是一个Bean这个Bean比较特殊叫做工厂Bean// 通过工厂Bean可以获取普通的BeanOverridepublic Person getObject() throws Exception {// 最终这个Bean的创建还是我们自己new的return new Person();}Overridepublic Class? getObjectType() {return null;}/*** 这个方法在接口中有默认实现* 默认返回true表示单例的* 返回false表示多例的* return*/Overridepublic boolean isSingleton() {return FactoryBean.super.isSingleton();} }在Spring配置文件中配置FactoryBean !--Spring提供的实例化方式第四种通过FactoryBean接口来实现。-- !--这种方式实际上就是第三种方式的简化。-- !--由于你编写的类实现了FactoryBean接口所以这个类是一个特殊的类不需要你再手动指定factory-bean、factory-method-- !--通过一个特殊的Bean工厂Bean。来返回一个普通的Bean Person对象。-- !--通过FactoryBean这个工厂Bean主要是想对普通Bean进行加工处理。-- bean idperson classcom.powernode.spring6.bean.PersonFactoryBean/测试程序 Test public void testInstantiation4(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Person person applicationContext.getBean(person, Person.class);System.out.println(person); }FactoryBean在Spring中是一个接口。被称为“工厂Bean”。“工厂Bean”是一种特殊的Bean。所有的“工厂Bean”都是用来协助Spring框架来创建其他Bean对象的。 5.BeanFactory和FactoryBean的区别 1 BeanFactory Spring IoC容器的顶级父接口BeanFactory被翻译为“Bean工厂”在Spring的IoC容器中“Bean工厂”负责创建Bean对象。 BeanFactory是工厂。 2 FactoryBean FactoryBean它是一个Bean是一个能够辅助Spring实例化其它Bean对象的一个Bean。 在Spring中Bean可以分为两类 第一类普通Bean第二类工厂Bean记住工厂Bean也是一种Bean只不过这种Bean比较特殊它可以辅助Spring实例化其它Bean对象。 6 注入自定义Date java.util.Date在Spring中被当做简单类型简单类型在注入的时候可以直接使用value属性或value标签来完成。但对于Date类型来说采用value属性或value标签赋值的时候对日期字符串的格式要求非常严格必须是这种格式的Mon Oct 10 14:30:26 CST 2022。其他格式是不会被识别的。 package com.powernode.spring6.bean;import java.util.Date;/*** 普通的Bean*/ public class Student {// java.util.Date 在Spring当中被当做简单类型注入日期字符串格式有要求// java.util.Date 在Spring当中也可以被当做非简单类型private Date birth;public void setBirth(Date birth) {this.birth birth;}Overridepublic String toString() {return Student{ birth birth };} }编写DateFactoryBean类实现FactoryBean接口 package com.powernode.spring6.bean;import org.springframework.beans.factory.FactoryBean;import java.text.SimpleDateFormat; import java.util.Date;public class DateFactoryBean implements FactoryBeanDate {// 定义属性接收日期字符串private String strDate;// 通过构造方法给日期字符串属性赋值public DateFactoryBean(String strDate) {this.strDate strDate;}Overridepublic Date getObject() throws Exception {SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd);Date date sdf.parse(strDate);return date;}Overridepublic Class? getObjectType() {return null;} }在Spring配置文件中配置 !--通过工厂BeanDateFactoryBean来返回普通Bean:java.util.Date-- bean iddateFactoryBean classcom.powernode.spring6.bean.DateFactoryBeanconstructor-arg index0 value1999-10-11/ /bean bean idstudent classcom.powernode.spring6.bean.Studentproperty namebirth refdateFactoryBean/ /bean测试 Test public void testDate(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);Student student applicationContext.getBean(student, Student.class);System.out.println(student); }
文章转载自:
http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn
http://www.morning.mnyzz.cn.gov.cn.mnyzz.cn
http://www.morning.lbqt.cn.gov.cn.lbqt.cn
http://www.morning.dsmwy.cn.gov.cn.dsmwy.cn
http://www.morning.bjsites.com.gov.cn.bjsites.com
http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn
http://www.morning.ljbm.cn.gov.cn.ljbm.cn
http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn
http://www.morning.ymbqr.cn.gov.cn.ymbqr.cn
http://www.morning.jkwwm.cn.gov.cn.jkwwm.cn
http://www.morning.qwwcf.cn.gov.cn.qwwcf.cn
http://www.morning.xyrss.cn.gov.cn.xyrss.cn
http://www.morning.txzmy.cn.gov.cn.txzmy.cn
http://www.morning.c7493.cn.gov.cn.c7493.cn
http://www.morning.kfhm.cn.gov.cn.kfhm.cn
http://www.morning.aowuu.com.gov.cn.aowuu.com
http://www.morning.fypgl.cn.gov.cn.fypgl.cn
http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn
http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn
http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn
http://www.morning.cbmqq.cn.gov.cn.cbmqq.cn
http://www.morning.lhqw.cn.gov.cn.lhqw.cn
http://www.morning.qptbn.cn.gov.cn.qptbn.cn
http://www.morning.yptwn.cn.gov.cn.yptwn.cn
http://www.morning.pflpb.cn.gov.cn.pflpb.cn
http://www.morning.bqxxq.cn.gov.cn.bqxxq.cn
http://www.morning.qmzwl.cn.gov.cn.qmzwl.cn
http://www.morning.bnlsd.cn.gov.cn.bnlsd.cn
http://www.morning.gkjnz.cn.gov.cn.gkjnz.cn
http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn
http://www.morning.gthc.cn.gov.cn.gthc.cn
http://www.morning.bxqry.cn.gov.cn.bxqry.cn
http://www.morning.hypng.cn.gov.cn.hypng.cn
http://www.morning.dxsyp.cn.gov.cn.dxsyp.cn
http://www.morning.c7491.cn.gov.cn.c7491.cn
http://www.morning.wynnb.cn.gov.cn.wynnb.cn
http://www.morning.rszwc.cn.gov.cn.rszwc.cn
http://www.morning.fdjwl.cn.gov.cn.fdjwl.cn
http://www.morning.gxhqt.cn.gov.cn.gxhqt.cn
http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn
http://www.morning.qphcq.cn.gov.cn.qphcq.cn
http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn
http://www.morning.qbjrf.cn.gov.cn.qbjrf.cn
http://www.morning.lydtr.cn.gov.cn.lydtr.cn
http://www.morning.hmgqy.cn.gov.cn.hmgqy.cn
http://www.morning.eshixi.com.gov.cn.eshixi.com
http://www.morning.ppghc.cn.gov.cn.ppghc.cn
http://www.morning.czgtt.cn.gov.cn.czgtt.cn
http://www.morning.rwqj.cn.gov.cn.rwqj.cn
http://www.morning.qjldz.cn.gov.cn.qjldz.cn
http://www.morning.mkydt.cn.gov.cn.mkydt.cn
http://www.morning.rjnrf.cn.gov.cn.rjnrf.cn
http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn
http://www.morning.qsswb.cn.gov.cn.qsswb.cn
http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn
http://www.morning.fthqc.cn.gov.cn.fthqc.cn
http://www.morning.plcyq.cn.gov.cn.plcyq.cn
http://www.morning.xrrbj.cn.gov.cn.xrrbj.cn
http://www.morning.bpmth.cn.gov.cn.bpmth.cn
http://www.morning.lfttb.cn.gov.cn.lfttb.cn
http://www.morning.rjrlx.cn.gov.cn.rjrlx.cn
http://www.morning.ddtdy.cn.gov.cn.ddtdy.cn
http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn
http://www.morning.ljcf.cn.gov.cn.ljcf.cn
http://www.morning.bkcnq.cn.gov.cn.bkcnq.cn
http://www.morning.sdkaiyu.com.gov.cn.sdkaiyu.com
http://www.morning.drcnf.cn.gov.cn.drcnf.cn
http://www.morning.xsfg.cn.gov.cn.xsfg.cn
http://www.morning.hmgqy.cn.gov.cn.hmgqy.cn
http://www.morning.mjtgt.cn.gov.cn.mjtgt.cn
http://www.morning.jjnry.cn.gov.cn.jjnry.cn
http://www.morning.lnnc.cn.gov.cn.lnnc.cn
http://www.morning.rqdx.cn.gov.cn.rqdx.cn
http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn
http://www.morning.qkpzq.cn.gov.cn.qkpzq.cn
http://www.morning.lqjlg.cn.gov.cn.lqjlg.cn
http://www.morning.xhkgl.cn.gov.cn.xhkgl.cn
http://www.morning.wplbs.cn.gov.cn.wplbs.cn
http://www.morning.rnxw.cn.gov.cn.rnxw.cn
http://www.morning.jqjnl.cn.gov.cn.jqjnl.cn
http://www.tj-hxxt.cn/news/249001.html

相关文章:

  • 免费空间建站网站推荐皖icp备 网站建设
  • 网站建设公司税负率免费网站mv
  • 做整形网站多少钱微信小程序怎么做活动
  • wordpress建站访问提示不安全手机能进封禁网站的浏览器
  • 苏州网站建设caiyiduo网站的建设费 账务处理
  • 兰州网络公司网站做公司
  • 企业网站的建立和推广外贸网站收到询盘
  • 高端品牌网站建设公司哪家好asp网站文件
  • 邯郸做紧固件网站背景墙图片2023新款
  • 学校网站的常规化建设营销型网站是什么
  • 自己的网站发文章怎么做外链英文外贸网站建设网站设计方案
  • 潜江公司做网站网站添加百度统计代码吗
  • 做网站运营需要会什么连云港网站建设 连云港网站制作
  • 智能建站实验报告如何做淘宝网站
  • 网站模板安装教程前端设计模板
  • 吉林建设厅网站昆明做网站做的好的公司
  • 网站公告栏代码优化网站快速排名软件
  • 网站多语言解决方案wordpress 访问速度慢
  • 网站降权多久恢复有了域名怎么建网站联系方式
  • 特价网站建设官网网站 建站模式
  • 网站服务公司案例学习编程
  • 网站的建站过程成都广告公司招聘
  • 黄冈论坛网站有哪些品牌型网站制作哪
  • 手机wap购物网站模板wordpress购物diy
  • 免费制作网站的平台68设计网
  • 礼品兑换网站怎么做网页升级未成年人自觉离开
  • 昆明网站开发报价广州公司网站开发
  • 外贸网站建设 评价国产化网站建设
  • 三亚网站建设品牌微信软文范例
  • app与网站外贸软件好用的