본문 바로가기
반응형
SMALL

SpringBoot/웹 애플리케이션 개발3

정적 리소스 처리 스프링 부트의 정적 리소스 기본 구조스프링 부트는 resources/static 디렉토리 하위의 파일들을 자동으로 정적 리소스로 인식합니다.특별한 설정 없이 아래 위치에 파일을 넣기만 하면 URL로 바로 접근할 수 있어요.src/└── main/ └── resources/ ├── static/ ← 정적 리소스 위치 │ ├── css/ │ ├── js/ │ ├── images/ │ └── favicon.ico └── templates/ ← HTML 템플릿 (Thymeleaf 등)예시 - URL 매핑 파일 경로 접근 URL static/css/style.css/css/style.cssstatic.. 2025. 4. 14.
템플릿 엔진(Thymeleaf) 연동 Thymeleaf란?Thymeleaf는 HTML 파일에 서버 데이터를 바인딩하여 동적으로 화면을 구성할 수 있게 해주는 템플릿 엔진입니다. 특징 설명 HTML 문법을 그대로 유지브라우저에서 템플릿 자체 미리보기 가능서버-사이드 렌더링@Controller와 함께 HTML 응답Spring과 높은 호환성spring-boot-starter-thymeleaf 제공1. 의존성 추가build.gradle 예시dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web'}spring-boot-star.. 2025. 4. 14.
컨트롤러(@RestController, @Controller) Controller란?스프링 MVC에서 Controller는 사용자의 요청(Request)을 받아 처리하고, 적절한 응답(Response)을 돌려주는 역할을 합니다. MVC 구조에서 **"C(Controller)"**에 해당하죠.@Controller특징HTML 뷰(View)를 반환할 때 사용주로 Thymeleaf, JSP 등 템플릿 엔진과 함께 사용반환 값은 뷰 이름이며, 템플릿에서 해당 파일을 찾아 렌더링함예시@Controllerpublic class HelloController { @GetMapping("/hello") public String hello(Model model) { model.addAttribute("name", "단비"); return "hello.. 2025. 4. 14.
LIST