【发布时间】:2020-01-17 16:26:25
【问题描述】:
我已经使用 http 方法 DELETE 为控制器实现了删除功能。我接下来打算做的是提示用户是否真的想删除或删除 物品或产品。
使用 spring MVC 是否可以实现这样的操作?请告诉我怎么做?
code_1:
@Controller
@RequestMapping("/product/remove")
public class RemoveProductPageController {
public final static String sRemoveProductFromListAttributeName = "removeProductFromList";
public final static String CONTROLLER_URL = "/product/remove";
public final static String DO_REMOVE_HANDLER_METHOD_URL = CONTROLLER_URL + "/{idx}";
@Autowired
private ProductService productService;
@RequestMapping(value = "/{idx}",
method = RequestMethod.DELETE)
@ResponseBody
public ResponseEntity<String> doRemove(@Validated @Size(min = 0) @PathVariable(required = true) int idx,
Model model) {
Product productToBeRemove = productService.getProductFromListByIdx(idx);
if (productToBeRemove == null) {
return new ResponseEntity<String>("no product is avaialble at index:" + idx, HttpStatus.NOT_FOUND);
}
model.addAttribute(RemoveProductPageController.sRemoveProductFromListAttributeName, productToBeRemove);
productService.removeProdcutFromListBxIdx(idx);
return new ResponseEntity<String>("product removed from index: " + idx, HttpStatus.OK);
}
}
【问题讨论】:
标签: java ajax spring spring-boot spring-mvc