状态这个字段在数据表中,属于tinyInt类型,转换到数据库中是bit类型,只有0和1,转换完是true和false
在jsp页面上,编写JS
function update(id,saleState) {
if(saleState==false){
confirm("您确定要上架吗?");
window.location.href="goodsDetail_update1.action?goodsdetail.id="+id;
}else{
confirm("您确定要下架吗?");
window.location.href="goodsDetail_update1.action?goodsdetail.id="+id;
};
};
<a class="button border-main" href="javascript:void(0)" οnclick="update(${goodsdetail.id},${goodsdetail.saleState})">
<span class="icon-edit"></span>
<c:if test="${goodsdetail.saleState==false }">上架</c:if>
<c:if test="${goodsdetail.saleState==true }">下架</c:if>
</a>
编写action方法
public String update1(){
Integer id=goodsdetail.getId();
goodsdetail=goodsDetailService.find(id);
if(goodsdetail.getSaleState()){
goodsdetail.setSaleState(false);
}else{
goodsdetail.setSaleState(true);
}
goodsDetailService.update(goodsdetail);
return "eee";
}
dao实现类的方法
@Override
public void update1(Goodsdetail goodsdetail) {
hibernateTemplate.update(goodsdetail);
}