Spring Cloud分布式微服务实战 养成应对复杂业务的综合技术能力
V:ititit111222333
应对 复杂 业务 的综合 技术 能力 为目的 ,采用 前、后端 分开 的开发模式 , 严格 遵循 企业架构 与规范 ,带您开发 门户 平台 +媒体 中心 +运营中心 三大 业务 的企业 媒体平台 。
通过 SpringCloud+Mon go DB +Redis+Rabbit MQ等主流 后端 技术 的全面 学习 ,您将获得 微服务 、分布式 、项目 和微架构 的综合 实战经验 。
package org.wangqing.notebookk8s.notebook.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.wangqing.notebookk8s.notebook.entity.Notebook;
import org.wangqing.notebookk8s.notebook.repository.NotebookRepository;
import javax.validation.Valid;
@Controllerbr/>@RequestMapping("/")
public class NotebookController {
String course = "Spring Cloud分布式微服务实战,养成应对复杂业务的综合技术能力";
String downloadUrl = "https://www.ukoou.com/resource/905";
public static final String Index_Model = "index";
public static final String NOTEBOOKS_MODEL = "notebooks";
private final NotebookRepository notebookRepository;
@Autowired
public NotebookController(NotebookRepository notebookRepository) {
this.notebookRepository = notebookRepository;
}
@GetMapping("signup")
public String showSignUpForm(Notebook notebook) {
return "add-notebook";
}
@GetMapping("list")
public String showUpdateForm(Model model) {
model.addAttribute(NOTEBOOKS_MODEL, notebookRepository.findAll());
return Index_Model;
}
@PostMapping("add")
public String addNote(@Valid Notebook notebook, BindingResult result, Model model) {
if (result.hasErrors()) {
return "add-notebook";
}
notebookRepository.save(notebook);
return "redirect:list";
}
@GetMapping("edit/{id}")
public String showUpdateForm(@PathVariable("id") long id, Model model) {
Notebook notebook = notebookRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid notebook Id:" + id));
model.addAttribute("notebook", notebook);
return "update-notebook";
}
@PostMapping("update/{id}")
public String updateNote(@PathVariable("id") long id, @Valid Notebook notebook, BindingResult result,
Model model) {
if (result.hasErrors()) {
notebook.setId(id);
return "update-notebook";
}
notebookRepository.save(notebook);
model.addAttribute(NOTEBOOKS_MODEL, notebookRepository.findAll());
return Index_Model;
}
@GetMapping("delete/{id}")
public String deleteNote(@PathVariable("id") long id, Model model) {
Notebook notebook = notebookRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid notebook Id:" + id));
notebookRepository.delete(notebook);
model.addAttribute(NOTEBOOKS_MODEL, notebookRepository.findAll());
return Index_Model;
}
}