인생 디벨로퍼

[Bank App] 2강 모델링 본문

Project/개인 Project - Bank App

[Bank App] 2강 모델링

뫄뫙뫄 2023. 6. 9. 23:49
728x90

2강 모델링 (1)

DB 모델링

table.sql

CREATE TABLE user_tb(
id int auto_increment primary key,
username varchar unique not null,
password varchar not null,
fullname varchar not null,
created_at timestamp not null
);
CREATE TABLE account_tb(
id int auto_increment primary key,
number varchar unique not null,
password varchar not null,
balance bigint not null,
user_id int,
created_at timestamp not null
);
CREATE TABLE history_tb(
id int auto_increment primary key,
amount bigint not null,
w_balance bigint,
d_balance bigint,
w_account_id int,
d_account_id int,
created_at timestamp not null
);

테이블 설계

data.sql

INSERT INTO user_tb(username, password, fullname, created_at) values('ssar', '1234',
'쌀', now());
INSERT INTO user_tb(username, password, fullname, created_at) values('cos', '1234',
'코스', now());
INSERT INTO account_tb(number, password, balance, user_id, created_at)
values('1111', '1234', 1000, 1, now());
INSERT INTO account_tb(number, password, balance, user_id, created_at)
values('2222', '1234', 1000, 2, now());
INSERT INTO history_tb(amount, w_balance, d_balance, w_account_id, d_account_id,
created_at) values(100, 900, 1100, 1, 2, now());
INSERT INTO history_tb(amount, w_balance, d_balance, w_account_id, d_account_id,
created_at) values(100, 800, null, 1, null, now());
INSERT INTO history_tb(amount, w_balance, d_balance, w_account_id, d_account_id,
created_at) values(100, null, 900, null, 1, now());
commit;

더미데이터 추가


자바 모델링

User.java

import lombok.Setter;

@Setter
@Getter
public class User {

    private Integer id;
    private String username;
    private String password;
    private String fullname;
    private Timestamp createdAt;
}

Account.java

package shop.mtcoding.bankapp.model.user;

import java.sql.Timestamp;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Account {

    private Integer id;
    private String number;
    private String password;
    private Long balance;
    private Integer userId;
    private Timestamp createdAt;
}

History.java

package shop.mtcoding.bankapp.model.history;

import java.sql.Timestamp;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class History {
    private Integer id;
    private Long amount;
    private Long wBalance;
    private Long dBalance;
    private Integer wAccountId;
    private Integer dAccountId;
    private Timestamp createdAt;
}

UserRepository.java

package shop.mtcoding.bankapp.model.user;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserRepository {
    public int insert(User user);

    public int updateById(User user);

    public int deleteById(int id);

    public List<User> findAll();

    public User findById(int id);
}

AccountRepository.java

package shop.mtcoding.bankapp.model.accout;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface AccountRepository {
    public int insert(Account account);

    public int updateById(Account account);

    public int deleteById(int id);

    public List<Account> findAll();

    public Account findById(int id);
}

HistoryRepository.java

package shop.mtcoding.bankapp.model.history;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface HistoryRepository {
    public int insert(History history);

    public int updateById(History history);

    public int deleteById(int id);

    public List<History> findAll();

    public History findById(int id);
}

user.xml


http://mybatis.org/dtd/mybatis-3-mapper.dtd>">
            select * from user_tb
        
            select * from user_tb where id = #{id}
        
            select * from user_tb where username = #{username} and password = #{password}
        

        
            insert into user_tb (username, password, fullname, created_at) values(#{username}, #{password}, #{fullname}, now())
        

        
            delete from user_tb where id = #{id}
        

        
            update user_tb set username= #{username}, password= #{password}, fullname= #{fullname} where id = #{id}
        
    

history.xml


http://mybatis.org/dtd/mybatis-3-mapper.dtd>">
            select * from history_tb
        
            select * from history_tb where id = #{id}
        

        
            insert into history_tb(amount, w_balance, d_balance, w_account_id, d_account_id, created_at)
            values(#{amount}, #{wBalance},  #{dBalance},  #{wAccountId}, #{dAccountId}, now())
        

        
            delete from history_tb where id = #{id}
        
        
            update history_tb
            set amount= #{amount}, w_balance= #{wBalance}, d_balance= #{dBalance}, w_account_id = #{wAccountId}, d_account_id = #{dAccountId} where id = #{id}
        
    

account.xml


http://mybatis.org/dtd/mybatis-3-mapper.dtd>">
            select * from account_tb
        
            select * from account_tb where id = #{id}
        
        
            insert into account_tb (number, password, balance, user_id, created_at) values(#{number}, #{password}, #{balance}, #{userId}, now())
        
        
            delete from account_tb where id = #{id}
        
        
            update account_tb set number= #{number}, password= #{password}, balance= #{balance}, user_id= #{userId} where id = #{id}
        
    

서버 체크

tomcat 8080 이 나오는지 확인하자!


Tomcat

💡 스프링 애플리케이션 서버(Spring Application Server)
  • 웹 서버(Web Server) : 스프링 어플리케이션을 실행, 웹 서버와 스프링 어플리케이션을 함께 사용하여 동적인 웹 페이지를 생성하고 제공
  • 웹 컨테이너(Web Container) : 웹 컨테이너는 동적인 웹 페이지를 생성하기 위해 서블릿(Servlet)과 JSP(JavaServer Pages)를 실행하고, HTTP 요청을 처리하는 등의 역할을 담당
728x90