ํฐ์คํ ๋ฆฌ ๋ทฐ
(๊ตฌ)Spring
[์คํ๋ง๋ถํธ] ๋ถํธ์์ JSP์ ๋ง์ด๋ฐํฐ์ค ์ฌ์ฉํ๊ธฐ
yeahajeong 2019. 7. 16. 21:57๋ฐ์ํ
์๋ก์ด ํ๋ก์ ํธ ์์ฑ
DevTools๋ ์๋์ผ๋ก ์๋ฒ๋ฅผ ์ฌ์์ํ๊ฒ ํด์ฃผ๋ ํด์ด๋ค.
JSP๊ด๋ จ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ pom.xml์ ์ค์
๋ถํธ์์ JSP๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ๊ด๋ จ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ฐ๋ก ์ค์ ํด์ฃผ์ด์ผํ๋ค.
๋ค์ ์ฝ๋๋ฅผ dependency๋ถ๋ถ ๋ง์ง๋ง์ ๋ถ์ฌ๋ฃ๋๋ค.
1
2
3
4
5
6
7
8
9
10
11
|
<!-- JSP ์ค์ -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
|
application.properties ์์ค์ฝ๋
JSP์ ๋ทฐ๋ฆฌ์กธ๋ฒ ์ค์ ์ ํด์ค๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# server port change
server.port=8000
# Datasource setting
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/boot?useSSL=false&serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=mysql
# JSP viewResolver config
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
|
JSP ํด๋์ ๊ตฌ์กฐ ๋ง๋ค๊ธฐ
๋ถํธ์์๋ JSP๋ฅผ ๊ถ์ฅํ์ง ์์์ ๋ฐ๋ก ํด๋๊ฐ ์กด์ฌํ์ง ์๋๋ค.
๊ทธ๋์ JSP๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ํด๋์ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์ด ์ฃผ์ด์ผํ๋ค.
์ปจํธ๋กค๋ฌ ์์ฑ
SampleController.java ์์ค์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.springboot.boot02.sample;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class SampleController {
@GetMapping("/hello")
public String hello(Model model) {
model.addAttribute("data", "์๋
~~");
return "hello";
}
}
|
MyBatis ์ฐ๋ํ๊ธฐ
1. ๋ง์ด๋ฐํฐ์ค DAO ์ธํฐํ์ด์ค ์์ฑ
2. ์ธํฐํ์ด์ค์์ ๋ฉ์๋ ์์ฑ
1
2
3
4
5
6
7
|
package com.springboot.boot02.repository;
public interface TimeDAO {
String getTime() throws Exception;
}
|
3. ๋งคํผ ์์ฑ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.springboot.boot02.repository.TimeDAO">
<select id="getTime" resultType="string">
select now()
</select>
</mapper>
|
4. ์ค์ ํ์ผ์์ ๋งคํผ์์น ์ง์
1
2
|
# Mapper location config
mybatis.mapper-locations=classpath:mappers/**/*Mapper.xml
|
ํ ์คํธํ๊ธฐ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package com.springboot.boot02;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.springboot.boot02.repository.TimeDAO;
import lombok.extern.java.Log;
@Log
@RunWith(SpringRunner.class)
@SpringBootTest
public class MybatisTest {
@Autowired
private TimeDAO dao;
@Test
public void testTime() throws Exception {
log.info("==========================================");
log.info("# ํ์ฌ์๊ฐ : " + dao.getTime());
}
}
|
์๋ฌ๊ฐ ๋๋ค;
์๋๋๊ฑฐใ ใ !!!!!!!!!!!!!11
1
2
3
4
5
6
7
|
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'com.springboot.boot02.MybatisTest':
Unsatisfied dependency expressed through field 'dao';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'com.springboot.boot02.repository.TimeDAO' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
|
๋ฐ์ํ
'(๊ตฌ)Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์คํ๋ง๋ถํธ] ํ์๋ฆฌํ ์๋์์ฑ ์ค์น (0) | 2019.07.16 |
---|---|
[์คํ๋ง๋ถํธ] ํ์๋ฆฌํ (thymeleaf) (0) | 2019.07.16 |
[์คํ๋ง๋ถํธ] ์คํ๋ง ๋ฐ์ดํฐ JPA (0) | 2019.07.13 |
[์คํ๋ง๋ถํธ]RestController (0) | 2019.07.10 |
[์คํ๋ง๋ถํธ] Spring Boot ์์ํ๊ธฐ (0) | 2019.07.09 |
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ์ดํด๋ฆฝ์ค ์ค์น
- java jdk ์ค์น
- Algorithm
- ์๊ณ ๋ฆฌ์ฆ
- mysql์ค์น
- ์จ๋ฆฌ์์ค
- ์๋ฐ
- ์๋ฃ๊ตฌ์กฐ
- ์ ์ฒด๊ฒ์๋ฌผ ์กฐํ
- Java
- typeAliases
- ๊ฒ์ํ ์กฐํ
- ๋ณ๋ช ์ฒ๋ฆฌ
- ๋ถํธ ์๋์์ฑ
- ์คํ๋ง๋ถํธ ์๋์์ฑ
- ๊ฒ์ํ ์ญ์
- ๊ฐ๋ฐํ๊ฒฝ๊ตฌ์ถ
- ์ดํด๋ฆฝ์ค ํ๊ธ ์ธ์ฝ๋ฉ
- tomcat์ค์น
- ๊ฒ์๋ฌผ ์ญ์
- ๊ฐ๋ฐ
- ๊ฒ์๋ฌผ์กฐํ
- java ํ๊ฒฝ๋ณ์
- ๊ฒ์ํ๋ง๋ค๊ธฐ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
๊ธ ๋ณด๊ดํจ