냥코딩쟝

스프링 부트 라이브러리
thymeleaf
web

gradle,maven은 의존관계를 관리해준다.

external library ->웹애플리케이션을 만들기 위한것들..

core까지 당겨온다

라이브러리...

springboot starter login 라이브러리가 있다.

ch.oqos.logback, org.sif4
-> 많이 씀

test - java진영에서는 juint 5버전을 많이 씀

assert -test를 하기 편하게 만들어줌

test -spring 과 통하면서 test할 수 있도록 도와줌

boot core sif4j

테스트 라이브러리
juint mockito assertj spring-test

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/

-reference 문서

index html -> tempelet을 찾는다

템플릿 관리 thymeleaf
package hello.hellospring.controller;

import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HelloController {

-hello spring application

    @GetMapping("hello")
    public String hello(Model model) {
        model.addAttribute(attributeName: "data", attributeValue:"hello!!");
        return "hello";//index.html 와 연결
    }

    }
<!DOCTYPE HTML> <html>
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head>
<body> Hello
<p th:text="안녕하세요. ' + ${data}">안녕하세요. 손님 </p>
<!-- <a href="/hello">hello</a> </body>-->
</html>

빌드하고 실행하기

콘솔로이동

  1. ./gradlew bat
  2. cd build/libs
  3. java -jar hello-spring-0.0.1-SNAPSHOT.jar

-> 배포파일
4. 실행확인

폴더목록확인ls dir
윈도우에서 Git bash 터미널사용하기
링크: https://www.inflearn.com/questions/53961

내장 톰캣서버 ->hello-staic 관련 컨트롤러
resource :static /hello-static.html

MVC와 템플릿 엔진(

MVC

controller

@Controller
public class HelloController {
@GetMapping("hello-string") @ResponseBody
public String helloString(@RequestParam("name") String name) {
return "hello " + name; }
}

정적 contents
spring boot는 정적컨텐츠 기능을 자동으로 제공한다.

-static contents 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"   />
    <title>static content</title>
</head>
<body>
정적 컨텐츠 입니다
</body>
</html>

정적켄텐츠입니다가 그대로 들어오게 된다.

ㅡMVC 템플릿 엔진

바탕이 되는 내용* local host -> controller가 우선순위를 가진다
->hello-staic.html

package hello.hellospring.controller;

import org.springframework.web.bind.annotation.GetMapping;

public class HelloController {

    @GetMapping("hello")
    public String hello(Model model) {
        model.addAttribute(attributeName: "data", attributeValue:"hello!!");
        return "hello";//index.html 와 연결
    }

    }

'view - resources/temlate/hello-template.html

<html xmlns:th="http://www.thymeleaf.org">
  <body>
<p th:text="'hello ' + ${name}">hello! empty</p> 
  </body>
  </html>

-API
@Response Body

참고 -김영한님 강의

profile

냥코딩쟝

@yejang

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!