新增按钮弹出模态框的实现新增功能

<div id="toolbar">
                    "button" value="新增" id="addBtn" data-toggle="modal" data-target="#addUserModal" class="btn btn-primary" >
div>

<div class="modal fade" id="addUserModal" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h3>新增h3>
                    div>
                    <div class="modal-body">
                        <form id="addUserForm" action="${pageContext.request.contextPath}/basicxxx/insertxxx.do" method="post" class="form-horizontal">
                            <div class="form-group">
                                <label for="opro" class="col-sm-2 control-label">路线:label>
                                <div class="col-sm-7">
                                    <input type="text" name="opro" id="opro" class="form-control"  placeholder="路线"/>
                                div>
                                <label id="errorAccount" for="opro" class="col-sm-3 control-label">label>
                            div>
    form>
    div>
        <div class="modal-footer">
                        <button type="button" id="conf" class="btn btn-default" onclick="addUser()">确定button>
                        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="resetAddModal()">取消button>
                    div>
                div>              
            div>
        div>
//点击取消后清空表单中已写信息
function resetAddModal() {
    document.getElementById("addUserForm").reset();
}
//新增用户
function addUser() {
    var param = $("#addUserForm").serializeArray();
    //debugger;
    $("#conf").attr("onclick", "addUser()");
    $.ajax({
        url: "${pageContext.request.contextPath}/basicxxx/insertxxx.do",
        method: "post",
        data: param,
        dataType: "json",
        "success":function(obj){        
            if(obj.state==1){
                location="${pageContext.request.contextPath}/basixxx/showxxx.do"; 
                alert(obj.message);
            }else{
                alert(obj.message);
            }
        }
    });
    }
@RequestMapping("/showxxx.do")
    public String showRoute(ModelMap map,String opro,HttpSession session) {
    List<Route> list = routeService.getByOpro(opro);
    map.addAttribute("opro", opro);
    map.addAttribute("list", list); 
    return "xxx";
    //xxx.jsp

@RequestMapping("/insertxxx.do")
    @ResponseBody
    //新增工艺路线数据
    public ResponseResult<Void> insertRoute(@RequestParam("opro")String opro,@RequestParam("dsca")String dsca,  @RequestParam("memo")String memo,@RequestParam("oprotype")String oprotype,@RequestParam("oprotypename")String oprotypename){
        ResponseResult<Void> rr = new ResponseResult<Void>();                   
        try {
            Route route = new Route();
            route.setOpro(opro);
            route.setDsca(dsca);
            route.setMemo(memo);
            route.setOprotype(oprotypename);
            route.setOprotypename(oprotypename);
            routeService.addRoute(route);
            //System.out.println("opro="+opro);
            rr.setState(1);
            rr.setMessage("添加成功");
        } catch (Exception e) {
            rr.setState(0);
            rr.setMessage("添加失败");
        }
        return rr;
    }

实体类就不写了:
ResponseResult<T>为实体类,里面有
    private Integer state;
    private String message;
    private T data;

你可能感兴趣的:(新增按钮弹出模态框的实现新增功能)