这是vue中的前端代码axios({ method: 'get', url: '/BookShopSystem_war/getQueryBook/' + bookName <select id="getQueryBook" parameterType="String" resultMap="bookResult"> select * from book where book_name like CONCAT('%',#{bookName},'%') </select> 传递的bookName是String但最后会乱码导致查询不到书籍,如何解决

时间: 2024-04-01 20:36:33 浏览: 16
出现乱码的原因可能是因为在HTTP请求中未对参数进行编码。我们可以使用JavaScript的encodeURIComponent()函数来对参数进行编码,以确保它们被正确地传输。 在你的代码中,将`/BookShopSystem_war/getQueryBook/' + bookName`替换为`/BookShopSystem_war/getQueryBook/' + encodeURIComponent(bookName)`应该可以解决你的问题。这将对bookName进行编码,使其在HTTP请求中正确传输,从而避免了出现乱码。
相关问题

<div class="layui-tab-content layui-row layui-col-space30"> <div class="layui-col-xs3" v-for="(collect, index) in collectBook" :key="index"> <div class="goods"> <a :href="'detail?id='+collect.bookId"> <img :src="'/BookShopSystem_war/' + collect.image1"> </a> <p>{{ collect.bookName }}</p> <p class="price">¥{{ collect.bookPrice }}</p> <button @click="delCollect()"> <span class="del">&times;</span> </button> </div> </div> </div> new Vue({ el: "#app", data: { userId: '', collectBook: [] }, mounted() { var _this = this; axios.get('/BookShopSystem_war/getUserId') .then((response) => { this.userId = response.data; var userId = this.userId; // 将userId赋值给一个变量 axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getCollectBook/' + userId }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 200) { _this.collectBook = data; } console.log(data) }) }) .catch((error) => { console.log(error); }); }, methods: { delCollect() { var _this = this; axios({ method: "delete", url: "http://localhost:8080/BookShopSystem_war/deleteCollect", data: { userId: _this.userId, bookId: _this.collectBook.bookId } }).then(resp => { alert("取消收藏"); }) } }该取消收藏方法有错,给出原因并纠正

在 `delCollect()` 方法中,`_this.collectBook.bookId` 是错误的,因为 `collectBook` 是一个数组,而不是一个单独的对象。另外,通过 `v-for="(collect, index) in collectBook"` 循环遍历 `collectBook` 数组,所以应该在 `delCollect()` 方法中传递 `collect.bookId` 作为参数,以便正确删除相应的收藏。以下是修改后的代码: ``` delCollect(bookId) { var _this = this; axios({ method: "delete", url: "http://localhost:8080/BookShopSystem_war/deleteCollect", data: { userId: _this.userId, bookId: bookId } }).then(resp => { alert("取消收藏"); // 从 collectBook 数组中移除被删除的收藏 _this.collectBook = _this.collectBook.filter(collect => collect.bookId !== bookId); }); } ``` 在模板中,需要将 `delCollect()` 方法调用中的参数改为 `collect.bookId`: ``` <button @click="delCollect(collect.bookId)"> ```

这是前端代码 <div class="layui-tab-content layui-row layui-col-space30"> <div class="layui-col-xs3" v-for="(collect, index) in collectBook" :key="index"> <div class="goods"> <a :href="'detail?id='+collect.bookId"> <img :src="'/BookShopSystem_war/' + collect.image1"> </a> <p>{{ collect.bookName }}</p> <p class="price">¥{{ collect.bookPrice }}</p> <button @click="delCollect(collect.bookId)"> <span class="del">×</span> </button> </div> </div> </div> new Vue({ el: "#app", data: { userId: '', collectBook: [] }, mounted() { var _this = this; axios.get('/BookShopSystem_war/getUserId') .then((response) => { this.userId = response.data; var userId = this.userId; // 将userId赋值给一个变量 axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getCollectBook/' + userId }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 200) { _this.collectBook = data; } console.log(data) }) }) .catch((error) => { console.log(error); }); }, methods: { delCollect(bookId) { var _this = this; axios({ method: "delete", url: "http://localhost:8080/BookShopSystem_war/deleteCollect", data: { userId: _this.userId, bookId: bookId } }).then(resp => { alert("取消收藏"); // 从 collectBook 数组中移除被删除的收藏 _this.collectBook = _this.collectBook.filter(collect => collect.bookId !== bookId); 请分析逻辑是否有误

这段前端代码主要是用于展示用户收藏的图书列表,其中通过 v-for 指令循环遍历用户收藏的每一本图书,展示图书的封面、名称和价格,并且为每一本图书提供了一个取消收藏的按钮。 在 mounted 钩子函数中,通过获取用户的 ID,调用后台接口获取该用户收藏的图书列表,并将数据赋值给 collectBook 数组,用于在页面中展示用户收藏的图书。 delCollect 方法用于取消用户收藏的图书,点击取消收藏按钮后,将调用后台接口将该图书从用户收藏的列表中删除,并且从 collectBook 数组中移除被删除的图书,最后弹出取消收藏的提示框。 逻辑上没有明显的错误,但是需要注意的是,由于涉及到与后台接口的交互,需要在后台接口中进行相应的安全性校验,以保证数据的安全。

相关推荐

0"> {{bk.bookName}} ¥{{bk.bookPrice}} //列表页——分页 layui.use(['laypage'], function () { var laypage = layui.laypage; laypage.render({ elem: 'houseList' , count: 25 , limit: 5 , theme: '#daba91' , layout: ['page', 'next'] }); }); Vue.config.productionTip = false //阻止vue在启动时生成生产提示 new Vue({ el: "#app", data() { return { bookAll: [] } }, mounted() { var _this = this; axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getBookAll' }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 0) { _this.bookAll = data; } console.log(data) }) } })已省略部分代码,数据都可遍历出来,如何实现分页功能

{{ data.bookName }} {{ data.bookAuthor }} {{ data.bookPublish }} {{ data.price }} <input type="text" :value="data.num" readonly class="cOnt"> ¥{{data.total}} 删除 new Vue({ el: '#app', data: { userId: '', list: [] // list: [ // {userId:null,bookName:"图书1",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2}, // {userId:null,bookName:"图书2",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:1}, // {userId:null,bookName:"图书3",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2} // ] }, //选择或不选择一项 $(".xzWxz").click(function () { if ($(this).hasClass("on")) { $(this).removeClass("on"); } else { $(this).addClass("on"); } var ty = $(".xzWxz.on").length; $(".sXd1").find("font").html(ty); if (ty == es) { $(".ifAll").addClass("on"); } else { $(".ifAll").removeClass("on"); } jsZj(); }); 当我使用未被注释的list, 该代码点击后没有变化,而我使用注释的静态list数组,该代码点击有变化,为什么,未注释的list是能获取到数据并遍历了出来,如何解决

最新推荐

recommend-type

解决vue net :ERR_CONNECTION_REFUSED报错问题

主要介绍了解决vue net :ERR_CONNECTION_REFUSED报错问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

解决vue2中使用axios http请求出现的问题

使用axios处理post请求时,出现的问题解决 默认情况下: axios.post(url, params).then(res =&gt; res.data); 当url是远程接口链接时,会报404的错误: Uncaught (in promise) Error: Request failed with status code...
recommend-type

vue项目中axios请求网络接口封装的示例代码

主要介绍了vue项目中axios请求网络接口封装的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

vue+ts下对axios的封装实现

主要介绍了vue+ts下对axios的封装实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

vue+axios实现文件下载及vue中使用axios的实例

主要介绍了vue+axios实现文件下载及vue中使用axios的实例,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。