当前位置: 首页 > news >正文

基于springboot+mybatis+vue的项目实战之页面参数传递

如图所示,删除操作可以用按钮实现,也可以用超链接来实现。

1、第一种情况,用按钮实现。

html页面相关:

 <button type="button" @click="deleteId(peot.id)">删除</button>

<script>new Vue({el:"#app",data() {return {peotList:[]}},methods:{findAll:function () {var _this = this;axios.post('/findAllJsoon', {}).then(function (response) {_this.peotList = response.data.data;//响应数据给peotList赋值}).catch(function (error) {console.log(error);});},deleteId:function (id) {var _thisd = this;if (window.confirm("确定要删除该条数据吗???")){axios.post('/deletePeot?id='+id).then(function (response) {alert("删除成功")_thisd.findAll();}).catch(function (error) {console.log(error);});}}},created() {// 获得参数id值// this.id = location.href.split("?id=")[1]// 通过id查询详情this.findAll();},})</script>

controller文件相关:

 @RequestMapping("/deletePeot")public void deletePeot(Integer id){peotService.deletePeot(id);}

可以看到,这里的controller文件中没有进行参数传递。这是因为,是在当前页面操作,参数直接传递给js,不需要通过url来传递。

2、第二种情况,通过超链接来删除,并跳转回查询所有的页面。

<a :href="'peot_delete.html?id='+peot.id">删除</a>
peot_delete.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><script src="./js/vue.js"></script><script src="./js/axios-0.18.0.js"></script></head>
<body>
<h1 align="center">诗人信息列表</h1>
<div id="app" align="center"><a href="peot_insert.html">新增</a><table  border="1"><tr><th>id</th><th>author</th><th>gender</th><th>dynasty</th><th>title</th><th>style</th><th>操作</th></tr><tr v-for="peot in peotList"><td>{{peot.id}}</td><td>{{peot.author}}</td><td>{{peot.gender}}</td><td>{{peot.dynasty}}</td><td>{{peot.title}}</td><td>{{peot.style}}</td><td><button type="button" @click="deleteId(peot.id)">删除</button><a :href="'peot_delete.html?id='+peot.id">删除</a><a :href="'peot_edit.html?id='+peot.id">修改</a></td></tr></table>
</div></body><script>new Vue({el:"#app",data() {return {peotList:[]}},methods:{findAll:function () {var _this = this;axios.post('/findAllJsoon', {}).then(function (response) {_this.peotList = response.data.data;//响应数据给peotList 赋值}).catch(function (error) {console.log(error);});},deleteId:function (id) {var _thisd = this;var url = `deletePeot_url/${this.id}`  //注意这里是反引号if (window.confirm("确定要删除该条数据吗???")){axios.post(url).then(function (response) {alert("删除成功")// _thisd.findAll();location.href = 'peot_listAll.html'}).catch(function (error) {console.log(error);});}}},created() {// 获得参数id值this.id = location.href.split("?id=")[1]// 通过id查询详情this.deleteId();},})</script></html>

controller页面相关:

    @RequestMapping("/deletePeot_url/{id}")public void deletePeot_url(@PathVariable("id") Integer id){peotService.deletePeot(id);}

可以看出,这里的controller是使用标准@PathVariable("id")进行了参数传递。

3、总结

从一个页面到另外一个页面,如果需要传递参数,需要在controller文件中进行相关的操作。

有关参数的传递,参见文章:Springboot之页面参数传递-CSDN博客

http://www.lryc.cn/news/348413.html

相关文章:

  • CSS-浮动
  • MFC:字符串处理
  • 虚拟仿真云平台在教育应用中的优势和意义
  • CPU的的处理流程如何快速记忆
  • AI视频教程下载:基于OpenAl、LangChain、 Replicate开发AI应用程序
  • 【C++】继承相关(基类与派生类的继承关系以及细节整理)
  • 【Web后端】监听器Listener
  • C/C++ 初级球球大作战练手
  • ES6之字符串的扩展
  • 微信小程序开发,构建NPM报错解决
  • 【异常】SpringBoot整合RabbitMQ-发送消息报错
  • 通过钉钉卡片进行工单审批
  • C语言中的控制语句:深入解析与案例实践2
  • 【ARM Cortex-M 系列 2.1 -- Cortex-M7 Debug system registers】
  • 深入解析C#中的async和await关键字
  • 【VUE.js】前端框架——未完成
  • 开源的文件压缩和解压缩软件7-Zip
  • 搜维尔科技:Patchwork 3D 新功能:爆炸视图动画
  • Redis——RedLock、Zookeeper及数据库实现分布式锁
  • OpenSSL自签证书并基于Express搭建Web服务进行SSL/TLS协议分析
  • 记录一次 vue2 前端项目整合过程
  • 物联网五层架构分析
  • 【Java EE】多线程(三)线程状态
  • FFmpeg常用API与示例(一)—— 工具库篇(av_log、AVDictionary、avio)
  • 日志的基本用法
  • 什么是页分裂、页合并?
  • 软件2班20240513
  • 嵌入式学习-时钟树
  • 对博客系统基本功能进行自动化测试(Junit + Selenium)
  • 《换你来当爹》:AI驱动的养成游戏,探索虚拟亲子关系的新模式