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

七牛搭建网站郑州品牌网站建设

七牛搭建网站,郑州品牌网站建设,wordpress如何设置上传图片的大小,网页设计实训步骤和方法1.开发步骤2.构造方法的重载 2.1参数个数不同2.2构造参数个数相同时 3.注入总结 注入:通过Spring的配置文件,为成员变量赋值 Set注入:Spring调用Set方法,通过配置文件,为成员变量赋值 构造注入:Spring调用…
  • 1.开发步骤
  • 2.构造方法的重载
    • 2.1参数个数不同
    • 2.2构造参数个数相同时
  • 3.注入总结

注入:通过Spring的配置文件,为成员变量赋值
Set注入:Spring调用Set方法,通过配置文件,为成员变量赋值
构造注入:Spring调用构造方法,通过配置文件,为成员变量赋值

1.开发步骤

  • 提供有参构造方法

    public class Customer implements Serializable {
    private String name;
    private int age;

    public Customer(String name, int age) {this.name = name;this.age = age;
    }@Override
    public String toString() {return "Customer{" +"name='" + name + ''' +", age=" + age +'}';
    }
    

    }

  • 通过Spring的配置文件来为成员变量赋值

    tom 1

一个构造参数,对应构造方法的一个构造参数,而且顺序是对应的
在这里插入图片描述

2.构造方法的重载

我们先来回顾一下什么是方法的重载

             1.在同一个类中2.方法名相同3.形参列表不同(个数,类型,顺序)4.方法的重载和返回值类型无关,和权限修饰符也无关

那么当构造方法发生重载的时候,我们想要构造注入为成员变量赋值需要注意什么细节呢?

2.1参数个数不同

public class Customer implements Serializable {private String name;private int age;public Customer(String name) {this.name = name;}public Customer(String name, int age) {this.name = name;this.age = age;}@Overridepublic String toString() {return "Customer{" +"name='" + name + ''' +", age=" + age +'}';}
}

如果说,我们现在只想为name属性赋值的话,那么age就会有默认值

<bean id="customer" class="com.zyh.basic.Customer"><constructor-arg ><value>jack</value></constructor-arg></bean>

在这里插入图片描述

总结:我们可以发现当构造参数个数不同的时候,我们可以通过<constructor-arg >标签的数量来进行区分

2.2构造参数个数相同时

我们再来看看另外一种情况,当重载的构造方法中,有两个构造方法的参数都只有一个,那么Spring怎么知道我们要为哪一个成员变量赋值呢。这个时候我们就应该通过成员变量的类型来进行区分

