jsp页面中,以radio赋值(与 “jsp页面中,以radio取值” 成对)

来源:互联网 发布:音悦台 for mac 编辑:程序博客网 时间:2024/05/18 00:10

dao层:

void updateCodeState(@Param("codeState")String codeState,@Param("noid")Integer noid);

dao.xml层:

 <update id="updateCodeState">
   update t_user set code_state=#{codeState} where noid=#{noid}
  </update>

service层:

public void updateCodeState(String codeState,Integer noid) {
userDao.updateCodeState(codeState,noid);
}

controller层:

@RequestMapping("/code.do")
@ResponseBody
public String updateCodeState(String codeState,Integer noid){
System.out.println("当前值"+codeState);
System.out.println("当前id"+noid);
userService.updateCodeState(codeState,noid);
return "更改成功";
}

jsp层:

ajax方法:

$(function(){
 $(":radio").click(function(){
  var codeState=$(this).val();
  var changeState=$(this).attr("idvalue");
  if(codeState==1){
 
  alert("变更为可用");
  }
  else{
  alert("变更为锁定");
  }
 
 
  $.ajax({
 url:"/user/code.do",
 type:"POST",
 data:{ codeState:codeState,noid:changeState},
 
 success:function(data){
 alert(data);
 } 
  });
 });
});


取值方法:

<c:choose>
  <c:when test="${user.codeState== 1}">
  <input type="radio" name="${status.count }" idvalue="${user.noid }" value="1" 
  checked="checked" />正常 
  <input type="radio" name="${status.count }" idvalue="${user.noid }" value="2" />锁定 
  </c:when>
  <c:when test="${user.codeState== 2}">
  <input type="radio" name="${status.count }" idvalue="${user.noid }" value="1"
  />正常 
  <input type="radio" name="${status.count }" idvalue="${user.noid }" value="2" 
  checked="checked" />锁定
  </c:when>
  </c:choose> 



数据库原值:更改后的值:网页原显示:

网页更改后的值:更改时的弹框:


0 0
原创粉丝点击