从控制器显示错误或成功
Show error or success from controller
我正在使用 sweetAlert 来显示弹出消息,我想知道是否有任何原因要从控制器显示此警报
myPage.html
<form th:object="${ecran}" th:action="@{/createIssue}" method="post" >
...
<a class="btn btn-outline-danger" type="submit" >Valider la demande</a>
</form>
我的提醒
swal("Are you sure you want to do this?", {
buttons: ["Oh noez!", true],
});
myController.java
@PostMapping("/createIssue")
public String creerUneDemande(@Valid @ModelAttribute("ecran") Ecran ecran, BindingResult result,
RedirectAttributes redirectAttributes) {
...
}
您可以通过使用模态属性在控制器中设置一个标志来实现相同的目的,并根据您可以在视图页面中显示警报的标志值。
@PostMapping("/createIssue")
public String creerUneDemande(@Valid @ModelAttribute("ecran") Ecran ecran, BindingResult result,
RedirectAttributes redirectAttributes) {
...
//if everything working fine then set the flag value
redirectAttributes.addFlashAttribute("flag","showAlert");
}
在视图页面中接受 javascript 代码中的标志值并执行如下条件。
if('${flag}' == 'showAlert'){
swal("Are you sure you want to do this?", {
buttons: ["Oh noez!", true],
});
}
我正在使用 sweetAlert 来显示弹出消息,我想知道是否有任何原因要从控制器显示此警报
myPage.html
<form th:object="${ecran}" th:action="@{/createIssue}" method="post" >
...
<a class="btn btn-outline-danger" type="submit" >Valider la demande</a>
</form>
我的提醒
swal("Are you sure you want to do this?", {
buttons: ["Oh noez!", true],
});
myController.java
@PostMapping("/createIssue")
public String creerUneDemande(@Valid @ModelAttribute("ecran") Ecran ecran, BindingResult result,
RedirectAttributes redirectAttributes) {
...
}
您可以通过使用模态属性在控制器中设置一个标志来实现相同的目的,并根据您可以在视图页面中显示警报的标志值。
@PostMapping("/createIssue")
public String creerUneDemande(@Valid @ModelAttribute("ecran") Ecran ecran, BindingResult result,
RedirectAttributes redirectAttributes) {
...
//if everything working fine then set the flag value
redirectAttributes.addFlashAttribute("flag","showAlert");
}
在视图页面中接受 javascript 代码中的标志值并执行如下条件。
if('${flag}' == 'showAlert'){
swal("Are you sure you want to do this?", {
buttons: ["Oh noez!", true],
});
}