본문 바로가기
728x90

백엔드/타임리프20

타임리프 문자열 조합 https://blog.leocat.kr/notes/2018/11/21/thymeleaf-string-concatenation [Thymeleaf] 문자열 조합(합치기) (까먹을까봐 기록차) blog.leocat.kr 2022. 4. 5.
스프링부트 타임리프 라이브 reload https://easybrother0103.tistory.com/62 [Spring Boot] 인텔리제이 Live Reload 설정 템플릿엔진이나, js css등 수정이 잦은 것들을 매번 새로 빌드 하는 것은 매로 번거로운 일이다. SpringBoot Devtools를 통해 새로고침 만으로 resources 밑의 파일들의 실시간 반영을 할 수 있다. 1. Gradle c easybrother0103.tistory.com 2021.2 버전부터 Registry가 아니라 Advacned Settings에서 설정한다고 한다! Registry에서 compiler.automake.allow.when.app.running을 계속 찾다가.. 없어서 기록한다 Setting > Advanced Settings Allow .. 2022. 4. 5.
타임리프 셀렉트 박스 model에 Array로 넘겨줬다 ${item.deliveryCode}, ${deliveryCodes} 완전히 다른 객체이다. 2021. 9. 15.
타임리프 라디오 버튼 itemType Enum Controller에서 Enum 정보로 라디오 버튼 생성 HTML 체크박스 HTML 이랑 거의 비슷하다 2021. 9. 15.
타임리프 체크박스 단일체크박스 체크박스 속성상 select를 안하면 아예 서버로 전송이 안되므로 null 값을 받게된다(boolean 타입으로 저장해야한다.) 스프링 MVC에서는 _(name이름)을 사용해서 판단한다. 1. name 속성(open)이 오면 그대로 사용 2. name 속성(open)이 오지않으면 _open 값을 확인해서 open 속성에 = false를 넣어준다. 타임리프를 사용하면 체크박스의 히든 필드 관련 부분도 처리해준다. 멀티 체크박스 ${regions} 는 model의 addAttribute 로 추가해준 속성이고 *{regions} 는 form 에 있는 ${item} 내부의 regions 속성이다 ids.prev, ids.next를 사용해 동적으로 생성되는 id 값을 사용할 수 있게 한다. 2021. 9. 15.
타임리프 입력 폼 처리 th:object, th:field 중요!! Controller Model에 Item 객체 추가 @GetMapping("/add") public String addForm(Model model) { model.addAttribute("item", new Item()); return "form/addForm"; } Item 객체 import lombok.Data; @Data public class Item { private Long id; private String itemName; private Integer price; private Integer quantity; public Item() { } public Item(String itemName, Integer price, Integer quantit.. 2021. 9. 14.
템플릿 템플릿 조각 insert, replace 속성으로 불러오기 가능 main.html 부분 포함 부분 포함 insert 부분 포함 replace 부분 포함 단순 표현식 파라미터 사용 footer.html 푸터 자리 입니다. 파라미터 자리 입니다. 템플릿 레이아웃 layoutMain.html 의 head 태그 안의 값을 base.html의 head 태그의 common_header 템플릿 함수를 실행시키고 나온 결과값을 layoutMain.html head 태그로 적용한다. layoutMain.html 메인 컨텐츠 base.html 2021. 9. 13.
타임리프 자바스크립트, JS each 자바스크립트 inline 사용 Controller @GetMapping("/javascript") public String javascript(Model model) { model.addAttribute("user", new User("UserA", 10)); addUsers(model); return "basic/javascript"; } HTML 객체는 JSON으로 넣어준다. 2021. 9. 12.
타임리프 block 렌더링시 block이 들어가 있는 태그는 사라지고 내부 태그만 표시 Controller @GetMapping("/block") public String block(Model model) { addUsers(model); return "basic/block"; } HTML 사용자 이름1 사용자 나이1 요약 2021. 9. 12.
타임리프 주석 Controller @GetMapping("/comments") public String comments(Model model) { model.addAttribute("data", "Spring"); return "basic/comments"; } HTML 예시 html data 1. 표준 HTML 주석 2. 타임리프 파서 주석 여러줄 주석 html data 3. 타임리프 프로토타입 주석 (파일 그자체를 열떄는 안보이지만 타임리프를 이용해 서버사이드에서 렌더링시 표시) 2021. 9. 12.
타임리프 조건식(if, unless, switch) 조건을 충족시키지 않으면 태그자체가 삭제된다. Controller private void addUsers(Model model) { List list = new ArrayList(); list.add(new User("userA",10)); list.add(new User("userB",20)); list.add(new User("userC",30)); model.addAttribute("users",list); } @GetMapping("/condition") public String condition(Model model) { addUsers(model); return "basic/condition"; } HTML if, unless count username age 1 username 0 switc.. 2021. 9. 12.
타임리프 반복(each) Controller @GetMapping("/each") public String each(Model model) { addUsers(model); return "basic/each"; } private void addUsers(Model model) { List list = new ArrayList(); list.add(new User("userA",10)); list.add(new User("userB",20)); list.add(new User("userC",30)); model.addAttribute("users",list); } HTML 기본 테이블 username age username 0 반복 상태 유지 count username age etc username username 0 index .. 2021. 9. 12.
타임리프 속성 값 설정 controller @GetMapping("/attribute") public String attribute(){ return "basic/attribute"; } HTML 속성 설정 속성 추가 - th:attrappend = - th:attrprepend = - th:classappend = checked 처리 - checked o - checked x - checked=false 2021. 9. 12.
타임리프 연산 Controller @GetMapping("/operation") public String operation(Model model) { model.addAttribute("nullData", null); model.addAttribute("data", "Srping!!"); return "basic/operation"; } HTML 산술 연산 10 + 2 = 10 % 2 == 0 = 비교 연산 1 > 10 = 1 gt 10 = 1 >= 10 = 1 ge 10 = 1 == 10 = 1 != 10 = 조건식 (10 % 2 == 0)? '짝수':'홀수' = Elvis 연산자 ${data}?: '데이터가 없습니다.' = ${nullData}?: '데이터가 없습니다.' = No-Operation ${data}?:.. 2021. 9. 12.
타임리프 리터럴 Controller @GetMapping("/literal") public String literal(Model model) { model.addAttribute("data","Spring!"); return "basic/literal"; } HTML 리터럴 'hello' + ' world!' = 'hello world!' = 'hello ' + ${data} = 리터럴 대체 |hello ${data}| = 2021. 9. 12.
타임리프 URL 링크 컨트롤러 @GetMapping("link") public String link(Model model) { model.addAttribute("param1", "data1"); model.addAttribute("param2", "data2"); return "basic/link"; } HTML URL 링크 basic url hello query param path variable path variable + query parameter 2021. 9. 11.
타임리프 유틸리티 객체와 날짜 타임리프 유틸리티 객체들 #message : 메시지, 국제화 처리 #uris : URI 이스케이프 지원 #dates : java.util.Date 서식 지원 #calendars : java.util.Calendar 서식 지원 #temporals : 자바8 날짜 서식 지원 #numbers : 숫자 서식 지원 #strings : 문자 관련 편의 기능 #objects : 객체 관련 기능 제공 #bools : boolean 관련 기능 제공 #arrays : 배열 관련 기능 제공 #lists , #sets , #maps : 컬렉션 관련 기능 제공 #ids : 아이디 처리 관련 기능 제공 컨트롤러 @GetMapping("/date") public String date(Model model) { model.addAt.. 2021. 9. 11.
타임리프 기본객체(session, request, response) 및 스프링 빈 조회 컨트롤러 @Controller @RequestMapping("/basic") public class BasicController { @GetMapping("/basic-objects") public String basicObjects(HttpSession session) { session.setAttribute("sessionData","hello Session"); return "basic/basic-objects"; } @Component("helloBean") static class HelloBean{ public String hello(String data){ return "Hello " + data; } } } HTML 식 기본 객체 (Expression Basic Objects) request.. 2021. 9. 11.
타임리프 SpringEL, 지역변수 컨트롤러 @Controller @RequestMapping("/basic") public class BasicController { @GetMapping("/variable") public String varible(Model model) { User userA = new User("userA", 10); User userB = new User("userB", 10); List list = new ArrayList(); list.add(userA); list.add(userB); Map map = new HashMap(); map.put("userA", userA); map.put("userB", userB); model.addAttribute("user", userA); model.addAttribut.. 2021. 9. 11.
타임리프 text, utext 컨트롤러 데이터 전송 @Controller @RequestMapping("/basic") public class BasicController { @GetMapping("text-unescaped") public String textUnescaped(Model model) { model.addAttribute("data", "Hello Spring!"); return "basic/text-unescaped"; } } HTML text vs utext th:text = th:utext = [[...]] vs [(...)] [[...]] = [[${data}]] [(...)] = [(${data})] 2021. 9. 11.
728x90