springboot整合vue2实现简单的新增删除,整合ECharts实现图表渲染

news2024/10/7 2:25:36

先看效果图:

1.后端接口

 //    查询所有商品信息
//    @CrossOrigin(origins = "*")
    @RequestMapping("/list1")
    @ResponseBody
    public List<Goodsinfo> list1(){
        List<Goodsinfo> list = goodsService.list();
        return list;
    }


//    删除
//    @CrossOrigin(origins = "*")
    @RequestMapping("/del")
    @ResponseBody
    public String del(int id){
        try {
            goodsService.removeById(id);
            return "删除成功";
        }catch (Exception e){
            return "删除失败";
        }
    }

//    根据条件查询
    @RequestMapping("/search")
    @ResponseBody
    public List<Goodsinfo> search(String goodsname,String goodsType){
        System.out.println(goodsname+","+goodsType);
        QueryWrapper<Goodsinfo> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(goodsname),"name",goodsname).like(StringUtils.isNotBlank(goodsType),"goods_type",goodsType);
        List<Goodsinfo> list = goodsService.list(wrapper);
        for (Goodsinfo goodsinfo : list) {
            System.out.println(goodsinfo);
        }
        return list;
    }

// 添加数据
    @RequestMapping("/add")
    @ResponseBody
    public String add(@RequestBody Goodsinfo goodsinfo){
        System.out.println(goodsinfo);
        goodsService.save(goodsinfo);
        return "添加成功";
    }

2.前端页面:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- CSS only -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
    />
    <style>
      .red {
        color: red!important;
      }
      .search {
        width: 300px;
        margin: 20px 0;
      }
      .my-form {
        display: flex;
        margin: 20px 0;
      }
      .my-form input {
        flex: 1;
        margin-right: 20px;
      }
      .table > :not(:first-child) {
        border-top: none;
      }
      .contain {
        display: flex;
        padding: 10px;
      }
      .list-box {
        flex: 1;
        padding: 0 30px;
      }
      .list-box  a {
        text-decoration: none;
      }
      .echarts-box {
        width: 600px;
        height: 400px;
        padding: 30px;
        margin: 0 auto;
        border: 1px solid #ccc;
      }
      tfoot {
        font-weight: bold;
      }
      @media screen and (max-width: 1000px) {
        .contain {
          flex-wrap: wrap;
        }
        .list-box {
          width: 100%;
        }
        .echarts-box {
          margin-top: 30px;
        }
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="contain">
        <!-- 左侧列表 -->
        <div class="list-box">

          <!-- 添加资产 -->
          <form class="my-form">
            <input type="text" v-model="goods.name" class="form-control" placeholder="名称" />
            <input type="text" v-model="goods.price" class="form-control" placeholder="价格" />
			<input type="text" v-model="goods.intro" class="form-control" placeholder="简介" />
			<input type="text" v-model="goods.amount" class="form-control" placeholder="库存" />
			<input type="text" v-model="goods.goodsType" class="form-control" placeholder="类别" />
			<input type="text" v-model="goods.remark" class="form-control" placeholder="备注" />
            <button type="button" class="btn btn-primary" @click="add()">添加账单</button>
          </form>

          <table class="table table-hover">
            <thead>
              <tr>
                <th>编号</th>
                <th>名称</th>
                <th>价格</th>
                <th>简介</th>
				<th>库存</th>
				<th>类别</th>
				<th>备注</th>
				<th>操作</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item,index) in list" :key="item.id">
                <td>{{index+1}}</td>
                <<th>{{item.name}}</th>
                <th :class="{red:item.price>1}">{{item.price}}</th>
				<th>{{item.intro}}</th>
				<th>{{item.amount}}</th>
				<th>{{item.goodsType}}</th>
				<th>{{item.remark}}</th>
                <td><a href="javascript:;" @click="del(item.id)">删除</a></td>
              </tr>
             
            </tbody>
            <tfoot>
              <tr>
                <td colspan="4">消费总计: {{totalPrice}}</td>
              </tr>
            </tfoot>
          </table>
        </div>
        
        <!-- 右侧图表 -->
        <div class="echarts-box" id="main"></div>
      </div>
    </div>
    <script src="../echarts.min.js"></script>
    <script src="../vue.js"></script>
    <script src="../axios.js"></script>
    <script>
      /**
       * 接口文档地址:
       * https://www.apifox.cn/apidoc/shared-24459455-ebb1-4fdc-8df8-0aff8dc317a8/api-53371058
       * 
       * 功能需求:
       * 1. 基本渲染
       * 2. 添加功能
       * 3. 删除功能
       * 4. 饼图渲染
       */
      const app = new Vue({
        el: '#app',
        data: {
          list:[],
		  goods:{
			  name:"",
			  price:"",
			  amount:"",
			  intro:"",
			  goodsType:"",
			  remark:""
		  }
		  
        },
		computed: {
		  totalPrice () {
		    return this.list.reduce((sum, item) => sum + item.price, 0)
		  }
		},
		 created() {
			 /* axios.get("http://localhost:8080/list1")
			.then(res=>{
				console.log(res.data);
				this.list=res.data;
			})
			.catch(err=>{
				console.log(err)
			}) */
			this.getlist()
		},
		mounted() {
			this.myChart = echarts.init(document.getElementById("main"));
			this.myChart.setOption(
			{
			  title: {
			    text: '价格结构图',
			    
			    left: 'center'
			  },
			  tooltip: {
			    trigger: 'item'
			  },
			  legend: {
			    orient: 'vertical',
			    left: 'left'
			  },
			  series: [
			    {
			      name: '单价',
			      type: 'pie',
			      radius: '50%',
			      data: [
			        /* { value: 1048, name: 'Search Engine' },
			        { value: 735, name: 'Direct' },
			        { value: 580, name: 'Email' },
			        { value: 484, name: 'Union Ads' },
			        { value: 300, name: 'Video Ads' } */
			      ],
			      emphasis: {
			        itemStyle: {
			          shadowBlur: 10,
			          shadowOffsetX: 0,
			          shadowColor: 'rgba(0, 0, 0, 0.5)'
			        }
			      }
			    }
			  ]
			}
			)
			
		},
		methods:{
			// 查询所有
			getlist(){
				axios.get("http://localhost:8080/list1")
				.then(res=>{
					console.log(res.data);
					this.list=res.data;
					// 更新图表
					this.myChart.setOption({
						series: [
							{
						   /* data: [
						      { value: 1048, name: 'Search Engine' },
						      { value: 735, name: 'Direct' },
						      { value: 580, name: 'Email' },
						      { value: 484, name: 'Union Ads' },
						      { value: 300, name: 'Video Ads' }
						    ] */
							data: this.list.map(item => ({ value: item.price, name: item.name}))
						  }
						  ]
					})
				})
				.catch(err=>{
					console.log(err)
				});
				
				
				
			},
			// 新增
			add(){
				axios.post("http://localhost:8080/add",this.goods)
				.then(res=>{
					console.log(this.goods);
					alert(res.data);
					this.getlist();
					this.goods={};
					/* for(var i in this.goods){
						this.goods[i] = ''
					} */
				})
			},
			// 删除
			del(id){
				if(confirm("确认删除数据?")){
					axios.get("http://localhost:8080/del?id="+id)
					.then(res=>{
						this.getlist();
					})
				}
				
			}
			
		},
		
		
      })
    </script>
  </body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1211718.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

普通测径仪升级的智能测径仪 增添11大实用功能!

普通测径仪能对各种钢材进行非接触式的外径及椭圆度在线检测&#xff0c;测量数据准确且无损&#xff0c;可测、监测、超差提示、系统分析等。在此基础上&#xff0c;为测径仪进行了进一步升级制成智能测径仪&#xff0c;为其增添更多智能化模块&#xff0c;让其使用更加方便。…

mac下vue-cli从2.9.6升级到最新版本

由于mac之前安装了 vue 2.9.6 的版本&#xff0c;现在想升级到最新版本&#xff0c;用官方给的命令&#xff1a; npm uninstall vue-cli -g 发现不行。 1、究其原因&#xff1a;从vue-cli 3.0版本开始原来的npm install -g vue-cli 安装的都是旧版&#xff0c;最高到2.9.6。安…

Mysql删除占用事务的线程

参考&#xff1a;https://www.jianshu.com/p/dd0291391188 产生原因&#xff1a;这个问题的原因是在mysql中产生了事务A&#xff0c;执行了修改的语句&#xff0c;比如&#xff1a; update t1 set aget18 where id1;此时事务并未进行提交&#xff0c;事务B开始运行&#xff0c…

【2015年数据结构真题】

用单链表保存m个整数&#xff0c;结点的结构为 [data] [link]&#xff0c;且|data|<n(n为正整数)。现要求设计一个时问复杂度尽可能高效的算法&#xff0c;对于链表中 data 的绝对值相等的结点&#xff0c;仅保留第一次出现的结点而删除其余绝对值相等的结点。例如&#xff…

HackTheBox-Starting Point--Tier 2---Unified

文章目录 一 Unified 测试过程1.1 打点1.2 权限获取1.3 权限提升 二 题目 一 Unified 测试过程 1.1 打点 1.端口扫描 nmap -sV -sC 2.访问8080端口 页面跳转到&#xff1a;https://10.129.96.149:8443/manage/account/login?redirect%2Fmanage   观察到版本号为unifi 6.4.5…

Java GUI小程序之图片浏览器

以下是一个简单的图片浏览器示例代码&#xff0c;它包含了图片放大缩小、拖拽、上一张/下一张查看等功能。你可以根据它进行扩展&#xff0c;提高用户体验。 import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.e…

Copliot:让你一秒变身网页达人的神奇助手

Copliot&#xff1a;一款能够帮助你快速理解网页内容的智能助手 你是否有过这样的经历&#xff0c;当你浏览网页时&#xff0c;遇到了一些你不太了解的内容&#xff0c;比如一些专业术语&#xff0c;一些复杂的概念&#xff0c;或者一些有趣的话题&#xff1f;你是否想要快速地…

【深度学习 | 核心概念】那些深度学习路上必经的核心概念,确定不来看看? (六)

&#x1f935;‍♂️ 个人主页: AI_magician &#x1f4e1;主页地址&#xff1a; 作者简介&#xff1a;CSDN内容合伙人&#xff0c;全栈领域优质创作者。 &#x1f468;‍&#x1f4bb;景愿&#xff1a;旨在于能和更多的热爱计算机的伙伴一起成长&#xff01;&#xff01;&…

Android问题笔记四十五:解决SeekBar操作thumb周围产生的圆形阴影/灰色阴影/白色圆圈的解决办法

点击跳转专栏>Unity3D特效百例点击跳转专栏>案例项目实战源码点击跳转专栏>游戏脚本-辅助自动化点击跳转专栏>Android控件全解手册点击跳转专栏>Scratch编程案例点击跳转>软考全系列点击跳转>蓝桥系列点击跳转>ChatGPT和AIGC &#x1f449;关于作者 专…

登上CMMLU性能评测榜单第一 四大维度解码夸克自研大模型

11月14日&#xff0c;拥有千亿参数的夸克自研大模型正式发布&#xff0c;立刻占据CMMLU榜单第一名。夸克大模型将应用于通用搜索、医疗健康、教育学习、职场办公等多个场景。性能方面&#xff0c;其整体水平已经超过GPT-3.5&#xff0c;其中在写作、考试等部分场景中可以超过GP…

Shopee可以绑定大陆银行卡吗?Shopee收款方式选哪种?——站斧浏览器

shopee可以绑定大陆银行卡吗&#xff1f; 对于中国大陆的卖家而言&#xff0c;他们希望能够在Shopee上绑定自己的大陆银行卡&#xff0c;方便进行交易和收款。然而&#xff0c;目前的情况是Shopee并不支持直接绑定大陆银行卡。这主要是因为Shopee在中国大陆并不是主要运营的电…

成本2元开发游戏,最快3分钟完成!全程都是AI智能体“打工”,大模型加持的那种

金磊 发自 凹非寺 量子位 | 公众号 QbitAI 家人们&#xff0c;OpenAI前脚刚发布自定义GPT&#xff0c;让人人都能搞开发&#xff1b;后脚国内一家大模型初创公司也搞了个产品&#xff0c;堪称重新定义开发——让AI智能体们协作起来&#xff01; 只需一句话&#xff0c;最快3分…

ubuntu 18.04安裝QT+PCL+VTK+Opencv

资源 qt5.14.1:qt5.14.1.run opencv4.5.5:opecv4.5.5压缩包 1.国内换中科大源&#xff0c;加快下载速度 cd /etc/apt/ sudo gedit sources.list 替换成如下内容 deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirro…

kubernetes集群编排(11)

目录 k8s etcd 备份 恢复 k8s etcd [rootk8s2 etcd]# scp -r /etc/kubernetes/pki/etcd/ k8s1: 备份 从镜像中拷贝etcdctl二进制命令 [rootk8s2 ~]# docker run -it --rm reg.westos.org/k8s/etcd:3.5.4-0 sh输入ctrlpq快捷键&#xff0c;把容器打入后台 获取容器id [rootk8s2 …

数据分析场景下,企业如何做好大模型选型和落地?

在数据驱动的数字化时代&#xff0c;有效的数据分析已成为企业成功的关键因素。而随着大模型带来能力突破&#xff0c;让AI与数据分析相互结合&#xff0c;使分析结果更好支撑业务&#xff0c;促进企业内部数据价值释放&#xff0c;成为了当下企业用户尤为关注的话题。 如何按照…

区域入侵AI算法如何应用在工地场景,保卫工地施工安全?

在工地、厂区等施工场所&#xff0c;安全保障是必不可少的&#xff0c;特别是在人工智能技术日益成熟的今天&#xff0c;如何利用旭帆科技AI智能视频中的区域入侵算法助力智慧工地、保障工地安全呢&#xff1f; 1、建筑物周界安全 TSINGSEE青犀区域入侵算法可以用于监控建筑物…

音画欣赏|《纯洁的梦乡》

《纯洁的梦乡》 80x60cm 陈可之2021年绘 题龙阳县青草湖 【元】唐温如 西风吹老洞庭波&#xff0c;一夜湘君白发多。 醉后不知天在水&#xff0c;满船清梦压星河。 车遥遥篇 【宋】范成大 车遥遥&#xff0c;马憧憧。 君游东山东复东&#xff0c;安得奋飞逐西风。 愿我如星…

SARAS多步TD目标算法

SARAS多步TD目标算法 代码仓库:https://github.com/daiyizheng/DL/tree/master/09-rl SARSA算法是on-policy 时序差分 在迭代的时候&#xff0c;我们基于 ϵ \epsilon ϵ-贪婪法在当前状态 S t S_t St​ 选择一个动作 A t A_t At​ &#xff0c;然后会进入到下一个状态 S…

从HTTP到Tomcat:揭秘Web应用的底层协议与高性能容器

WEB服务器 1. HTTP协议1.1 HTTP-概述1.1.1 介绍1.2.2 特点 2.2 HTTP-请求协议2.3 HTTP-响应协议2.3.1 格式介绍2.3.2 响应状态码 2.4 HTTP-协议解析 2. WEB服务器-Tomcat2.1 简介2.1.1 服务器概述2.1.2 Web服务器2.1.3 Tomcat 2.2 基本使用2.2.1 下载2.2.2 安装与卸载2.2.3 启动…

nestJs(二)node项目发送请求

整体演示 Get 请求参数 Get 请求的参数一般会放在 URL 上&#xff0c;这只需要Query 装饰器就行了。 Post 参数 Post 参数有些不同&#xff0c;会用到 DTO 的传输。因为数据通过 HTTP 传输是文本类型&#xff0c;因此需要将文本类型转化成代码可识别的变量。 新建 students…