스프링 부트 프로젝트의 클래스 컨트롤러에있는 주석에 문제가 있습니다. 어떤 방법을 사용해야합니까?
@Controller
@RequestMapping("/products")
public class ProductController {
/**
* Only a Test
*/
@Autowired
private ProductService productService;
최소한 다음과 같은 CRUD 메서드가 있어야합니다.
@GetMapping
public String index(Model model) {
List<Product> products = productService.searchAll();
model.addAttribute("products", products);
return "product/index";
}
@GetMapping("/addProduct")
public String add(Product product, Model model) {
logger.info("Creating new 'Product' on data source");
this.productService.inserir(product);
return "product/addProduct";
}
@GetMapping("/editProduct/{id}")
public String edit(@PathVariable("id") Long id, Model model) {
logger.info("Find 'Product' Id: {} on data source", id);
Product product = this.productService.searchById(id);
model.addAttribute("product", product);
return "product/editProduct";
}
@GetMapping("/deleteProduct/{id}")
public String delete(@PathVariable("id") Long id, Model model) {
logger.info("Deleting 'Product' Id:{} from data source", id);
this.productService.deletar(id);
return index(model);
}
@PostMapping("/saveProduct")
public String save(@Valid Product product, BindingResult result, Model model) {
if (result.hasErrors()) {
return add(product, model);
}
if (product.getId() != 0) {
logger.info("Updating 'Product' Id: {} on data source", product.getId());
this.productService.atualizar(product);
} else {
logger.info("Creating new 'Product' on data source");
this.productService.inserir(product);
}
return index(model);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다