package com.spring.springTest.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class WebsiteVO {
public String driver;
private String url;
private String user;
private String password;
}
2. studyController.java
@RequestMapping(value = "/website", method = RequestMethod.GET)
public String homeworkGet(Model model) {
AbstractApplicationContext ctx = new GenericXmlApplicationContext("xml/website.xml");
List<WebsiteVO> vos = new ArrayList<WebsiteVO>();
for(int i=1; i<=4; i++) {
vos.add(ctx.getBean("vo" + i, WebsiteVO.class));
}
ctx.close();
model.addAttribute("vos", vos);
return "study/xml/website";
}
3. website.xml
<?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="vo1" class="com.spring.springTest.vo.WebsiteVO">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db명"/>
<property name="user" value="root"/>
<property name="password" value="1234"/>
</bean>
<bean id="vo2" class="com.spring.springTest.vo.WebsiteVO">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
<property name="user" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<bean id="vo3" class="com.spring.springTest.vo.WebsiteVO">
<property name="driver" value="org.mariadb.jdbc.Driver"/>
<property name="url" value="jdbc:mariadb://localhost:3306/db명"/>
<property name="user" value="root"/>
<property name="password" value="1234"/>
</bean>
<bean id="vo4" class="com.spring.springTest.vo.WebsiteVO">
<property name="driver" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/db명"/>
<property name="user" value="postgres"/>
<property name="password" value="1234"/>
</bean>
</beans>
4. website.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctp" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>website.jsp</title>
<jsp:include page="/WEB-INF/views/include/bs5.jsp" />
</head>
<body>
<p><br/></p>
<div class="container">
<h2>WebSite JDBC 정보 보기(vo명: WebSiteVO)</h2>
<c:forEach var="vo" items="${vos}" varStatus="st">
<div>번호 : ${st.count}</div>
<div>드라이버 : ${vo.driver}</div>
<div>URL : ${vo.url}</div>
<div>User : ${vo.user}</div>
<div>Password : ${vo.password}</div>
<hr/>
</c:forEach>
<div><a href="${ctp}/" class="btn btn-success">돌아가기</a></div>
</div>
<p><br/></p>
</body>
</html>
첫댓글 JDBC정보는 1회만 처리해도 좋습니다... 수고하셨어요