场景:点击页面上一条数据的a标签,更改数据的状态
实现:
/**
* 确认或退回时执行
*/
@RequestMapping(value = "/statusChange/{id}/{status}")
@ResponseBody
public ApiResponses<Void> statusChange(@PathVariable("id") String id,
@PathVariable("status") String status,
HttpServletResponse response){
appOverShipmentService.statusChange(id, status);
return success();
}
<td>
<a class="fontBlue" href="#" th:value="${item.overShipmentId}" onclick="comfirmStatus(this)">确认</a>
| <a class="fontBlue" href="#" th:value="${item.overShipmentId}" onclick="backStatus(this)">退回</a>
</td>
/**状态确认操作*/
function comfirmStatus(obj) {
var id = $(obj).attr("value");
$.ajax({
url: "/moreorless/confirm/statusChange/"+id+"/S",
data: {id: id},
type: 'post',
success: function (data) {
if (data.status === 200) {
art.dialog({
title: '提示', content: '成功确认!', ok: function () {
window.location.reload();
}
});
} else {
art.dialog({icon: 'error', content: "确认失败"});
}
}
});
}
确认和退回的js基本一样
遇到的困难:
本来不想在写js,希望通过点击a标签直接更改。虽然可以达到更改状态,但是点击后主页直接刷新,form表单的查询的数据被清空,只好写js,不会将form表单的查询数据清空。
本来只写a标签是这样:
<td>
<a class="fontBlue"
th:href="'/moreorless/confirm/statusChange/'+${item.overShipmentId}+'/S'" target="_self">确认</a>
| <a class="fontBlue" th:href="'/moreorless/confirm/statusChange/'+${item.overShipmentId}+'/B'" target="_self">退回</a>
</td>
这样效果不理想,表单数据会被清空。