淘先锋技术网

首页 1 2 3 4 5 6 7

如何在properties文件编写中换行?

package javaall;

/*@Component("employee")*/
/*请求代管,自动创建bean,id=employee*/
public class Employee {

    /*@Value("Employeename")*/
    private String name;
    /*@Value("worknumber")*/
    private String worknumber;

    public Employee() {
    }

    public Employee(String name, String worknumber) {
        this.name = name;
        this.worknumber = worknumber;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getWorknumber() {
        return worknumber;
    }

    public void setWorknumber(String worknumber) {
        this.worknumber = worknumber;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", worknumber='" + worknumber + '\'' +
                '}';
    }
}

package javaall;

import cn.yys.one.Employee;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component("corp")
public class Corp {

    @Value("${corpName}")
    private String corpName;
    
    @Resource(name = "staff")
    private List<Employee> staff;

    public Corp() {
    }

    public Corp(String corpName, List<Employee> staff) {
        this.corpName = corpName;
        this.staff = staff;
    }

    public String getCorpName() {
        return corpName;
    }

    public void setCorpName(String corpName) {
        this.corpName = corpName;
    }

    public List<Employee> getStaff() {
        return staff;
    }

    public void setStaff(List<Employee> staff) {
        this.staff = staff;
    }

    @Override
    public String toString() {
        return "Corp{" +
                "corpName='" + corpName + '\'' +
                ", staff=" + staff +
                '}';
    }
}

package javaall;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    public static void main(String[] args) {
        String path = "spring/beans.xml";
        /*必须先指出xml文件的配置路径*/
        ApplicationContext context = new ClassPathXmlApplicationContext(path);
        Corp info = context.getBean(Corp.class,"corp");
        System.out.println(info);/*输出信息*/
    }
}

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <!--注解java文件所在的包名-->
    <context:component-scan base-package="javaall" />
    <!--本机环境下寻找配置文件-->
    <context:property-placeholder location="spring/employee.properties"/>

    <!--构造注入Employee-->
    <bean id="staff-1" class="javaall.Employee">
        <constructor-arg index="0" value="韬韬"/>
        <constructor-arg index="1" value="0520"/>
    </bean>

    <!--设值注入Employee-->
    <bean id="staff-3" class="javaall.Employee">
        <property name="name" value="玺子"></property>
        <property name="worknumber" value="1128"></property>
    </bean>

    <!--注解注入-->
    <util:list id="staff">
        <ref bean="staff-1"/>
        <ref bean="staff-3"/>
    </util:list>
</beans>

输出结果:
在这里插入图片描述想要变成那种可以两个公司,相同员工,不知如何进行?

所以想请问各位大佬们,这个输出换行的问题该如何解决?我实在是找不到解决办法了。。。。。请求各位大佬帮我解答一下