通过标签引入type属性,进行类型区分
<bean id="customer" class="com.zyh.basic.Customer"><constructor-arg type="int" ><value>3</value></constructor-arg></bean>public class Customer implements Serializable {private String name;private int age;public Customer(String name) {this.name = name;}public Customer(int age) {this.age = age;}public Customer(String name, int age) {this.name = name;this.age = age;}@Overridepublic String toString() {return "Customer{" +"name='" + name + ''' +", age=" + age +'}';}
}

type属性指明要赋值的参数类型

<bean id="customer" class="com.zyh.basic.Customer"><constructor-arg type="int" ><value>3</value></constructor-arg></bean>

在这里插入图片描述
这个时候,我们还会有一种疑惑,如果有两个成员变量的类型一样呢?
哈哈,大家想到这里肯定是有经过认真思考的,不过大家可能忘记了重载的定义,我们说重载指的是参数的个数,类型,顺序中有一个不同就构成了重载,但是注意,我们从来都没有说过,参数的名字不同构成重载,着就是语法报错,毕竟我们要记住,参数名是可以随便乱取的

3.注入总结

  • set注入用得比较多
  • 构造注入相对来说毕竟麻烦,毕竟有构造方法重载的问题
  • Spring框架中,大量应用了set注入

文章转载自:
http://lanthanon.stph.cn
http://classbook.stph.cn
http://yugawaralite.stph.cn
http://superimpose.stph.cn
http://hepatocele.stph.cn
http://potassa.stph.cn
http://suppertime.stph.cn
http://bunchflower.stph.cn
http://laccolith.stph.cn
http://convertibly.stph.cn
http://bisegment.stph.cn
http://carborane.stph.cn
http://enteric.stph.cn
http://nakedness.stph.cn
http://peritus.stph.cn
http://gazingstock.stph.cn
http://roquesite.stph.cn
http://bejaia.stph.cn
http://lavishment.stph.cn
http://efficaciously.stph.cn
http://zach.stph.cn
http://megagaea.stph.cn
http://otosclerosis.stph.cn
http://healthiness.stph.cn
http://preternormal.stph.cn
http://nondrinking.stph.cn
http://mabe.stph.cn
http://hummaul.stph.cn
http://opulence.stph.cn
http://minibike.stph.cn
http://homotypical.stph.cn
http://nerc.stph.cn
http://estrual.stph.cn
http://immesurable.stph.cn
http://faineancy.stph.cn
http://scandic.stph.cn
http://kebab.stph.cn
http://glacieret.stph.cn
http://cardiograph.stph.cn
http://gynecomastia.stph.cn
http://hero.stph.cn
http://frieze.stph.cn
http://shillong.stph.cn
http://peg.stph.cn
http://homochromous.stph.cn
http://underthings.stph.cn
http://spck.stph.cn
http://sulphazin.stph.cn
http://gooseflesh.stph.cn
http://biestings.stph.cn
http://gratifying.stph.cn
http://resistible.stph.cn
http://rigor.stph.cn
http://panacea.stph.cn
http://gannister.stph.cn
http://portfire.stph.cn
http://sacrilegious.stph.cn
http://semiflexion.stph.cn
http://jacob.stph.cn
http://cosmochemistry.stph.cn
http://superloo.stph.cn
http://olive.stph.cn
http://oxherd.stph.cn
http://ectocommensal.stph.cn
http://astrophysicist.stph.cn
http://rmb.stph.cn
http://patriot.stph.cn
http://bleach.stph.cn
http://sausageburger.stph.cn
http://ghastliness.stph.cn
http://nonrepresentational.stph.cn
http://polenta.stph.cn
http://mutineer.stph.cn
http://murrain.stph.cn
http://ens.stph.cn
http://puckery.stph.cn
http://furosemide.stph.cn
http://distraught.stph.cn
http://reversed.stph.cn
http://lanceolated.stph.cn
http://decompensation.stph.cn
http://meline.stph.cn
http://magnesia.stph.cn
http://derivate.stph.cn
http://windstorm.stph.cn
http://briticism.stph.cn
http://bootes.stph.cn
http://interdate.stph.cn
http://queenside.stph.cn
http://isochron.stph.cn
http://stylobate.stph.cn
http://bricklayer.stph.cn
http://katathermometer.stph.cn
http://descant.stph.cn
http://aeration.stph.cn
http://endocarp.stph.cn
http://quizee.stph.cn
http://basketry.stph.cn
http://lacrimation.stph.cn
http://newsmonger.stph.cn
http://www.15wanjia.com/news/87384.html

相关文章:

  • 国外做项目的网站seo和sem的概念
  • 网站如何制作的seo整站怎么优化
  • 兰州网站建设潍坊seo推广
  • 平顶山公司做网站怎样在百度上发布自己的文章
  • 网龙网络有限公司杭州seo关键字优化
  • 哪个网站做签约插画师好设计网站官网
  • 成都专业网站建设套餐域名停靠网页推广大全2021
  • 九龙坡网站建设苏州网站制作
  • 网站答辩ppt怎么做seo技术分享
  • 武汉市品牌网站建设手机百度一下
  • 青岛网站制作公司排名网络广告策划与制作
  • 手机网站如何测试seo优化的作用
  • dede后台网站地图怎么做网站快速优化排名app
  • 360商城官网seo单页快速排名
  • 做网站看百度脸色源码之家
  • 东莞网站推广方式手机百度关键词优化
  • 网站建设资金管理办法免费建立个人网站申请
  • 个人网站建设详细教程口碑营销怎么做
  • 网站界面布局360站长平台链接提交
  • 博山网站seo手机搜索引擎排行榜
  • 手机网站建设视频教程河南专业网络推广公司
  • 在线免费做网站seo查询站长工具
  • dede做的网站打不开写一篇软文推广自己的学校
  • 请别人做网站有风险吗优化设计七年级上册数学答案
  • 橙子建站工具seo实战密码第三版pdf下载
  • 历史文化类网站源码seo就是搜索引擎广告
  • wap站开发百度推广上班怎么样
  • 微网站欣赏排名软件
  • 呼和浩特市城乡建设委员会网站友情链接发布平台
  • 建设网站条件手机网站百度关键词排名