Spring(89)
-
[Spring] Error resolving template 문제 해결
- 문제 [THYMELEAF][http-nio-8080-exec-1] Exception processing template "/contents/createContentForm.html": Error resolving template [/contents/createContentForm.html], template might not exist or might not be accessible by any of the configured Template Resolvers - 원인 Mapping 메소드의 return을 "/url"로 해서 그렇다. 이 경우 절대경로로 인식한다. 예를 들어, 다음과 같다. @GetMapping("/new") public String createForm(Model model) { mo..
2023.12.24 -
[Spring] h2를 간단하게 메모리로 돌리기
다음과 같이 설정하면 된다. spring: datasource: # 메모리에서 돌리기: 시작 url: jdbc:h2:mem:testdb # 메모리에서 돌리기: 끝 username: sa password: driver-class-name: org.h2.Driver
2023.12.24 -
[Spring] @PathVariable에 대한 나름의 이해
@PathVariable은 request url에 들어있는 값을 변수로 가지고 오고 싶을때 사용한다. 예를 들어, 다음을 보자. @GetMapping("/download/{contentId}") public ResponseEntity downloadFile(@PathVariable("contentId") Long contentId) throws IOException { 내가 변수로 설정하고 싶은 부분을 request url에서 {name}으로 담는다. 그리고 메소드 파라미터에 @PathVariable("name") type variable을 넣어주면 name의 값을 variable에 값이 담겨 이를 사용할 수 있다.
2023.12.24 -
[Spring] 타임리프로 이미지 넣기
다음과 같이 src에 ${content.image}로 넣어야한다. 아래와 같이 자바코드를 사용해서 하면 안된다. 아마 타임리프 문법이 다르기 때문일 것이다. 또한 주의할 점은 image는 다음과 같이 String이어야 한다. byte[]이면 안된다. Base64.getEncoder().encodeToString(form.getImage().getBytes()); 그래서 한가지 우려되는게 Content Entity를 설계할 때 String으로 바꾸어야하는데 이게 맞는가 싶다. byte[]로 두는게 더 범용성이 크지 않을까 생각한다. 따라서 이 방법은 지금 생각으로는 좋지 못하다고 생각한다. Reference https://stackoverflow.com/questions/48235379/how-to-dis..
2023.12.24 -
[Spring] MVC 패턴에 대해
MVC 패턴은 Model, View, Controller로 역할을 분리한 패턴이다. Controller는 모든 요청을 처리한다. 그리고 서비스 로직을 호출한다. 또한 Model(서블릿에서는 HttpServletRequest에)에 저장한다. View는 Model에서 데이터를 꺼내서 표시한다. Model은 Controller와 View 사이를 매개한다. 이 MVC 패턴에도 forward 중복, viewpath 중복 등 공통 처리가 중복된다는 문제가 있다. 이를 해결하기 위해 공통 처리를 해주는 프론트 컨트롤러를 사용한다. 실제로 Spring MVC에서는 프론트 컨트롤러가 구현되어 있다. Reference https://www.inflearn.com/course/lecture?courseSlug=%EC%8A%..
2023.12.17 -
[Spring] Controller에 대한 나름의 이해
MVC 패턴에서 사용되는 Controller는 들어오는 모든 요청을 처리한다. Reference https://www.inflearn.com/course/lecture?courseSlug=%EC%8A%A4%ED%94%84%EB%A7%81-mvc-1&unitId=71186 학습 페이지 www.inflearn.com
2023.12.17