



package org.example.hello.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class BoardController {
// localgost:8080/home
@GetMapping("/home")
public String home() {
return "home";
}
// localhost8080/detail
@GetMapping("/detail")
public String detail() {
return "detail";
}
}package org.example.hello.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class UserController {
// localhost8080/detail (GET) detail.mustache
// localhost8080:join
// body : username- ssa
// header : Content-Type : application.x-www-form-urlencoded
// 줄게 -> 회원가입 정보를
@PostMapping("/join")
public String join(String username) {
// 1. DB insert
System.out.println("username:" + username);
// 2. 응답
return "redirect:/home";
}
// 줘 -> 회원가입 페이지
@GetMapping("/join-form")
public String joinForm() {
return "join-form";
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>상세보기 페이지입니다.</h1>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>홈 페이지</h1>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>회원가입 페이지 - 폼 태그, 인풋</h1>
<from action="/join" method="post">
<input type="text" name=" username" placeholder="Enter username">
<button type="submit">회원가입</button>
</from>
</body>
</html>Share article