添加/修改/删除

本文展示了使用Java Spring Boot进行模糊查询、增删改操作,并与前端Vue.js进行交互的实例。通过BookService和Mapper接口实现数据查询,前端使用axios库发送POST请求进行数据提交,实现了添加、修改、删除和查询功能。同时,文章还涵盖了前端表单验证和消息提示。
摘要由CSDN通过智能技术生成

//模糊查询
@Res...Mapper("list")
public Map<String,Object> list(Book book){
    List<Book> list=bookService.list(book);
    Map<String,Object> data=new HashMap<>();
    data.put("OK",true);
    data.put("rs",list);
    return map;
}

//添加/修改/删除
@Res...Mapper("add")
public String list(Book book){
    int count=bookService.add(book);
    if(count > 0){
    return "ture";    
    }else{
    return "false";
    }

}

select * from t_book where 1=1
<if test=bookname!=null>
 and bookname like concat('%',#{bookname},'%')
</if>


//添加/修改按钮
submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.form.id==null){
    //添加
            let url=this.axios.urls.BOOK_ADD;
            axios.post(
    url,this.form
    ).then(res=>{
    if(res.data=="true"){
    this.$message('添加成功')
    this.getList();
    }
    });
    //修改
    }else{
     let url=this.axios.urls.BOOK_UPDATE;
            axios.post(
    url,this.form
    ).then(res=>{
    if(res.data=="true"){
    this.$message('修改成功')
    this.getList();
    }
    });
    }
       this.dialogFormVisible:ture;
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },

//删除按钮
dele(id){
this.$confirm('确定要删除吗?').then(()=>{
let url=this.axios.urls.BOOK_DELETE;
    let data={
      'id':id
    }
            axios.post(
    url,this.form
    ).then(res=>{
    if(res.data=="true"){
    this.$message('删除成功')
    this.getList();
    }
    });
});
}


//查询所有
getlist(){
let url=this.axios.urls.BOOK_LIST;
axios.get('url', {
    params: {
      bookname: this.form.bookname
    }
  }) .then(res=>{
    let data=res.data;
    this.tableData=data.rs;

})
}

//钩子函数
created(){
   this.getlist();
}

//查询按钮
onSubmit(){
    this.getlist();
},


type="flex"

add(){
this.title="添加书本"
this.form.bookname=null;
....
this.dialogFormVisible:ture;
}

update(row){
this.title="修改书本"
this.form.id=row.id;
this.form.bookname=row.bookname;
....
this.dialogFormVisible:ture;
}


'BOOK_LIST':'https://localhost:8080:ssm/book.list',


https://element.eleme.cn/#/zh-CN


https://github.com/axios/axios

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值