Initial commit: SB 백엔드 (Spring Boot + MyBatis)

- 사용자 CRUD REST API (/api/users)
- MariaDB(MyBatis) + Redis 캐싱 구성
- CORS 설정 및 헬스 체크 엔드포인트

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@
This commit is contained in:
ByungCheol
2026-05-30 21:18:35 +09:00
commit 9243a41385
20 changed files with 827 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
server:
port: 8080
servlet:
context-path: /
spring:
application:
name: sb_bt
# ===== MariaDB =====
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/sb_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul
username: sb_user
password: sb_pass
hikari:
maximum-pool-size: 10
minimum-idle: 2
connection-timeout: 30000
pool-name: sbHikariPool
# ===== Redis =====
data:
redis:
host: localhost
port: 6379
password:
database: 0
timeout: 3000ms
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
# ===== MyBatis =====
mybatis:
type-aliases-package: com.example.sb_bt.domain
mapper-locations: classpath:mapper/**/*.xml
configuration:
map-underscore-to-camel-case: true
jdbc-type-for-null: 'NULL'
default-fetch-size: 100
default-statement-timeout: 30
# ===== Logging =====
logging:
level:
root: INFO
com.example.sb_bt: DEBUG
com.example.sb_bt.mapper: DEBUG
+34
View File
@@ -0,0 +1,34 @@
-- ============================================================
-- sb_bt 초기 스키마 / 시드 데이터 (MariaDB)
-- 사용법:
-- 1) MariaDB 접속 후 아래 DB/계정 생성 (관리자 권한)
-- 2) sb_db 선택 후 users 테이블 생성 및 시드 입력
-- ============================================================
-- 데이터베이스 및 계정 (최초 1회, root 등 관리자로 실행)
CREATE DATABASE IF NOT EXISTS sb_db
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS 'sb_user'@'%' IDENTIFIED BY 'sb_pass';
GRANT ALL PRIVILEGES ON sb_db.* TO 'sb_user'@'%';
FLUSH PRIVILEGES;
USE sb_db;
-- 샘플 테이블
CREATE TABLE IF NOT EXISTS users (
id BIGINT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uk_users_email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 시드 데이터
INSERT INTO users (name, email) VALUES
('홍길동', 'hong@example.com'),
('김철수', 'kim@example.com'),
('이영희', 'lee@example.com')
ON DUPLICATE KEY UPDATE name = VALUES(name);
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.sb_bt.mapper.UserMapper">
<resultMap id="userResultMap" type="User">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="email" column="email"/>
<result property="createdAt" column="created_at"/>
</resultMap>
<select id="findAll" resultMap="userResultMap">
SELECT id, name, email, created_at
FROM users
ORDER BY id DESC
</select>
<select id="findById" parameterType="long" resultMap="userResultMap">
SELECT id, name, email, created_at
FROM users
WHERE id = #{id}
</select>
<insert id="insert" parameterType="User" useGeneratedKeys="true" keyProperty="id">
INSERT INTO users (name, email, created_at)
VALUES (#{name}, #{email}, NOW())
</insert>
<update id="update" parameterType="User">
UPDATE users
SET name = #{name},
email = #{email}
WHERE id = #{id}
</update>
<delete id="delete" parameterType="long">
DELETE FROM users
WHERE id = #{id}
</delete>
</mapper>