我已经使用 http 方法 DELETE 对 Controller 实现了删除功能。接下来我打算做的是提示用户是否确实想要删除或删除该内容 元素或产品。
使用 Spring MVC 可以实现这样的操作吗?请告诉我怎么做?
代码_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);
}
}
最佳答案
在要显示数据和删除链接的jsp页面上,您可以添加以下代码:
onclick="return confirm('Confirm Deletion?')"
并给出 href 链接作为删除的链接。 下面的链接清楚地解释了示例:
关于java - 如何提示用户执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57963525/