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

如何建设网站和app重庆网站建设企业

如何建设网站和app,重庆网站建设企业,网络设计与集成,沈阳男科医院好吗标题注入依赖注入的方式通过Set方法注入通过构造方法注入自动注入依赖注入的数据类型注入Bean对象注入基本数据类型和字符串注入List注入Set注入Map注入Properties注解实现IOCComponentRepository、Service、Controller注入 依赖注入的方式 在使用依赖注入时#xff0c;如果… 标题注入依赖注入的方式通过Set方法注入通过构造方法注入自动注入依赖注入的数据类型注入Bean对象注入基本数据类型和字符串注入List注入Set注入Map注入Properties注解实现IOCComponentRepository、Service、Controller注入 依赖注入的方式 在使用依赖注入时如果注入的是 Bean 对象那么要求注入的 Bean 对象与被注入的 Bean 对象都需要 Spring 通过Set方法注入 需要为注入的成员变量提供 Set 方法。 配置文件 bean idusersDao classcom.bjsxt.dao.impl.UsersDaoImpl/ bean idusersDaoMybatis classcom.bjsxt.dao.impl.UsersDaoImpl/ bean idusersService namename1,name2,name3 classcom.bjsxt.service.impl.UsersServiceImpl!--name要和UsersServiceImpl中属性名相同--property nameusersDaoref beanusersDaoMybatis//property !--property nameusersDao refusersDaoMybatis/-- /beanBean对象 private UsersDao usersDao; public UsersDao getUsersDao() {return usersDao; } public void setUsersDao(UsersDao usersDao) {this.usersDao usersDao; }通过构造方法注入 Bean 对象中需要提供有参的构造方法 配置文件 bean idusersDaoMybatis classcom.bjsxt.dao.impl.UsersDaoMybatisImpl/ bean idusersService namename1, name2, name3 classcom.bjsxt.service.impl.UsersServiceImpl!--property nameusersDao refusersDaoMybatis/--!--一个constructor-arg标签表示构造方法中的一个参数name:根据参数名称识别参数index:根据参数的位置识别参数type:根据参数类型识别参数--constructor-arg typecom.bjsxt.dao.UsersDaoref beanusersDaoMybatis//constructor-arg /bean2.Bean对象 private UsersDao usersDao; public UsersServiceImpl(UsersDao usersDao){this.usersDao usersDao; }自动注入 自动注入的方式有两种一种是全局配置自动注入另一种是局部配置自动注入。 无论全局配置或局部单独配置都有 5 个值可以选择 no当 autowire 设置为 no 的时候Spring 就不会进行自动注入。byName在 Spring 容器中查找 id 与属性名相同的 bean并进行注入。需要提供 set 方 法。byType在 Spring 容器中查找类型与属性名的类型相同的 bean并进行注入。需要提 供 set 方法。constructor仍旧是使用 byName 方式只不过注入的时候使用构造方式进行注入。default全局配置的 default 相当于 no局部的 default 表示使用全局配置设置 局部自动注入通过 bean 标签中的 autowier 属性配置自动注入有效范围仅针对当前 bean 标签生效 全局自动注入通过 beans 标签中的 default-autowire 有效范围配置文件中的所有 bean 依赖注入的数据类型 注入Bean对象 方式一 property nameFieldNameref beanBeanID/ /property方式二 property nameFieldName refBeanID/注入基本数据类型和字符串 方式一 property nameFieldNamevaluecontent/value /property !--content是要传入内容的值--方式二 property nameFieldName valueContent/注入List property nameuserslistbean classcom.bjsxt.pojo.Usersproperty nameusername valueOldlu/property nameuserage value30//beanbean classcom.bjsxt.pojo.Usersproperty nameusername valueadmin/property nameuserage value20//bean/list/property注入Set property nameusersSetsetbean classcom.bjsxt.pojo.Usersproperty nameusername valueOldlu-set/property nameuserage value30//beanbean classcom.bjsxt.pojo.Usersproperty nameusername valueadmin-set/property nameuserage value20//bean/set/property注入Map 方式一 property namemapmapentry keykey1 valuevalue1/entry keykey2 valuevalue2//map/property方式二 bean idusers1 class...... bean idusers1 class...... property nameFieldNamemapentry keykey1 value-refusers1/entry keykey2 value-refusers2//map /property注入Properties property nameFieldName propsprop keyKeyNameContent/prop/props /property注解实现IOC E:\java\Spring\spring_ioc2Component 作用用于创建对象放入Spring容器相当于 bean id class 注意 要在配置文件中配置扫描的包扫描到该注解才能生效。 context:component-scan base-packagecom.itbaizhan /context:component-scan Component 注解配置bean的默认id是首字母小写的类名。也 可以手动设置bean的id值。 / 此时bean的id为studentDaoImpl Component public class StudentDaoImpl implements StudentDao{public Student findById(int id) {// 模拟根据id查询学生return new Student(1,百战程序 员,北京);}}// 此时bean的id为studentDao Component(studentDao) public class StudentDaoImpl implements StudentDao{public Student findById(int id) {// 模拟根据id查询学生return new Student(1,百战程序 员,北京);} }Repository、Service、Controller 作用这三个注解和Component的作用一样使用它们是为了区分该类属于什么层。 Repository用于Dao层Service用于Service层Controller用于Controller层 Scope指定bean的创建策略:singleton prototype request session globalsession
http://www.dnsts.com.cn/news/8381.html

相关文章:

  • xml网站地图怎么做江苏省建设厅网站权力阳光系统
  • 商城网站建设明细莱芜市官网
  • 北京网站建设兴田德润官网多少WordPress怎么添加留言功能
  • 查看网站开发语言seo网站排名优化教程
  • vip视频解析网站怎么做的建筑网站大图
  • 用织梦做网站有后台吗360免费wifi旧版本下载
  • 管理系统网站建设营销型网站建设专家
  • 网站建设河南php网站安装包制作
  • 收企业做网站备案公众平台安全助手
  • 厦门北京网站建设公司网站使用cookies
  • 网站验证码 出不来杭州有奖举报
  • 郑州网站seo顾问请人做网站需要注意什么
  • 个人网站模板html代码免费建立一个网站的英文
  • 青岛企业网站制作公司我国哪些网站是做调查问卷的
  • 公司网站建设费建站技术入门
  • 好大夫在线网站官网做提眉的医生中国国家住房和城乡建设部网站
  • 深圳网站制作开发绍兴seo整站优化
  • 查网站是不是用shopify做的山东省建设协会网站
  • 网站建设 阿里巴巴旗下如何自己建一个微网站
  • 北京微信网站开发wordpress 主题 小工具
  • 做网站编辑校对百度广告点击软件源码
  • 翻墙到国外网站怎么做企业建站
  • 零基础学it从哪方面学起aso优化推广公司
  • 许昌中国建设银行官网站上海企业网络维护
  • 自动引流推广app优化算法分类
  • 浅析网站域名在搜索引擎排名中的作用腾讯云网站建设教程
  • 莆田个人仿牌外贸网站建设常州制作网站信息
  • 公司做网站多少钱乐器wordpress ftp安装
  • 弥勒网站设计公司python做网站吗
  • 建站需求高新快速建设网站找哪家