package ch04_p01.ems;
import org.springframework.context.support.GenericXmlApplicationContext;
import ch04_p01.ems.member.Student;
import ch04_p01.ems.member.dao.StudentDao;
import ch04_p01.ems.member.service.EMSInformationService;
import ch04_p01.ems.member.service.PrintStudentInformationService;
import ch04_p01.ems.member.service.StudentDeleteService;
import ch04_p01.ems.member.service.StudentModifyService;
import ch04_p01.ems.member.service.StudentRe1gisterService;
import ch04_p01.ems.member.service.StudentSelectService;
import ch04_p01.ems.utils.InitSampleData;
public class MainClass {
public static void main(String[] args) {
/*
* IoC 컨테이너 생성
*/
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:applicationContext.xml");
// 샘플 데이터
InitSampleData initSampleData = ctx.getBean("initSampleData", InitSampleData.class);
String[] sNums = initSampleData.getsNums();
String[] sIds = initSampleData.getsIds();
String[] sPws = initSampleData.getsPws();
String[] sNames = initSampleData.getsNames();
int[] sAges = initSampleData.getsAges();
String[] sGenders = initSampleData.getsGenders();
String[] sMajors = initSampleData.getsMajors();
// 데이터베이스에 샘플 데이터 저장
StudentRe1gisterService re1gisterService = ctx.getBean("studentRe1gisterService", StudentRe1gisterService.class);
for (int i = 0; i < sNums.length; i++) {
re1gisterService.re1gister(new Student(sNums[i], sIds[i], sPws[i], sNames[i], sAges[i], sGenders[i], sMajors[i]));
}
// 학생 리스트
PrintStudentInformationService printStudentInformationService = ctx.getBean("printStudentInformationService", PrintStudentInformationService.class);
printStudentInformationService.printStudentsInfo();
re1gisterService = ctx.getBean("studentRe1gisterService", StudentRe1gisterService.class);
re1gisterService.re1gister(new Student("hbs006", "deer", "p0006", "melissa", 26, "W", "Music"));
StudentDao studentDao = ctx.getBean("studentDao", StudentDao.class);
System.out.println("re1gister() 후 studentDB: " + studentDao.getStudentDB().keySet());
printStudentInformationService.printStudentsInfo();
StudentSelectService selectService = ctx.getBean("studentSelectService", StudentSelectService.class);
System.out.println("select() 전 studentDB: " + studentDao.getStudentDB().keySet());
Student selectedStudent = selectService.select("hbs006");
System.out.println("STUDENT START ---------------------");
System.out.print("sNum:" + selectedStudent.getsNum() + "\t");
System.out.print("sId:" + selectedStudent.getsId() + "\t");
System.out.print("sPw:" + selectedStudent.getsPw() + "\t");
System.out.print("sName:" + selectedStudent.getsName() + "\t");
System.out.print("sAge:" + selectedStudent.getsAge() + "\t");
System.out.print("sGender:" + selectedStudent.getsGender() + "\t");
System.out.println("sMajor:" + selectedStudent.getsMajor());
System.out.println("END ---------------------");
StudentModifyService modifyService = ctx.getBean("studentModifyService", StudentModifyService.class);
modifyService.modify(new Student("hbs006", "pig", "p0066", "melissa", 27, "W", "Computer"));
printStudentInformationService.printStudentsInfo();
StudentDeleteService deleteService = ctx.getBean("studentDeleteService", StudentDeleteService.class);
deleteService.delete("hbs005");
printStudentInformationService.printStudentsInfo();
EMSInformationService emsInformationService = ctx.getBean("emsInformationService", EMSInformationService.class);
emsInformationService.printEMSInformation();
ctx.close();
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
package ch04_p01.ems.member.service;
import ch04_p01.ems.member.Student;
import ch04_p01.ems.member.dao.StudentDao;
public class StudentSelectService {
private StudentDao studentDao;
public StudentSelectService(StudentDao studentDao) {
this.studentDao = studentDao;
}
public Student select (String sNum) {
if (verify(sNum)) {
return studentDao.select(sNum);
} else {
System.out.println("Student information is unavailable");
}
return null;
}
public boolean verify(String sNum) {
Student student = studentDao.select(sNum);
return student == null ? true : false;
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
<?xml version="1.0" encoding="UTF-8"?>
<!-- InitSampleData 빈 -->
<bean id="initSampleData"
class="ch04_p01.ems.utils.InitSampleData">
<property name="sNums">
<array>
<value>hbs001</value>
<value>hbs002</value>
<value>hbs003</value>
<value>hbs004</value>
<value>hbs005</value>
</array>
</property>
<property name="sIds">
<array>
<value>rabbit</value>
<value>hippo</value>
<value>raccoon</value>
<value>elephant</value>
<value>lion</value>
</array>
</property>
<property name="sPws">
<array>
<value>p0001</value>
<value>p0002</value>
<value>p0003</value>
<value>p0004</value>
<value>p0005</value>
</array>
</property>
<property name="sNames">
<array>
<value>agatha</value>
<value>barbara</value>
<value>chris</value>
<value>doris</value>
<value>elva</value>
</array>
</property>
<property name="sAges">
<array>
<value>19</value>
<value>22</value>
<value>20</value>
<value>27</value>
<value>19</value>
</array>
</property>
<property name="sGenders">
<array>
<value>M</value>
<value>W</value>
<value>W</value>
<value>M</value>
<value>M</value>
</array>
</property>
<property name="sMajors">
<array>
<value>English</value>
<value>Korean</value>
<value>French</value>
<value>Philosophy</value>
<value>History</value>
</array>
</property>
</bean>
<!-- StudentDao 빈 -->
<bean id="studentDao"
class="ch04_p01.ems.member.dao.StudentDao" />
<!-- StudentRe1gisterService 빈 생성 -->
<bean id="studentRe1gisterService"
class="ch04_p01.ems.member.service.StudentRe1gisterService">
<constructor-arg ref="studentDao" />
</bean>
<!-- StudentModifyService 빈 생성 -->
<bean id="studentModifyService"
class="ch04_p01.ems.member.service.StudentModifyService">
<constructor-arg ref="studentDao" />
</bean>
<!-- StudentDeleteService 빈 생성 -->
<bean id="studentDeleteService"
class="ch04_p01.ems.member.service.StudentDeleteService">
<constructor-arg ref="studentDao" />
</bean>
<!-- StudentSelectService 빈 생성 -->
<bean id="studentSelectService"
class="ch04_p01.ems.member.service.StudentSelectService">
<constructor-arg ref="studentDao" />
</bean>
<!-- StudentAllSelectService 빈 생성 -->
<bean id="studentAllSelectService"
class="ch04_p01.ems.member.service.StudentAllSelectService">
<constructor-arg ref="studentDao" />
</bean>
<!-- PrintStudentInformationService 빈 생성 -->
<bean id="printStudentInformationService"
class="ch04_p01.ems.member.service.PrintStudentInformationService">
<constructor-arg ref="studentAllSelectService" />
</bean>
<!-- DBConnectionInfo 빈 -->
<!-- 개발에 사용하는 데이터베이스 빈 생성 -->
<bean id="dev_DBConnectionInfoDev"
class="ch04_p01.ems.member.DBConnectionInfo">
<property name="url" value="000.000.000.000" />
<property name="userId" value="admin" />
<property name="userPw" value="0000" />
</bean>
<!-- 실제 서비스에 이용하는 데이터베이스 빈 생성 -->
<bean id="real_DBConnectionInfo"
class="ch04_p01.ems.member.DBConnectionInfo">
<property name="url" value="111.111.111.111" />
<property name="userId" value="master" />
<property name="userPw" value="1111" />
</bean>
<!-- EMSInformationService 빈 -->
<bean id="emsInformationService"
class="ch04_p01.ems.member.service.EMSInformationService">
<property name="info"
value="Education Management System program was developed in 2022." />
<property name="copyRight"
value="COPYRIGHT (C) 2022 EMS CO., LTD. ALL RIGHT RESERVED. CONTACT MASTER FOR MORE INFORMATION." />
<property name="ver" value="The version is 1.0" />
<property name="sYear" value="2022" />
<property name="sMonth" value="3" />
<property name="sDay" value="1" />
<property name="eYear" value="2022" />
<property name="eMonth" value="4" />
<property name="eDay" value="30" />
<property name="developers">
<list>
<value>Cheney.</value>
<value>Eloy.</value>
<value>Jasper.</value>
<value>Dillon.</value>
<value>Kian.</value>
</list>
</property>
<!-- administrators 필드 초기화 -->
<property name="administrators">
<map>
<entry>
<key>
<value>Cheney</value>
</key>
<value>cheney@springPjt.org</value>
</entry>
<entry>
<key>
<value>Jasper</value>
</key>
<value>jasper@springPjt.org</value>
</entry>
</map>
</property>
<!-- dbInfos 필드 초기화 -->
<property name="dbInfos">
<map>
<!-- 개발용 데이터베이스 지정 -->
<entry>
<key>
<value>dev</value>
</key>
<ref bean="dev_DBConnectionInfoDev" />
</entry>
<!-- 실제 서비스 데이터베이스 지정 -->
<entry>
<key>
<value>real</value>
</key>
<ref bean="real_DBConnectionInfo" />
</entry>
</map>
</property>
</bean>
</beans>
hbs006 등록후 전체출력 자체는 되는데 select에서 오류남
그럴 이유가 있나? gpt랑 놀아봤는데 모르겠음...
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.