environment: #springboot #maven #oracle #eclipse(sts) #java
File-New-Other-Spring Starter Project
Name: API, Type: Maven, Packaging: Jar, Java Version: 8, Language: Java, Group: com.api, Package: com.api
Dependency(의존성): JDBC API, Oracle Driver, Spring Web
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<!--<version>1.3.2.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
package com.db.Controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping(value="/test")
public Map<String,Object> test() {
Map<String,Object> result = new HashMap<String,Object>();
result.put("name", "happy");
result.put("age", 10);
return result;
}
}
@RestController
, @RequestMapping
: ctrl+space, enter
HashMap
: ctrl+shift+o
2. 실행
3. localhost:8080/test 접속
create table test(
id int primary key,
name varchar(20),
email varchar(20)
);
insert into test(id, name, email)
values(1,'happy','happy@smile.com');
select * from test;
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/orcl
spring.datasource.username=system
spring.datasource.password=1234
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
api/controller/TestController
, api/dao/TestDao
, api/service/TestService