Vue+Element(el-switch的使用)+springboot

10 篇文章 0 订阅
7 篇文章 0 订阅

目录

1、编写模板

2、发送请求

3、后端返数据

1.Controller类 

 2.interface接口(Service层接口)

3.Service(接口实现)

4.interface接口(Mapper层接口)

 5.xml

6.效果

4、el-switch属性


1、编写模板

<el-table :data="goodsData" border style="width: 100%">
  <el-table-column prop="id" label="id" width="180"></el-table-column>
  <el-table-column prop="name" label="商品名称" width="180"></el-table-column>
  <el-table-column prop="price" label="商品价格" width="180"></el-table-column>
  <el-table-column prop="imageUrl" label="商品图片" width="180"></el-table-column>
  <el-table-column prop="status" label="状态">
    <template slot-scope="scope">
      <el-switch v-model="scope.row.status"
                 active-color="green"
                 inactive-color="#ff4949"
                 active-value="1"
                 active-text="未删除"
                 inactive-text="已删除"
                 inactive-value="0"
                 width="50"
                 @change="deleteGoods(scope.row.id, scope.row.status)">
      </el-switch>
    </template>
  </el-table-column>
</el-table>

2、发送请求

  deleteGoods(id,status){
            if(id!=''&&id!=null){
                this.$axios({
                    method:'post',
                    url:'http://localhost:8080/api/upload/deleteGoods',
                    data:{
                        id:id,
                        status:status
                    }
                }).then((res)=>{
                    this.$message({
                        message:'修改成功',
                        type:"success"
                    })
                })
            }
        },

3、后端返数据

1.Controller类 
    @PostMapping("/deleteGoods")
    public Result deleteGoods(@RequestBody Goods goods) {
        return uploadFileService.deletegoods(goods);
    }
 2.interface接口(Service层接口)
public interface UploadFileService {

    Result deletegoods(Goods goods);

}
3.Service(接口实现)
    @Override
    public Result deletegoods(Goods goods) {

        //删除:物理删除,逻辑删除
        //这里是逻辑删除

        int count=uploadFileMapper.updateGoods(goods);
        if (count==1){
            return Result.succeed("删除成功");
        }else{
            return Result.failed("删除失败");
        }

    }
4.interface接口(Mapper层接口)
public interface UploadFileMapper {

    int updateGoods(Goods goods);


}
 5.xml

    <update id="updateGoods">

       update goods
        <set>
            <if test="name!=''and name!=null">name=#{name},</if>
            <if test="price!=''and price!=null">price=#{price},</if>
            <if test="imageUrl!=null">imageUrl=#{imageUrl},</if>
            <if test="status!=''and status!=null">status=#{status}</if>
        </set>
        where
            id = #{id}
    </update>
6.效果

 

4、el-switch属性

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

娃哈哈哈哈呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值