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

岳阳网站设计邳州做网站的公司

岳阳网站设计,邳州做网站的公司,保定网站优化,万网免费建企业网站这一章节我们来讨论一下如何通过属性注入Bean#xff1f;这一章节分为两部分#xff0c;第一部分我们通过属性向对象注入值#xff0c;第二部分我们通过属性向对象注入还有一个对象的引用。1.如何通过属性向对象注入值#xff1f;#xff08;1#xff09;domainpackage c… 这一章节我们来讨论一下如何通过属性注入Bean这一章节分为两部分第一部分我们通过属性向对象注入值第二部分我们通过属性向对象注入还有一个对象的引用。1.如何通过属性向对象注入值1domainpackage com.raylee.my_new_spring.my_new_spring.ch01.topic_1_7;public class Cake {private final int id index;private static int index 0;private String name ;private double size 0;public String getName() {return name;}public void setName(String name) {this.name name;}public double getSize() {return size;}public void setSize(double size) {this.size size;}public int getId() {return id;}Overridepublic String toString() {return create the cake,its id: id , size: size inch ,name: name;} } 这一个领域类我们仅仅须要一个Cake就够了。可是我们在里面会加上名称name和大小size这两个属性然后我们通过Spring来帮我们赋值。2測试类package com.raylee.my_new_spring.my_new_spring.ch01.topic_1_7;import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations {/com/raylee/my_new_spring/my_new_spring/ch01/topic_1_7/ApplicationContext-test.xml }) public class CakeTest {Autowiredprivate ApplicationContext applicationContext;Testpublic void testChief() {Cake cake applicationContext.getBean(Cake.class);System.out.println(cake.getId());System.out.println(cake.getName());System.out.println(cake.getSize());} } 没什么特别。仅仅须要get那个Bean出来然后打印一下几个属性就可以。 3配置文件?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:contexthttp://www.springframework.org/schema/context xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:txhttp://www.springframework.org/schema/tx xmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd bean idcake classcom.raylee.my_new_spring.my_new_spring.ch01.topic_1_7.Cake property namename valueBlueberry Cheesecake / property namesize value7 / /bean /beans 配置文件比較重要我们在Bean里面须要插入property这个标签然后name这个属性须要跟我们的domain类的属性名字一样。注意这里首字母能够不区分大写和小写也就是bean idcakeclasscom.raylee.my_new_spring.my_new_spring.ch01.topic_1_7.Cakeproperty nameName valueBlueberry Cheesecake /property nameSize value7 //bean和bean idcakeclasscom.raylee.my_new_spring.my_new_spring.ch01.topic_1_7.Cakeproperty namename valueBlueberry Cheesecake /property namesize value7 //bean是一样的 可是像以下的全然的大写就会抛异常bean idcakeclasscom.raylee.my_new_spring.my_new_spring.ch01.topic_1_7.Cakeproperty nameNAME valueBlueberry Cheesecake /property nameSIZE value7 //bean  測试输出0Blueberry Cheesecake7.0 总结这一章节主要介绍了如何通过属性向对象注入值还有中间须要注意的大写和小写的问题 文件夹http://blog.csdn.net/raylee2007/article/details/50611627  我的githubhttps://github.com/raylee2015/my_new_spring  转载于:https://www.cnblogs.com/gccbuaa/p/7249788.html
http://wiki.neutronadmin.com/news/127624/

相关文章:

  • 服装营销型网站建设上海社区网站建设
  • 网站建设如何站内搜索超链接怎么做
  • 外贸网站源码怎么建wordpress主题开发过程
  • 高端企业网站建设蓦然郑州网站建设6免费wordpress导购主题
  • cms网站搭建wordpress搜索翻页404
  • 南京网站制作哪家专业搜索引擎推广的三种方式
  • 单位做网站需要多少钱微信音乐音频怎么关闭
  • 淘宝客怎么建设自己网站常用的网页开发技术有哪些
  • 做特卖的网站上品折扣网站建设中的背景图片模板
  • 合川网站制作企业网站有哪些企业
  • 制作网站的视频教程苏州网站建设网站建设
  • 佛山制作做网站网站页面设计工具
  • 辽宁建设厅网站什么时候换的7k7k网页游戏入口
  • 国外儿童社区网站模板站长统计幸福宝2022年排行榜
  • 网站采集注意网站建设的题目
  • 学网站建设与管理好吗网站建设自己能做吗
  • 深圳龙华企业网站设计网站备案没有固定电话
  • 网站的漂浮广告怎么做商务网站建设摘要
  • 网站制作 知乎seo查询爱站网
  • 网络工程师和网站开发员浙江省建设局房管科网站
  • 学设计的网站编程app开发软件
  • 哪里网站建设专业厦门 网站建设 公司哪家好
  • 做财经类新闻的网站建设一个网站的工作方案
  • 深圳市城乡和建设局网站首页wordpress 优惠码
  • 常德网站优化哪家好wordpress eva lovia
  • 企业网站备案管理系统建设行业信息管理系统网站
  • 国内做微商城比较知名的网站镇江微信推广平台
  • 做暧暧网站在线wordpress自适应手机修改
  • 百度的合作网站有哪些简洁风格的网站模板免费下载
  • 某网站做参考文献的书写wordpress 设计