实现一个按钮一个月内只允许点击一次,如果已被点击过,则提示已被点击,不可再次点击。
后台controller层代码:
/**
* 跳转支付页面
*/
@RequestMapping("pay")
public String pay(@RequestParam Map map, HttpSession session){
Object dw_account = session.getAttribute("account");
System.out.println(dw_account);
map.put("dw_account", dw_account);
List<Map> list = comService.getTime(map);
//拿到汇缴记录时间
String oldTi = list.get(0).get("ANCE_DATE") + "";
//将汇缴时间的“-”变为“”,并且截取前六位
String oldTime = oldTi.replace("-", "").substring(0, 6);
//取当前时间
Date date = new Date();
//把时间格式设置为yyyyMM格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
String now = dateFormat.format(date);
//把时间转换为字符串
String nowTime = now.toString();
//拿到汇缴记录的时间与当前时间的年月作比较,看是否相等
if (nowTime.equals(oldTime)) {
session.setAttribute("Msg","本月已汇缴!");
return "qiantai/danjiaona";
}else{
Object payables = map.get("payables");
Object userID=map.get("userID");
session.setAttribute("payables",payables);
session.setAttribute("userID",userID);
return "qiantai/pay";
}
}
/**
* 提示错误信息
* @return
*/
@ResponseBody
@RequestMapping("showMsg")
public Object showMsg(HttpSession httpSession){
Object msg = "";
try {
msg = httpSession.getAttribute("Msg");
} catch (Exception e) {
return msg;
}
return msg;
}
js代码:
使用ajax从后台取数据
$.ajax({
url:"/qian/showMsg",
success:function (data) {
$("#info").html(data);
}
});