{"id":1390,"date":"2024-01-30T00:29:44","date_gmt":"2024-01-29T16:29:44","guid":{"rendered":"http:\/\/zyg.luchers.cn\/?p=1390"},"modified":"2024-01-30T00:33:50","modified_gmt":"2024-01-29T16:33:50","slug":"springioc%e5%ae%b9%e5%99%a8%e4%b9%8b%e5%9f%ba%e4%ba%8exml%e7%ae%a1%e7%90%86bean%ef%bc%88%e5%ae%9e%e9%aa%8c%e4%ba%8c%ef%bc%89","status":"publish","type":"post","link":"http:\/\/zyg.luchers.cn\/index.php\/2024\/01\/30\/springioc%e5%ae%b9%e5%99%a8%e4%b9%8b%e5%9f%ba%e4%ba%8exml%e7%ae%a1%e7%90%86bean%ef%bc%88%e5%ae%9e%e9%aa%8c%e4%ba%8c%ef%bc%89\/","title":{"rendered":"springIoC\u5bb9\u5668\u4e4b\u57fa\u4e8eXML\u7ba1\u7406Bean\uff08\u5b9e\u9a8c\u4e8c\uff09"},"content":{"rendered":"<h4>\u5b9e\u9a8c\u4e8c\uff1a\u4f9d\u8d56\u6ce8\u5165\u4e4bsetter\u6ce8\u5165<\/h4>\n<p><strong>\u2460\u521b\u5efa\u5b66\u751f\u7c7bStudent<\/strong><\/p>\n<pre><code class=\"language-java\">package com.atguigu.spring6.bean;\n\npublic class Student {\n\n    private Integer id;\n\n    private String name;\n\n    private Integer age;\n\n    private String sex;\n\n    public Student() {\n    }\n\n    public Integer getId() {\n        return id;\n    }\n\n    public void setId(Integer id) {\n        this.id = id;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public Integer getAge() {\n        return age;\n    }\n\n    public void setAge(Integer age) {\n        this.age = age;\n    }\n\n    public String getSex() {\n        return sex;\n    }\n\n    public void setSex(String sex) {\n        this.sex = sex;\n    }\n\n    @Override\n    public String toString() {\n        return &quot;Student{&quot; +\n                &quot;id=&quot; + id +\n                &quot;, name=&#039;&quot; + name + &#039;\\&#039;&#039; +\n                &quot;, age=&quot; + age +\n                &quot;, sex=&#039;&quot; + sex + &#039;\\&#039;&#039; +\n                &#039;}&#039;;\n    }\n\n}<\/code><\/pre>\n<p><strong>\u2461\u914d\u7f6ebean\u65f6\u4e3a\u5c5e\u6027\u8d4b\u503c<\/strong><\/p>\n<p>spring-di.xml<\/p>\n<pre><code class=\"language-xml\">&lt;bean id=&quot;studentOne&quot; class=&quot;com.atguigu.spring6.bean.Student&quot;&gt;\n    &lt;!-- property\u6807\u7b7e\uff1a\u901a\u8fc7\u7ec4\u4ef6\u7c7b\u7684setXxx()\u65b9\u6cd5\u7ed9\u7ec4\u4ef6\u5bf9\u8c61\u8bbe\u7f6e\u5c5e\u6027 --&gt;\n    &lt;!-- name\u5c5e\u6027\uff1a\u6307\u5b9a\u5c5e\u6027\u540d\uff08\u8fd9\u4e2a\u5c5e\u6027\u540d\u662fgetXxx()\u3001setXxx()\u65b9\u6cd5\u5b9a\u4e49\u7684\uff0c\u548c\u6210\u5458\u53d8\u91cf\u65e0\u5173\uff09 --&gt;\n    &lt;!-- value\u5c5e\u6027\uff1a\u6307\u5b9a\u5c5e\u6027\u503c --&gt;\n    &lt;property name=&quot;id&quot; value=&quot;1001&quot;&gt;&lt;\/property&gt;\n    &lt;property name=&quot;name&quot; value=&quot;\u5f20\u4e09&quot;&gt;&lt;\/property&gt;\n    &lt;property name=&quot;age&quot; value=&quot;23&quot;&gt;&lt;\/property&gt;\n    &lt;property name=&quot;sex&quot; value=&quot;\u7537&quot;&gt;&lt;\/property&gt;\n&lt;\/bean&gt;<\/code><\/pre>\n<p><strong>\u2462\u6d4b\u8bd5<\/strong><\/p>\n<pre><code class=\"language-java\">@Test\npublic void testDIBySet(){\n    ApplicationContext ac = new ClassPathXmlApplicationContext(&quot;spring-di.xml&quot;);\n    Student studentOne = ac.getBean(&quot;studentOne&quot;, Student.class);\n    System.out.println(studentOne);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u9a8c\u4e8c\uff1a\u4f9d\u8d56\u6ce8\u5165\u4e4bsetter\u6ce8\u5165 \u2460\u521b\u5efa\u5b66\u751f\u7c7bStudent package com.atguigu.spr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1390","post","type-post","status-publish","format-standard","hentry","category-spring-spring"],"_links":{"self":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/1390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1390"}],"version-history":[{"count":0,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/1390\/revisions"}],"wp:attachment":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1390"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}