Spring_DI_Value
18546 ワード
目次
- 1.2. コード#コード#
- 1.1.1. Program (Main)
- 1.1.2. NewlecExam.Java(Examインタフェース実装クラス)
- 1.1.3. setting.xml DI
- 1.1.4. コンソール
- Reference
1.入力値
1.2. コード#コード#
1.1.1. Program (Main)
package spring.di;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring.di.entity.Exam;
import spring.di.entity.NewlecExam;
import spring.di.ui.ExamConsole;
import spring.di.ui.GridExamConsole;
import spring.di.ui.InLineExamConsole;
public class Program {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring/di/setting.xml");
// id명
ExamConsole console = (ExamConsole)context.getBean("console"); //
//자료형명
//ExamConsole console = context.getBean(ExamConsole.class);
console.print();
}
}
1.1.2. NewlecExam.Java(Examインタフェース実装クラス)
package spring.di.entity;
public class NewlecExam implements Exam {
private int kor;
private int eng;
private int math;
private int com;
public void setCom(int com) {
this.com = com;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getCom() {
return com;
}
@Override
public int total() {
// TODO Auto-generated method stub
return kor+eng+math+com;
}
@Override
public float avg() {
// TODO Auto-generated method stub
return total() / 4;
}
}
1.1.3. setting.xml DI
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="exam" class="spring.di.entity.NewlecExam">
<property name="kor" value="10">
<property name="eng" value="10">
<property name="math" value="10">
<property name="com" value="10">
</bean>
<bean id="console" class="spring.di.ui.InLineExamConsole">
<property name="exam" ref="exam"></property>
</bean>
</beans>
方法
package spring.di;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring.di.entity.Exam;
import spring.di.entity.NewlecExam;
import spring.di.ui.ExamConsole;
import spring.di.ui.GridExamConsole;
import spring.di.ui.InLineExamConsole;
public class Program {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring/di/setting.xml");
// id명
ExamConsole console = (ExamConsole)context.getBean("console"); //
//자료형명
//ExamConsole console = context.getBean(ExamConsole.class);
console.print();
}
}
package spring.di.entity;
public class NewlecExam implements Exam {
private int kor;
private int eng;
private int math;
private int com;
public void setCom(int com) {
this.com = com;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getCom() {
return com;
}
@Override
public int total() {
// TODO Auto-generated method stub
return kor+eng+math+com;
}
@Override
public float avg() {
// TODO Auto-generated method stub
return total() / 4;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="exam" class="spring.di.entity.NewlecExam">
<property name="kor" value="10">
<property name="eng" value="10">
<property name="math" value="10">
<property name="com" value="10">
</bean>
<bean id="console" class="spring.di.ui.InLineExamConsole">
<property name="exam" ref="exam"></property>
</bean>
</beans>
<property name="kor" value="10">
: setKor -> kor <property name="kor">
<value>10</value>
</property>
1.1.4. コンソール
Reference
Spring
Reference
この問題について(Spring_DI_Value), 我々は、より多くの情報をここで見つけました https://velog.io/@withcolinsong/SpringDIvalueテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol