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

目录

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属性

相关推荐

  1. C#中使用 => 运算符 switch 表达式

    2024-01-23 20:38:03       53 阅读
  2. 前端代码优化-switch使用

    2024-01-23 20:38:03       35 阅读
  3. 5.控制结构,if、switch、for使用【go】

    2024-01-23 20:38:03       31 阅读
  4. Flutter switch 语句补遗

    2024-01-23 20:38:03       41 阅读
  5. P4_16使用table实现通用switch分支语句

    2024-01-23 20:38:03       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-23 20:38:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-23 20:38:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-23 20:38:03       82 阅读
  4. Python语言-面向对象

    2024-01-23 20:38:03       91 阅读

热门阅读

  1. git rebase/revert/reset 命令用法及场景

    2024-01-23 20:38:03       56 阅读
  2. python 编写dll给c++调用

    2024-01-23 20:38:03       54 阅读
  3. git总结

    2024-01-23 20:38:03       62 阅读
  4. Open CASCADE学习|Aspect_Handle.h头文件

    2024-01-23 20:38:03       56 阅读
  5. C++ Webserver从零开始:基础知识(五)——信号

    2024-01-23 20:38:03       49 阅读
  6. Docker基础使用

    2024-01-23 20:38:03       55 阅读
  7. (十三)Head first design patterns原型模式(c++)

    2024-01-23 20:38:03       57 阅读
  8. js的十个知识点

    2024-01-23 20:38:03       60 阅读