Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 春季百里香:如何显示警报_Spring_Spring Boot_Thymeleaf - Fatal编程技术网

Spring 春季百里香:如何显示警报

Spring 春季百里香:如何显示警报,spring,spring-boot,thymeleaf,Spring,Spring Boot,Thymeleaf,我正在为一个项目开发crud。我想在管理员编辑员工、产品时显示一个警报,无论它是什么,都会显示一个带有消息“已成功编辑”的警报。我可以显示此消息,但我想在警报中显示它 我的模型: // Edit @GetMapping("/dashboard/contato/editar/{id}") public String edit(@PathVariable("id") Long id, Model model) { Contato contato

我正在为一个项目开发crud。我想在管理员编辑员工、产品时显示一个警报,无论它是什么,都会显示一个带有消息“已成功编辑”的警报。我可以显示此消息,但我想在警报中显示它

我的模型:

// Edit
@GetMapping("/dashboard/contato/editar/{id}")
public String edit(@PathVariable("id") Long id, Model model)
{   
    Contato contato = contatoService.findById(id);
    model.addAttribute("contato", contato);

    return "dashboard/pages/contato/editar";
}

@RequestMapping("/dashboard/contato/editar/{id}")
public String update(@Valid Contato contato, BindingResult result, RedirectAttributes attributes,Model model)
{
    if(result.hasErrors()) {
        attributes.addFlashAttribute("error", "Verifique se os campos 
        obrigatórios foram preenchidos!");
        return "redirect:/dashboard/contato/editar/{id}";
    }else{
        contatoService.save(contato);
        attributes.addFlashAttribute("success", "Editado com sucesso!");
        return "redirect:/dashboard/contato";
    }

}

您可以使用Jquery的
document ready
功能在用户每次重定向到成功页面时显示警报。因此,每次加载页面时,浏览器都会自动运行文档准备功能(有关jquery文档准备功能的更多信息,请参阅官方文章-

此外,如果您希望基于某些动态条件显示警报消息,您也可以使用thymeleaf+javascript。有关如何将thymeleaf与javascript一起使用的更多详细信息,请参阅此官方文档-