Java 如何提示用户进行操作

Java 如何提示用户进行操作,java,ajax,spring,spring-boot,spring-mvc,Java,Ajax,Spring,Spring Boot,Spring Mvc,我已经使用http方法DELETE实现了控制器的删除功能。下一步我打算做的是,如果用户真的想删除或删除它,则提示用户 物品或产品 使用SpringMVC,这样的操作是否可行??请告诉我怎么做 代码_1: @Controller @RequestMapping("/product/remove") public class RemoveProductPageController { public final static String sRemoveProductFromListAttribut

我已经使用http方法DELETE实现了控制器的删除功能。下一步我打算做的是,如果用户真的想删除或删除它,则提示用户 物品或产品

使用SpringMVC,这样的操作是否可行??请告诉我怎么做

代码_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);
}
}
@控制器
@请求映射(“/product/remove”)
公共类RemoveProductPageController{
公共最终静态字符串sRemoveProductFromListAttributeName=“removeProductFromList”;
公共最终静态字符串控制器_URL=“/product/remove”;
公共最终静态字符串DO_REMOVE_HANDLER_METHOD_URL=CONTROLLER_URL+“/{idx}”;
@自动连线
私人产品服务;
@RequestMapping(value=“/{idx}”,
方法=RequestMethod.DELETE)
@应答器
公共响应性doRemove(@Validated@Size(min=0)@PathVariable(required=true)int idx,
(模型){
Product productToBeRemove=productService.getProductFromListByIdx(idx);
if(productToBeRemove==null){
返回新的响应属性(“索引:+idx,HttpStatus.未找到任何产品可用”);
}
model.addAttribute(RemoveProductPageController.sRemoveProductFromListAttributeName,productToBeRemove);
productService.removeProdcutFromListBxIdx(idx);
返回新的响应属性(“从索引中删除的产品:+idx,HttpStatus.OK”);
}
}

在要显示删除数据和链接的jsp页面上,可以添加以下代码:

onclick="return confirm('Confirm Deletion?')"
并将href link作为删除的链接。 下面的链接中清楚地解释了示例:


如果您不打算使用Javascript,则可以将用户引导到第二个用于确认的页面。传递从第一页收集的所有表单数据等。第二页将显示相关信息,并要求用户确认或取消。如果用户确认,控制器类将执行删除;如果用户取消,控制器类将中止删除