ssm中ajax传值实例

前台:

jsp页面中

<script type="text/javascript">
//禁用账号
        function useDisable(id){            
            $.ajax({
                type:"POST",
                url:ctx+'/bus/busCityPartner/useAble',
                data:{"id":id,"use":0},
                success:function(msg){
                    if("OK"!=msg){
                        alert("禁用账号失败!");                       
                    }
                    location.href=ctx+"/bus/busCityPartner?repage";
                },
                error:function(e){
                    alert("禁用账号失败!");                   
                }
            });
        }
    script>

body里面的选项

<c:choose>
                <c:when test="${0 eq busCityPartner.isUse}">
                    <a href="javascript:void(0)" onclick="useAble('${busCityPartner.id}')">启用a>
                c:when>
                <c:when test="${1 eq busCityPartner.isUse}">
                    <a href="javascript:void(0)" onclick="useDisable('${busCityPartner.id}')">禁用a>
                c:when>
                c:choose>

后台:

controller中

@RequiresPermissions("bus:busCityPartner:edit")
    @RequestMapping(value = "useAble")
    @ResponseBody
    public String useAble(String id,String use){
        busCityPartnerService.useAble(id,use);
        return "OK";
    }

service中

/**
     * 根据id,启用账户
     * @param id
     * @param use
     */
    @Transactional(readOnly = false)
    public void useAble(String id, String use) {
        busCityPartnerDao.useAble(id,use);      
    }

dao中

/**
     * 根据id查询账号是否启用
     * @param id
     * @param use
     */
    public void useAble(String id, String use);

MyBatis mapping中

<select id="useAble" >
       UPDATE bus_city_partner SET
             is_use = #{param2}
       WHERE id = #{param1}      
    select>

你可能感兴趣的:(java开发应用)