newlife 프로젝트 시작에서 VO 만들기까지

2021. 10. 21. 19:15카테고리 없음

일단 maven이란?

https://goddaehee.tistory.com/199

 

[Maven] Maven 이란? (정의, 예제)

[Maven] 메이븐 이란? (정의, 예제) 안녕하세요. 갓대희 입니다. 이번 포스팅은 [ 메이븐 알아보기 ] 입니다. : ) 1. 빌드 (Build) #1 빌드란?  - 소스코드 파일을 컴퓨터에서 실행할 수 있는 독립

goddaehee.tistory.com


 

1. 이유없이 프로젝트명에 x가 뜬다면... show view에서 problems 꼭 켜서..console 탭 옆에 두고 찾아보자..

그럼.. 이유를 다 알려준다... 이걸 이제야 알다니..


2. maven update시 발생했던 에러..

https://jokerkwu.tistory.com/109

 

[ 에러 처리 ] Eclipse에서 Tomcat 실행시 발생 [ Maven 사용시 ][org.springframework.web.context.ContextLoaderListene

실행 잘되던 프로젝트에 maven - update project... 를 클릭후 정상적으로 실행이 안되서 찾아보니 프로젝트 우클릭 - Maven - Update Project 실행시 maven 라이브러리 경로가 삭제되는 현상이 발생한다고 한

jokerkwu.tistory.com


3. 이거..

https://m.blog.naver.com/ajdkfl6445/221549536647

 

[SPRING] dynamic web module 4.0 requires java 1.8 or newer 해결 방법

안녕하세요 개발자 마스터정(Master Jung)입니다. 오늘은 dynamic web module 4.0 requires java 1.8 or ...

blog.naver.com


4. 와... 이제 git에 올려볼까하다가...ㅋㅋㅋㅋ.. 리모트 위치가 얽히고 걍 system explorer에서 플젝 옮기다가(등신..)

다 섞임 ㅋㅋㅋㅋ 그래서 원격 브랜치 삭제하고서 pull하는데 pull을 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ병합말고 미는걸로 해가지고...

지금..플젝...새로 만들어야 한다~~ 와...

 

만들고 돌아왔다.. 놀랍게도 이미 다 해본 실수라 그런지 10분도 안걸려서 성공..


5. 그리고 나서.. 이미 만들었던 원격 commit했던 브랜치랑 local브랜치랑 병합이 안되서 아래 블로그 보고 해결

https://gdtbgl93.tistory.com/63

 

Git push가 안되는 경우 (fatal: refusing to merge unrelated histories)

로컬 저장소에 있는 프로젝트를 깃허브 사이트를 통해 만든 저장소로 push 하는 경우에 이런 메세지가 뜨는 경우가 있다. 1 2 3 4 5 6 7 8 C:\Users\gitProject>git push origin master To https://github.co..

gdtbgl93.tistory.com

patch.diff 파일이 생겼고.. 차이에 대한 기록파일인건 대강 알겠지만 파일을 지워도 되는지 어쩐지는 모르겠어서 일단 두고 다음으로 넘어간다..


6. 뭔가 큰 실수를 했을 때 되돌릴 방도가 없어서.. 혼자니깐 그냥 branch를 master하나로 해야지 하다가..

어제 날리고서, dev_lovari 브랜치를 새로 만들었다..... 웬만하면 lovari로 작업하고.. 확정되었을때 master로 가야겠다..


7. https://to-dy.tistory.com/15

 

스프링(Spring) 설정 - 프로젝트 구조 변경 및 설정

스프링 MVC 프로젝트를 생성한 기본 구조를 그대로 써도 상관없다. 다만 구조를 바꾼다면 web.xml의 경로만 잘 설정해주면 아무 문제없이 잘 돌아간다. 구성을 바꾸는 이유는 아직은 잘 모르겠다. 

to-dy.tistory.com

https://wikidocs.net/book/5792

 

스프링 MVC 하루만에 배우기

이 시리즈는 책으로 출간된 [스프링 MVC 하루만에 배우기](http://www.yes24.com/Product/Goods/96581707) 를 다룹니다. ![스프링 ...

wikidocs.net

이 두 곳을 보고 폴더 구조를 변경하고 초기 설정을 했다.


8. classpath: 에 대한 의문이 생겨서 아래 참고.

https://developer-joe.tistory.com/225

 

Spring의 classpath:의 경로 위치

아래 Spring web.xml의 ContextLoaderListener의 환경설정 파일인 applicationContext.xml의 위치를 지정하는 코드에서 classpath:의 위치가 어디인가? contextConfigLocation classpath:applicationCon..

developer-joe.tistory.com

https://pplenty.tistory.com/5

 

[Spring] classpath: vs classpath*:

spring classpath: vs classpath*: 이슈 Invalid bound statement (not found) 웹 어플리케이션을 리팩토링하고, 모듈 별로 분리하는 작업을 하는 과정에서 mapperLocations 에 설정된 mapper xml 을 읽지 못하고..

pplenty.tistory.com

classpath: 대신에 classpath*:를 써야 전부 가져온다.. 아직은 이렇게밖에 모르겠구만..


9. 이번엔 MySQL을 써보려고, new connection을 만드려는데 자꾸 access denied가 떠서 구글링 끝에 찾아냈다..

내가 새롭게 만들 connection의 user도 새로 만들었는데 걔한테 권한이 없어서 그랬던것.. 

workbench에서 이미 만들었던 connection에 들어가, privilege 설정에서 add user한 다음 dba role을 주었다.

그리고나서 다시 new connection만들기를 시도했더니 바로 성공~~


10. 스키마 생성하면서 characterset 설정하는데 이모지 때문에 utf8mb4쓴대서 참고함

https://nakanara.tistory.com/230

 

[MariaDB] 문자셋 변경 utf8 -> utf8mb4

MariaDB의 문자셋을 UTF8로 설정해두고 사용하고 있었는데 SQL이 오류가 발생했다. 로그를 봐도 깨진 문자열만 보이고 해당 문제가 무슨 글자인지 몰랐다. 인코딩이 맞지 않아서 깨진 것처럼 보이는

nakanara.tistory.com

my.ini, my.conf가 다 없어서 workbench 설정에서 찾았더니 파일이 없다고 만들어준단다~

그래서 만들어서 위 블로그가 가르쳐주는대로 handshake 어쩌구도 설정했다.

역시 GUI가 짱이다.. 체크박스라서 짱쉽게 해결.

DB서버와 접속을 할 때 클아이언트는 자신이 사용할 문자셋 설정하며, 그 설정을 사용하도록 되어있지만 skip-character-set-client-handshake 옵션을 사용할 경우 클라이언트에서 설정한 문자셋을 무시하고 character_set_server값으로 설정됩니다.

이름 참 잘 지은듯.. 클라이언트 캐릭터셋을 무시하니깐 악수한다는거 하하하


11. DB 모델링을 시작한다~

개념은 '오용철의 데이터베이스 모델링' ppt를 참고하고, MySQL을 쓰기로 했기 때문에 전체적인 naming 관련해서

https://www.sqlstyle.guide/

 

SQL style guide by Simon Holywell

A consistent code style guide for SQL to ensure legible and maintainable projects

www.sqlstyle.guide

여기를 쭉 읽어보고 참고했다.

항상 naming이 중요하고.. convention(관습) 따라서, 내맘대로 하지 않는게 중요한 것 같다.

왜냐면.. 내맘대로 막 만들면 유지보수가 어려우니까.. 내가 만든 개인 프로젝트여도 언젠가 다른 사람과 같이 협업하게 될수도 있으니깐...

 

👀 아래는 중요한거 몇개..👀


Columns (컬럼 네이밍)
  • Always use the singular name. 
  • Where possible avoid simply using id as the primary identifier for the table. 
  • Do not add a column with the same name as its table and vice versa.
    • 해당 테이블하고 똑같은 이름의 컬럼 만들지 말자.. 반대도 해당..
  • Always use lowercase except where it may make sense not to such as proper nouns.
    • 고유명사(proper noun) 말고는 항상 소문자 써라..

Uniform suffixes (정형화된 접미사들 네이밍 규칙)

The following suffixes have a universal meaning ensuring the columns can be read and understood easily from SQL code. Use the correct suffix where appropriate.

  • _status —flag value or some other status of any type such as publication_status.
    •  이거는 0, 1, 2 등으로 미리 정해둔 상태를 표시하는 것..
    •  예를 들어.. 0은 탈퇴, 1은 가입, 2는 휴면, 뭐 이런 식으로 
  • _total —the total or sum of a collection of values.
  • _num —denotes the field contains any kind of number.
  • _name —signifies a name such as first_name.
  • _seq —contains a contiguous sequence of values. (번호 매길때...for sequence)
  • _date —denotes a column that contains the date of something. (for date)
  • _tally —a count. (방문자 수 카운트 같은거 할때 count 대신 tally)
  • _size —the size of something such as a file size or clothing. 
  • _addr —an address for the record could be physical or intangible such as ip_addr. (주소)

위 링크 글의 github comments에서 참고할만한 것을 복사해왔다. boolean을 위한 규칙 있음

Below are some additional uniform-suffixes for consideration:
  • _dtime —denotes a column that contains the DATETIME for something.
  • _dtime_utc —denotes a column that contains the DATETIME in the UTC timezone.
  • _time —denotes a column that contains the TIME for something.
  • is_ —a boolean column (this is a prefix).
  • can_ —a boolean column (this is a prefix).
  • has_ —a boolean column (this is a prefix).

12.  위 글의 중요한 부분을 다 읽고 드디어 만들어볼까 하는데 primary key랑 foreign key 네이밍을 대체 어떻게 할지 모르겠어서.. 검색해봤다.. 

 

https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html#foreign-key-examples

 

MySQL :: MySQL 8.0 Reference Manual :: 13.1.20.5 FOREIGN KEY Constraints

13.1.20.5 FOREIGN KEY Constraints MySQL supports foreign keys, which permit cross-referencing related data across tables, and foreign key constraints, which help keep the related data consistent. A foreign key relationship involves a parent table that hol

dev.mysql.com

그런데 이렇게 MySQL 공식문서에서 ㅠㅠ... 예시를.. 위의 style guide 작성자랑 상반되게 들어서 ㅠㅠ 

나는 결국 대기업을 따르기로 했다...

/*Foreign Key Constraint Examples
This simple example relates parent and child tables through a single-column foreign key:*/

CREATE TABLE parent (
    id INT NOT NULL,
    PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE child (
    id INT,
    parent_id INT,
    INDEX par_ind (parent_id),
    FOREIGN KEY (parent_id)
        REFERENCES parent(id)
        ON DELETE CASCADE
) ENGINE=INNODB;
/* This is a more complex example in which a product_order table has foreign keys for two other tables. 
	One foreign key references a two-column index in the product table. 
	The other references a single-column index in the customer table: */

CREATE TABLE product (
    category INT NOT NULL, id INT NOT NULL,
    price DECIMAL,
    PRIMARY KEY(category, id)
)   ENGINE=INNODB;

CREATE TABLE customer (
    id INT NOT NULL,
    PRIMARY KEY (id)
)   ENGINE=INNODB;

CREATE TABLE product_order (
    no INT NOT NULL AUTO_INCREMENT,
    product_category INT NOT NULL,
    product_id INT NOT NULL,
    customer_id INT NOT NULL,

    PRIMARY KEY(no),
    INDEX (product_category, product_id),
    INDEX (customer_id),

    FOREIGN KEY (product_category, product_id)
      REFERENCES product(category, id)
      ON UPDATE CASCADE ON DELETE RESTRICT,

    FOREIGN KEY (customer_id)
      REFERENCES customer(id)
)   ENGINE=INNODB;

이렇게 두가지 예시가 있다.. 

결국...

primary key는 그냥 id로..
foreign key는 참조하는테이블이름_id 로 지어야 겠다

정말 허무하군... 이럴거면 그냥 okky의 erdcloud 보고서 바로 참고하는게 나았을듯하다 ㅠㅠ 그래도 배운게 있으니까...


13. 데이터베이스 모델링은 정말..어렵구나..

아직도 고민중이다.. 

https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_db&wr_id=199478#c_199478 

 

WWW.PHPSCHOOL.COM

개발자 커뮤니티 1위 PHPSCHOOL.COM 입니다.

www.phpschool.com

테이블 구조 때문에 검색하다가, 게시판에 따라 테이블을 나눌지, 하나의 테이블에 모든 게시판 글을 다 저장할 지에 대한 글을 보았다.. 사실 아직도 고민인데.. 요즘은 하나의 테이블로 한다고들 하고.. 나는 새 글이 매우 드물게 올라오는 교회 사이트를 만들거고.. 우리 교회는 규모가 작기 때문에 하나의 테이블로 결정했다..

결정했는데도 고민되네 ㅠㅠ 

지난번에 만들었던 보드게임 커뮤니티 사이트는 게시판마다 테이블이 하나씩 있었기 때문에 erd도 복잡했고, 결국 procedure 기능까지 스스로 배워서 anonymous block과 mybatis를 결합시켜서 수정 기능을 만들어야 했다...

물론 더 좋은 방법들이 있었겠지만 부족한 시간과 능력으로는 그정도가 최선이었지..

갑자기 과거 회상..하하하


14. 검색하다가 이런 글을 읽었다: Lombok 사용할까 말까

https://medium.com/geekculture/good-and-bad-usage-of-lombok-8c8f70874a93

 

Good and Bad usage of Lombok

A Fool with a tool is still a fool

medium.com

쭉 읽어봤는데 결론은 그거다.. 필자는 Lombok을 좋아하고.. 쓰는걸 추천하되 이러저러한 문제가 일어날 수 있으므로

@Getter 와 @Setter 어노테이션을 쓰라는 것..

잘 모르고 쓰는게 문제라는 것.. 그리고 I really discourage using any Lombok annotation that modifies the code. 한다고 한다.. 개발자가 핵심 로직으로 작성한 코드를 수정할만한 Lombok annotation은 쓰지말라는거..

again.... @Getter 와 @Setter 어노테이션을 쓰라는 것.. 그렇다~~

 

그렇지만 stackoverflow에서 많은 사람들이 조심하라고 했기 때문에.. 미래를 고려해서 안쓰기로 했다.


15. MySQL에 테이블을 드디어 만들었다...필수적인 테이블 6개만 만드는데도 정말 오래걸렸구나 ㅠㅠ

역시 디비 모델링은 오래걸린다.. 

erdcloud... 다신 안쓸거 같다...진짜 구려.. 왜 사람들이 안쓰는지 알겠다.. 담엔 돈을 내더라도

AQueryTool - AQuery.Web 여기서 할듯.... 저기가 무료일때 썼어야 했는데.. 

https://developer-jeongyeon.tistory.com/m/23

 

MySQL: primary key, foreign key 추가 및 삭제, constraint추가 방법.

1. key의 정의. pk는 DB 디자이너에 의해 선택 된 candidate key를 뜻한다. 그럼 candidate key는 뭘까? key는 하나의 tuple을 다른 tuple로부터 구별하는 방법이다. 예를 들어 학생의 학번이나 이메일 주소는 고

developer-jeongyeon.tistory.com

foreign key 연결은 여기 참고했다.

oracle DB로 작업했다가 MySQL로 하려니까 정말...사소하게 다른게 너무 많아서 힘들다 ㅠㅠ

oracle이....역시....짱이긴하다...

 

https://tychejin.tistory.com/19?category=765216 : MySQL 연동 참고

 

[Spring] 게시판 만들기(9) - MySQL 연동

 지난 포스팅에서 로컬에 설치한 MySQL을 자바에서 접근할 수 있도록 JDBC(Java DataBase Connectivity)와 MySQL을 연동하는 작업을 진행하도록 하겠습니다. 1. POM.xml에 의존성 추가  POM.xml에 MySQL과 관련..

tychejin.tistory.com


16. vo(value object)들을 만들려는데, 이번에 새로 만든 테이블들은 record가 그렇게 많이 있을것같지 않지만.. 또 미래를 생각해서 id의 데이터타입을 주로 int unsigned로 했다. 이에 매칭되는 java 데이터 타입에 관해 찾아봤다.

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

역시 공식문서가 믿을만하고 최고지만.. 찾기 힘들게 되어있어서 좀 불편하다...


결론은 int unsigned를 쓰고 싶으면 java에선 long을 쓰자!

tinyint(1)을 쓸거고 tinyInt1isBit 프로퍼티가 true로 설정되어있으면(디폴트) Boolean으로 하자~~

MySQL Type Name Return value of GetColumnTypeName Return value of GetColumnClassName
INT,INTEGER[(M)] [UNSIGNED] INTEGER [UNSIGNED] java.lang.Integer, if UNSIGNED java.lang.Long
TINYINT TINYINT java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.

17. 위의 데이터 타입을 참고해서 VO class를 전부 만들었다... 힘들군..