@Controller public class HomeController { @GetMapping("/") public String home() { return "home"; } }
Controller/MemberController
@Controller public class MemberController {
private final MemberService memberservice;
@Autowired
public MemberController(MemberService memberservice) {
this.memberservice = memberservice;
}
@GetMapping("/members/new")
public String createForm() {
return "members/createMemberForm";
}
@PostMapping("/members/new")
public String create(MemberForm form) {
Member member = new Member();
member.setName(form.getName());
memberservice.join(member);
return "redirect:/";
}
@GetMapping("/members")
public String list(Model model) {
List<Member> members = memberservice.findMembers();
model.addAttribute("members", members);
return "members/memberList";
}
}