2021-03-03-TIL

staic에서 templates로 경로 이동하면 static으로 <link>안의 내용이 자동으로 리팩토링 된다. 하지만 이렇게 되면 css를 정상적으로 불러오지 못한다. 따라서 리팩토링 설정을 해제하고 그냥 이동시켜야 한다. 이미 옮겼다면 ../static 이 부분을 모두 ../로 다시 변경해주어야 한다.

만약에 templates에 user 폴더를 추가하면 ../을 하나 더 추가해 주어야한다.

$ git remote -v                                    
origin  https://github.com/Polynomeer/spring-boot-qna.git (fetch)
origin  https://github.com/Polynomeer/spring-boot-qna.git (push)
$ git remote add -t Polynomeer upstream https://github.com/codesquad-members-2021/spring-boot-qna.git
$ git remote -v                                      
origin  https://github.com/Polynomeer/spring-boot-qna.git (fetch)
origin  https://github.com/Polynomeer/spring-boot-qna.git (push)
upstream        https://github.com/codesquad-members-2021/spring-boot-qna.git (fetch)
upstream        https://github.com/codesquad-members-2021/spring-boot-qna.git (push)
$ heroku git:remote -a august-qna                   
set git remote heroku to https://git.heroku.com/august-qna.git
$ git remote -v                                      
heroku  https://git.heroku.com/august-qna.git (fetch)
heroku  https://git.heroku.com/august-qna.git (push)
origin  https://github.com/Polynomeer/spring-boot-qna.git (fetch)
origin  https://github.com/Polynomeer/spring-boot-qna.git (push)
upstream        https://github.com/codesquad-members-2021/spring-boot-qna.git (fetch)
upstream        https://github.com/codesquad-members-2021/spring-boot-qna.git (push)
$ git push heroku feature/user:master
...
remote:        https://august-qna.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/august-qna.git
 * [new branch]      feature/user -> master

Heroku에서는 Git을 내장하고 있어서 push 명령어 만으로도 GitHub와 유사하게 사용할 수 있으며, git push heroku {source branch name in local}:{target branch name in Heroku}로 로컬에 있는 브랜치를 그대로 업로드 할 수 있으며, Heroku서버에서는 자동으로 빌드 및 서버 가동을 해준다. 마지막 로그에 나오는 해당 링크(https://august-qna.herokuapp.com)에 접속해보면 서버에 배포가 잘 되었다는 것을 확인할 수 있다.

User의 private 필드를 가져오지 못하는 현상

handlebars는 mustache의 수퍼셋이므로 mustache 문법은 모두 사용가능하다. 자바 빈의 멤버 필드는 Getters를 추가해주어야 handlebars에서 가져올 수 있다.

@PathVariable

https://www.baeldung.com/spring-pathvariable

View Resolver

handlebars.suffix=.html
handlebars.cache=false

.html 파일을 view 파일로 감지하기 위해서 설정

삽질은 적당히하고 삽 날이 무뎌졌다면 갈아끼워줄 필요가있다.

[August]

  • 자바 소스코드는 패키지를 생성해서 비슷한 역할끼리 묶어서 진행해도 좋을 것 같다. 예를 들면, controller, config 등 네이밍은 다른 프로젝트나 다른 사람의 코드를 참고.

[Shion]

  • <link> 에서 경로를 상대경로 보다는 절대경로로 지정하는 것이 편할 것 같다. 예를 들면, 현재 templates/list.html을 templates/user/list.html로 이동하면 또 다시 참고 경로를 ../../css 이런식으로 변경해야 하는데, 절대경로로 지정하면 바꾸지 않아도 된다. -> 그런데 이 부분은 상대경로가 나중에는 더 안정적일 수도 있는데, 한번 고민해보시길 바랍니다.

[cooper]

  • url상에서 상위 경로의 중복된 부분을 @RequestMappinig("users")으로 빼면 GetMapping/PostMapping에서 url중복을 줄일 수 있다.

[K]

  • templates에서 반복되는 부분을 따로 빼내어 중복을 제거할 수 있는데, 여기서 한 걸음 더 나아가서 반복되는 코드를 포함하는 전체적인 구조에 대한 템플릿(틀)을 미리 만들어 두고 해당 코드만 수정하도록 할 수 있다. http://jknack.github.io/handlebars.java/reuse.html
  • (K의 코드 참고) MvcConfig에서 컨트롤러 우선순위를 높여주어서 users/form을 갔을때 form이라는 userId로 접근 시도하지 않게된다. 핸들러 맵핑이 우선순위를 내부적으로 정해주어야지 우선순위를 지정할 수 있다. 하지만 users/form, users/login에서 만약에 form이나 login이라는 이름으로 계정을 생성하고 싶다면?… 안된다. 사실은 좀 잘못된 설계인 것 같다.
  • Handlebars 템플릿 엔진에서 @HandlebarsHalper를 통해 helper를 직접 작성해서 사용할 수 있는데, 날짜 포맷을 맞춰주려고 직접 작성해보았다.

[Sky]

  • 앞으로 static에서 사용하지 않을 html 파일들은 templates로 이동하면 좋을 것 같다.
Tip

dependencies 에서 compile은 사용하지 않는것이 좋다고 한다.인텔리제이에서 shift를 두 번 누르면 도구 전체 검색이 가능하다.인텔리제이 live-reload : https://oewoew.tistory.com/98

알고리즘

https://www.geeksforgeeks.org/print-all-permutations-with-repetition-of-characters/