Skip to content

Commit

Permalink
이슈 #39 FreeController 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
ezeun committed Jan 17, 2024
1 parent c771aa4 commit 6739587
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/umc/forgrad/controller/FreeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package umc.forgrad.controller;

import umc.forgrad.domain.common.Free;
import umc.forgrad.service.FreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Controller
public class FreeController {

private final FreeService freeService;

@Autowired
public FreeController(FreeService freeService) {
this.freeService = freeService;
}

@PostMapping(value = "/plans/memo")
public String create(FreeFrom form) {

Free free = new Free();
free.setMemo(form.getMemo());

freeService.addMemo(free);

return "redirect:/";
}

@GetMapping(value = "/plans/memo")
public String list(Model model) {
List<Free> memos = memoService.findMemos();
model.addAttribute("memos", memos);
return "memos/memoList"; //resources/templates/memos/memoList.html
}
}
11 changes: 11 additions & 0 deletions src/main/java/umc/forgrad/controller/FreeForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package umc.forgrad.controller;

public class FreeForm {
private String name;
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
}

0 comments on commit 6739587

Please sign in to comment.