250x250
Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- 프래그먼트
- 주엽역 생활맥주
- 막내의 막무가내 알고리즘
- 막내의막무가내 프로그래밍
- flutter network call
- 막내의막무가내 일상
- 막내의막무가내 안드로이드 코틀린
- 안드로이드 Sunflower 스터디
- 막내의막무가내 안드로이드
- 막내의막무가내 코틀린
- 막내의막무가내 코볼 COBOL
- 막무가내
- 2022년 6월 일상
- 막내의막무가내 플러터
- 막내의막무가내 플러터 flutter
- 막내의막무가내 알고리즘
- 막내의막무가내 코틀린 안드로이드
- 막내의막무가내 회고 및 목표
- 안드로이드
- 막내의 막무가내
- 막내의막무가내 안드로이드 에러 해결
- 막내의막무가내
- 안드로이드 sunflower
- 프로그래머스 알고리즘
- 부스트코스
- 막내의막무가내 목표 및 회고
- 막내의막무가내 rxjava
- 부스트코스에이스
- Fragment
- 막내의막무가내 SQL
Archives
- Today
- Total
막내의 막무가내 프로그래밍 & 일상
[Spring Boot] 스프링부트 타임리프 (thymeleaf) 정리 본문
728x90
스프링부트 팀프로젝트를 하면서 타임리프 관련된 거를 정리를 조금씩 해놀려고합니다. 나중에 보기 편하게 ㅎㅎ
조금씩 하면서 쓰는거라 미완성 코드 입니다.
컨트롤러(Controller) 관련 정리
https://youngest-programming.tistory.com/174?category=905760
[Spring] 스프링부트 컨트롤러 (Springboot controller)
@RequestMapping => value에는 url, method는 get, post 같은 HTTP 프로토콜 방식을 써주면 된다. 즉 클라이언트가 URL로 서버에 요청을 하면 해당 URL을 맵핑하고 있는 메소드가 해당 요청을 처리하고 응답해준..
youngest-programming.tistory.com
[객체 받는법] @ModelAttribute
@RequestMapping(value = "/do_register", method = RequestMethod.POST)
public ModelAndView doRegister(@ModelAttribute(name = "userDto") UserDto userDto, HttpServletRequest request) {
System.out.println(userDto.toString());
ModelAndView mv = new ModelAndView();
mv.setViewName("views/login/register");
return mv;
}
모델 객체
package com.mtjin.itarticle;
import com.mtjin.itarticle.domain.entity.UserEntity;
import lombok.*;
@Getter
@Setter
@ToString
@NoArgsConstructor
public class UserDto {
private long id;
private String name;
private String email;
private String password;
public UserEntity toEntity() {
UserEntity boardEntity = UserEntity.builder()
.id(id)
.name(name)
.email(email)
.password(password)
.build();
return boardEntity;
}
@Builder
public UserDto(long id, String name, String email, String password) {
this.id = id;
this.name = name;
this.email = email;
this.password = password;
}
}
html은 form 태그는 th:action 으로 url 맵핑. th:object로 @ModelAttribute 맵핑. input 태그는th:name 으로 객체 변수 이름과 맵핑
<form method="POST" th:action="@{/do_register}" th:object="${userDto}" class="my-login-validation" novalidate="">
<div class="form-group">
<label for="name">Name</label>
<input th:name="name" id="name" type="text" class="form-control" name="name" required autofocus>
<div class="invalid-feedback">
What's your name?
</div>
</div>
<div class="form-group">
<label for="email">E-Mail Address</label>
<input th:name="email" id="email" type="email" class="form-control" name="email" required>
<div class="invalid-feedback">
Your email is invalid
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input th:name="password" id="password" type="password" class="form-control" name="password" required data-eye>
<div class="invalid-feedback">
Password is required
</div>
</div>
<div class="form-group">
<div class="custom-checkbox custom-control">
<input type="checkbox" name="agree" id="agree" class="custom-control-input" required="">
<label for="agree" class="custom-control-label">I agree to the <a href="#">Terms and Conditions</a></label>
<div class="invalid-feedback">
You must agree with our Terms and Conditions
</div>
</div>
</div>
<div class="form-group m-0">
<button type="submit" class="btn btn-primary btn-block">
Register
</button>
</div>
<div class="mt-4 text-center">
Already have an account? <a th:href="@{'/login'}">Login</a>
</div>
</form>
728x90
'웹 > Spring Boot' 카테고리의 다른 글
| [Spring boot] 회원가입 기록 AWS(EC2, MySql) - JPA - Thymeleaf (0) | 2020.04.16 |
|---|---|
| [Spring Boot] $.ajax is not a function 에러 처리 (0) | 2020.04.16 |
| [Spring Boot] JPA 추가 및 프로젝트 패키지 분리 (0) | 2020.04.07 |
| [Spring Boot] aws mysql 데이터베이스 연동 기록 (0) | 2020.04.07 |
| [Spring] 인텔리제이 스프링부트 세팅 (0) | 2020.03.14 |
Comments