<!DOCTYPE html> <html lang="en"> <script src="../js/jquery-3.3.1.js"></script> <script src="../js/vue.min.js"></script> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post" id="div1"> <!--id<input type="text" name="id" readonly /><br/>--> dname<input type="text" name="dname"/><br/> loc<input type="text" name="loc"/><br/> <button type="button" @click="add">提交</button> </form> </body> <script> var my = new Vue({ el:"#div1", data:{ }, methods:{ add:function () { $.ajax({ url:"/add", type:"POST", data:$("form").serialize(), success:function (data) { alert("添加成功") window.location.href=("/"); } }) } } }) </script> </html>
//添加 @RequestMapping(value = "/add",method = RequestMethod.POST) public ResponseEntity addDept( Dept dept){ deptService.QaddDept(dept); return new ResponseEntity(HttpStatus.OK); }