Finalproject
폼을 만들었으니 js에 언급되어있는 ajax을 작성
@RestController
public class RecipeAjax {
@Autowired
private RecipeService recipeService;
@Autowired
private CommentService commentService;
// 조리과정리스트 - 조리리스트 버튼
@GetMapping("/ajax/recipeList")
public recipeListDTO recipeList(@RequestParam(name = "boardNo") int boardNo,@RequestParam(name = "cookingId") int cookingId) {
List<Cooking> cList = recipeService.getCookList(boardNo);
List<Material> materials = recipeService.getMaterialList(boardNo);
RecipeBoard recipe =recipeService.getRecipe(boardNo, false);
return new recipeListDTO(cList,materials,recipe);
}
// 조리과정리스트 -조리리스트 책 버튼
@GetMapping("/ajax/cookList")
public CookMeterialDTO cookList(@RequestParam(name = "boardNo") int boardNo,@RequestParam(name = "currentPage") int currentPage,
@RequestParam(name = "cookingId") int cookingId) {
Cooking getCook = recipeService.getCookList(boardNo).get(currentPage);
List<Material> materials = recipeService.getMaterialList(boardNo);
return new CookMeterialDTO(getCook, materials);
}
// 책의 첫페이지 -조리리스트 책 버튼
@GetMapping("/ajax/bookDetail")
public RecipeBoard getBook(Model model,@RequestParam(name = "boardNo") int boardNo) {
RecipeBoard recipe = recipeService.getRecipe(boardNo,false);
recipe.setMaterials(recipeService.getMaterialList(boardNo));
return recipe;
}
@PostMapping("/ajax/cookUpdate")
@ResponseBody
public List<Cooking> updateCookAjax(@RequestParam(name="boardNo")int boardNo) {
List<Cooking> cList = recipeService.getCookList(boardNo);
return cList;
}
@PostMapping("/ajax/materialUpdate")
@ResponseBody
public List<Material> updateMaterialAjax(@RequestParam(name="boardNo")int boardNo) {
List<Material> mList = recipeService.getMaterialList(boardNo);
// 재료리스트
return mList;
}
}
detail에 ajax 컨트롤러로 만들었다.