냥코딩쟝

spring boot롤 구성요소를 pick해 generate해줬다.

-lombok 설치

-테스트코드 실행
:생성된 스프링부트 프로젝트의 경우 이미 테스트 환경이 갖춰져 있다

package org.zerock.ex2;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Ex2ApplicationTests {

    @Test
    void contextLoads() {
    }

}

controller

package org.zerock.ex1.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController{

    @GetMapping("/hello")
    public String[] hello(){
            return new String[]{"Hello","World"};
    }
}
plugins {
    id 'org.springframework.boot' version '2.7.4'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'java'
    id 'war'
}

group = 'org.zerock'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}
plugins {
    id 'org.springframework.boot' version '2.7.4'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'java'
    id 'war'
}

group = 'org.zerock'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

-스프링부트를 단독으로 실행 가능한 파일로 만들기

bulid항목->bootjar파일생성
cmd환경을 이용해서 해당폴더에서 java -jar ex1-0.01-SNAPSHOT.jar 를 실행

실행후 Intellij에서 보던 로그와 동일한 결과가 나오는 것을 볼 수 있다.

db설치

mysql을 다운받아서 연동할려고 했지만,,, ㅜㅜ

비밀번호를 까먹은 바람에.. maria db와 mysql을 재설치 해줬다..

C:\Users\LG>mysql -v
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

C:\Users\LG>mysql -u root -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE opentutorials CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.17 sec)

mysql> USE opentutorials;
Database changed
mysql> SHOW opentutorials;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'opentutorials' at line 1
mysql> CREATE TABLE `TB_MEMBER` (
    ->
    ->     `mem_num` int(11) NOT NULL AUTO_INCREMENT,
    ->
    ->     `mem_name` varchar(20) NOT NULL,
    ->
    ->     `gender` varchar(5),
    ->
    ->     `age` varchar(5),
    ->
    ->     `mem_ph` varchar(20),
    ->
    ->     `addr` varchar(100),
    ->
    ->     `join_date` datetime,
    ->
    ->     `mem_birth` datetime,
    ->
    ->     PRIMARY KEY(mem_num)
    ->
    ->     ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected, 2 warnings (0.24 sec)

mysql>
mysql>
mysql> show tables;
+-------------------------+
| Tables_in_opentutorials |
+-------------------------+
| tb_member               |
+-------------------------+
1 row in set (0.07 sec)

mysql> INSERT INTO `TB_MEMBER` (mem_name, gender, age, mem_ph, addr, join_date, mem_birth)
    ->
    -> VALUES ('JIHYO', 'F', '22', '010-1234-1234', 'GangNam, Seoul', '2019-9-19 9:58', '1996-12-12 0:0');
Query OK, 1 row affected (0.04
``` sec)

C:\Program Files\MariaDB 10.11\bin>mysql -u root -p
Enter password: ****
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.11.0-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

marina db 까지 접속완료

profile

냥코딩쟝

@yejang

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!