Spring
about. What I learned

Spring

#Spring Sample파일 임포트하기

프로젝트 익스플로러에서 마우스 우클릭 후 임포트 선택하기
임포트하기 안에서 아카이브파일 선택후 zip파일로 넣어주기

해당 파일 우클릭하여 properties 클릭하기 -> java build path(파일을 가져오게되면 무조건 설정해야한다.) 에서 libraries에서

현재 톰캣 서버로 변경하기

#maven - 통합 라이브러리 관리 및 배포 지원

라이브러리 : 특정 목적에 따라 미리 구현된 프로그램 파일 집합, jar파일, ear파일

통합 라이브러리 관리 : 설정된 내용을 기반으로 jar 파일을 버전별 보관 및 제공

poem.xml에서 전역변수를 지정해 놓은 것과 같다.
이 파일은 enter를 제외한 공백은 허용하지 않는다.

jdbc.url=jdbc:oracle:thin:@아이피:포트(포트는 변경될 수 있다):서비스명

 

 

데이터와 연결하기

 

 

 

SAMPLE SPRING에 이렇게 생성하기 그리고 각 파일 코드 설정

데이터베이스로 넘어와 SYS에 다른사용자 TEST 추가하면서 모든 권한 부여 후 새접속 생성그리고 테이블 만들고 시퀀스 까지 생성

테이블 생성
데이터 삽입(16개) 과 커밋 

package com.spring.sample.web.test.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.spring.sample.web.test.dao.ITestDao;

@Service	
public class TestService implements ITestService {
	
	@Autowired
	public ITestDao iTestDao;

	@Override
	public List<HashMap<String, String>> getBList() throws Throwable {
		return iTestDao.getBList();
	}
}
package com.spring.sample.web.test.service;

import java.util.HashMap;
import java.util.List;

public interface ITestService {

	public List<HashMap<String, String>> getBList() throws Throwable;

}

 

package com.spring.sample.web.test.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository // 저장소에 접근한다 라는 Annotation
public class TestDao implements ITestDao {

	@Autowired
	public SqlSession sqlSession;
	//DB와 이어주기 위한 선언

	@Override
	public List<HashMap<String, String>> getBList() throws Throwable {
		return sqlSession.selectList("B.getBList");
	}
}
package com.spring.sample.web.test.dao;

import java.util.HashMap;
import java.util.List;

public interface ITestDao {

	public List<HashMap<String, String>> getBList() throws Throwable;

}
package com.spring.sample.web.test.controller;


import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.spring.sample.web.test.service.ITestService;

@Controller
public class TestController {
	@Autowired
	public ITestService iTestService;
	
	@RequestMapping(value="/test1")
	public ModelAndView test1(ModelAndView mav) throws Throwable {
		
		List<HashMap<String,String>> list
				=iTestService.getBList();
		
		mav.addObject("list", list);
		
		mav.setViewName("test/test1");
	
	return mav;
	}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
table{
width : 600px;
height : 10px;
border-collapse: collapse;
border : 2px solid black;
}
thead, tbody,td,th{
border-collapse: collapse;
border : 2px solid black;
text-align: center;
}
th{
background-color: orange;
}
</style>
</head>
<body>
<table>
<thead>
	<tr>
		<th>번호</th>
		<th>제목</th>
		<th>작성자</th>
		<th>작성일</th>
	</tr>
</thead>
<tbody>
	<c:forEach var="data" items="${list }">
		<tr>
			<td>${data.B_NO}</td>
			<td>${data.B_TITLE}</td>
			<td>${data.B_WRITER}</td>
			<td>${data.B_DT}</td>
		</tr>
	</c:forEach>
</tbody>
</table>
</body>
</html>

 

'about. What I learned' 카테고리의 다른 글

4주차 자바스터디  (0) 2021.08.25
DATA BASE ORACLE - 4/19  (0) 2021.04.20
DATA BASE - 함수  (0) 2021.04.18
4/13 DATABASE - 오라클 수업  (0) 2021.04.13
4/12 DATABASE - 배운 것  (0) 2021.04.12