gzk329
V2EX  ›  Java

bean 的 xml 文件中 单标签和一对标签有区别吗?

  •  
  •   gzk329 · Aug 25, 2020 · 1387 views
    This topic created in 2090 days ago, the information mentioned may be changed or developed.
        <bean id="helloWorld" class="com.gzk.HelloWorld" scope="singleton" >
            <property name="message" value="Hello World!"/>
        </bean>
    
        <bean class="com.gzk.InitHelloWorld" /> 
    <!--这句话不加</bean> 也是一个 initHelloWorld 类的对象的意思吗?-->
    
    4 replies    2020-08-25 17:25:57 +08:00
    gzk329
        1
    gzk329  
    OP
       Aug 25, 2020
    是不是要加别的参数的时候用一对标签? 不然的话就可以省略?
    如果是这样的化那是我傻了
    gzk329
        2
    gzk329  
    OP
       Aug 25, 2020
    但是这句话连 id 都能省掉了嘛
    lxk11153
        3
    lxk11153  
       Aug 25, 2020
    1. 可以省略,如果没子标签
    2. 属性能否省略你得看实现呀,spring-bean 的 id 实现是有默认 id 生成策略的,默认是类名+序号吧
    stevenkang
        4
    stevenkang  
       Aug 25, 2020
    找到一点资料:
    https://www.w3.org/standards/xml/core.html

    All elements must be closed or marked as empty.

    Empty elements can be closed as normal, <happiness></happiness> or you can use a special short-form, <happiness /> instead.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   910 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:27 · PVG 06:27 · LAX 15:27 · JFK 18:27
    ♥ Do have faith in what you're doing.