java

์Šคํ”„๋ง ๋ ˆ๊ฑฐ์‹œ - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(1) ํ™˜๊ฒฝ์„ค์ •

dev_summer 2021. 2. 27. 14:27

 

 

์„ ์ƒ๋‹˜์ด ๋ฐ”๋€Œ๊ณ  ๊ธฐ๋ณธ์ ์ธ ๋ ˆ๋ฒจ์„ ํ™•์ธํ•˜๊ธฐ์œ„ํ•ด ๋ ˆ๊ฑฐ์‹œ๋กœ ๊ฒŒ์‹œํŒ์„ ๋งŒ๋“ค์–ด ๋ณด๊ธฐ๋กœํ–ˆ๋‹น.

์Œค ๋„ˆ๋ฌด ๋นจ๋ž‘...ํžใ… ใ… 

 

 

์Šคํ”„๋ง๋ถ€ํŠธ๋Š” ์ž๋™ํ†ฐ์บฃ์ด์ง€๋งŒ ๋ ˆ๊ฑฐ์‹œ๋กœ ๊ฒŒ์‹œํŒ๋งŒ๋“ค๋•Œ๋Š” ์„œ๋ฒ„ ์„ค์ •ํ•ด์ค˜์•ผํ•œ๋‹ค.

 

 

๊ธฐ๋ณธ ๊ฒฝ๋กœ ์„ค์ •

 

 

 

 

ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜์ž๋งˆ์ž ์˜ค๋ฅ˜๊ฐ€ ๋‚œ๋‹ค๋ฉด ๋‹ค์‹œ ๋‹ค์šด ๋ฐ›๊ธฐ์œ„ํ•ด ๋ฐ‘์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์‹น ์ง€์›Œ๋ฒ„๋ฆฌ์Ÿˆ

๊บ…

 

 

 

 

ํ•œ๊ธ€ ์ธ์ฝ”๋”ฉ ์„ค์ •๋„ ํ•ด์ฃผ์Ÿˆ ์•„๋ž˜๋Š” ์›Œํฌ์ŠคํŽ˜์ด์Šค์˜ ์ธ์ฝ”๋”ฉ์„ค์ •! ์•ˆํ•ด์ค˜๋„ ์ž˜ ๋จน๊ธด ํ•œ๋ฐ ํ•œ๋ฒˆ ํ•ด๋ณด์ง€ ๋ชจ

 

 

 

์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๋ฒ„์ „์„ ๋งž์ถฐ์•ผํ•œ๋‹ค.

 

์Šคํ”„๋ง ๋ฒ„์ „์„ ํ™•์ธํ•ด์„œ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค. ์ž๋ฐ”๋ฒ„์ „์€ 1.8!

 

 

๋‹จ์œ„ํ…Œ์ŠคํŠธ ํ•  ์ œ์ด์œ ๋‹›์˜ ๋ฒ„์ „์€ 4.12!

 

 

์Šคํ”„๋งํ…Œ์ŠคํŠธ๋„ ๋‹ค์šด!

pom์— ๋ถ™์ผ๋•Œ์—๋„ ๋‚˜์˜์Šคํ”„๋ง๋ฒ„์ „์„ ํ™•์ธํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ๊ธฐ๋ฅผ ํ•˜์Ÿˆ!

 

 

 

 

 

ํ†ฐ์บฃ ์ž˜ ๋œจ๋Š”๊ฒƒ์„ ํ™•์ธํ•˜์˜€๋‹ค!

๊ทผ๋ฐ ํ•œ๊ธ€์ด ๊นจ์ง€๋‹ˆ web.xml์„ ์ˆ˜์ •ํ•˜์—ฌ์•ผ๊ฒ ๋‹ค.

	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>
			org.springframework.web.filter.CharacterEncodingFilter
		</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

 

 

ํ•„ํ„ฐ๋ฅผ ๊ฑธ์–ด์ฃผ๋ฉด ์™„๋ฃŒ์˜ค!

 

์ž˜๋œจ๋Š”๊ฒƒ์„ ํ™•์ธํ•˜์—ฌ๋•…

 

 

 

 

DB๋งŒ๋“ค๋Ÿฌ ๊ฐ€์•ผ์ง•

๊ธฐ์กด์— ์‚ฌ์šฉํ•˜์˜€๋˜ seoha๊ณ„์ •์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ด๋ธ”๋งŒ ์ƒ์„ฑํ•ด์ฃผ์—ˆ๋‹น.

CREATE TABLE `springdb`.`board` (
  `bno` INT NOT NULL INT(11) NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(100) NOT NULL,
  `content` TEXT NOT NULL,
  `write` VARCHAR(45) NOT NULL,
  `regDate` DATETIME NULL DEFAULT now(),
  `readCount` INT NULL DEFAULT '0',
  PRIMARY KEY (`bno`));

 

 

 

๋‘˜๋‹ค ๋‹ค์šด๋ฐ›๊ธฐ

๋‘˜๋‹ค pom.xml์— ๋„ฃ๊ธฐ

 

 

 

 

- root-context.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"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
		http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
	
	<!-- Root Context: defines shared resources visible to all other web components -->
	
	<bean id = "dataSouce" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url" value = "jdbc:mysql://localhost:3306/jspringdb"/>
		<property name="username" value="seoha"/>
		<property name="password" value="1234"/>
	</bean>
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSouce"/>
		
		
	</bean>
</beans>

 

 

์ž˜ ์—ฐ๊ฒฐ ๋ฌ๋Š”๋ฐ ์ œ์ด์œ ๋‹›์‚ฌ์šฉํ•˜๊ธฐ

package com.seoha.bbs;

import javax.inject.Inject;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring/root-context.xml"})
// ๋ฃจํŠธ์ปจํ…์ŠคํŠธ์˜ ํ™˜๊ฒฝ์„ค์ •์„ ํ…Œ์ŠคํŠธํ•ด๋ณด๊ฒ ๋‹ค.
public class DBTest {
	
	@Inject
	private SqlSessionFactory sqlFactory;
	
	@Test
	public void testFactory() {
		System.out.println(">>>>>>sqlFactory : "+sqlFactory);
	}
	
	@Test
	public void testSession() throws Exception{
		try (SqlSession session = sqlFactory.openSession()){
			System.out.println(">>>> session : "+session+"\n");
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}

 

 

 

 

 

 

 

์ž˜ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธ