📚코드로 배우는 스프링 부트 웹 프로젝트를 통해 공부한 내용들을 정리해보았습니다.
88p-90p
타임리프는 JSP를 사용해본 경험이 있다면 어려움 없이 적응이 가능하다는 장점이 있습니다.
Lombok의 @Data는 Getter/Setter,toString(), equals(),hashCode()를 자동을 생성합니다.
@Data
@Builder(toBuilder = true)
public class SampleDTO {
private Long sno;
private String first;
private String last;
private LocalDateTime regTime;
}
@GetMapping의 value 속성값을 '{}'로 처리하면 하나 이상의 URL을 지정할 수 있습니다.
@GetMapping({"/ex2"})
public void exModel(Model model){
List<SampleDTO>list = IntStream.rangeClosed(1,20).asLongStream().mapToObj(i->{
SampleDTO dto = SampleDTO.builder().sno(i)
.first("First")
.last("Last"+i)
.regTime(LocalDateTime.now())
.build();
return dto;
}).collect(Collectors.toList());
model.addAttribute("list",list);
}
3.2.1반복문처리
Thymeleaf에서의 반복문은 th:each라는 속성을 이용합니다.
each 속성은 다음과 같이 기술합니다.
th:each = "변수 : ${목록}"
07.14 추가
강의 영상을 참고해서 해결했다.
강의 영상에서도 list에는 에러 문구가 뜨는데 프로그램 구동할 때는 문제가 없다.
내가 오류났던 이유는 서버를 구동시킬 때, main 클래스에있는 Application을 구동하지 않았기 때문이다.
영상에서는 강사님은 아래의 방법으로 기술하셨다.
@GetMapping({"/ex2"})
public void exModel(Model model){
log.info("ex2.............");
SampleDTO dto = SampleDTO.builder()
.regTime(LocalDateTime.now())
.build();
List<SampleDTO> list =IntStream.rangeClosed(1,20).asLongStream().mapToObj(i->
dto.toBuilder().sno(i).first("first..."+i).last("last..."+i).build()).collect(Collectors.toList());
log.info(list);
model.addAttribute("list",list);
}
실행 화면
✔배운점
✔ 서버 구동은 main 클래스에있는 Application로 하기
✔ ${list}에 오류 메세지가 떠도 실행하는 건 문제 없다.
728x90
'🏰 Back-end > Spring Boot' 카테고리의 다른 글
[Spring Boot] 제어문 처리 (0) | 2021.07.16 |
---|---|
[Spring Boot] 반복문의 상태 객체 (0) | 2021.07.15 |
[Spring Boot] 스프링 MVC와 Thymeleaf | 포트 번호 바꾸기 | 404 에러 해결 (0) | 2021.07.11 |
[Spring Boot] @Query 어노테이션 (0) | 2021.07.10 |
[Spring Boot] 쿼리 메서드와 Pageable의 결합 (0) | 2021.07.09 |
댓글