AI교육과정 - Spring.8

단비·2022년 12월 14일
0

AI교육과정

목록 보기
47/69
  • @RequiredArgsConstructor
    • 빈 생성자 외 필요한 생성자를 만들어줌 (NoArgs~, AllArgs 안써도됨)
  • @Autowired(required = false)
    • 빈 타입을 못찾거나 의존성 주입을 할 수 없는 경우 null 에러가 발생, optional로 설정해줌
  • 사이트의 json 데이터 정리
    • private LocalDateTime transactionTime
      • LocalDateTime이 변경됐는지 ex) transactionTime(LocalDateTime.now()) “transaction_time”: “2022-12-14”
    • private String resultCode
      • 정상적으로 호출을 했는지 String 값을 넣어줌 ex) “resultCode”: “ok”
    • private T data
      • response 데이터를 담아줄 객체 ex) data { “userid”: “apple”, “userpw”: “1234” }
    • private String description
      • error에 대한 설명 ex) “description”: “정상”

  • getData
    • request의 모든 값을 가져옴

      UserApiRequest userApiRequest = request.getData()
    • request 파일엔 유저에게 받을 값

    • response 파일엔 DB에 저장할 값

  • 템플릿 엔진(Template Engine)
    • 지정된 템플릿 양식과 데이터가 합쳐져서 html 문서를 출력하는 소프트웨어
    • 서버 템플릿 엔진
      • velocity: 과거 스프링에서 많이 사용하던 엔진 (현재 권장하지 않음)
      • freemaker: 템플릿 엔진으로 많은 기능을 지원
        • Apatch 템플릿 엔진으로, 템플릿 및 변경 데이터를 기반으로 텍스트, 메일, 파일 등을 생성하는 Java 라이브러리를 제공
      • timeleaf: 스프링 부트에서 적극 지원하고 있는 엔진, 문법이 쉽지 않음
        • react, vue의 경험이 있다면 최적의 템플릿 엔진
      • mustache: 문법이 다른 템플릿 엔진보다 쉬움. 비즈니스 로직을 사용할 수 없음. View의 역할과 서버의 역할이 명확하게 구분됨

  • resource
    • static: css, js, image 파일
    • templates: html 파일
  • java에서 html 불러오는 법
    • ModelAndView: html을 불러올 수 있음

    • HttpServletRequest: session 쓸 때 필요

      @Controller
      @RequestMapping("pages") //http://localhost:8888/pages
      public class PageController {
          @RequestMapping(path="/cafe") //http://localhost:8888/pages/cafe
          public ModelAndView cafe(){
              return new ModelAndView("/cafe_index.html");
          }
      }
  • thymeleaf
    • 사용 시 doctype 위에 하기 코드 붙여넣기
      <html lang="ko"
            xmlns="http://www.w3.org/1999/xhtml"
            xmlns:th="http://www.thymeleaf.org/">
    • 사용 시
      • th:fragment: html에 사용되는 태그명

        <html lang="ko"
              xmlns="http://www.w3.org/1999/xhtml"
              xmlns:th="http://www.thymeleaf.org/">
        <footer th:fragment="footer">
          <p>My times with Coffee</p>
        </footer>
    • 선언 시
      • th:replace="실제 경로,파일명 :: 사용되는 태그명"

        <div th:replace="cafe_head :: head"></div>
profile
tistory로 이전! https://sweet-rain-kim.tistory.com/

0개의 댓글