为什么前端传的值后端获取不到,大神帮看看

心大自然宽 2020-11-24 11:03:11
xml
<!--搜索 '%?%'-->
<select id="searchbox" resultType="com.my.domain.testpojo">
SELECT * FROM time WHERE (title LIKE '%?%') OR (sub_title LIKE '%?%')

</select>
mapper
//搜索 ,@Param("sub_title")String sub_title
public List<testpojo> searchbox(@Param("title")String title);
Service
public List<testpojo> searchbox(String title) {

List<testpojo> time3 = apiMapper.searchbox(title);
System.out.println("123456"+time3);
System.out.println("852"+time3);
return time3;

}
controller
@RequestMapping(value = "/searchbox",method =RequestMethod.POST )
public List<testpojo> searchbox(HttpServletRequest request, HttpServletResponse response) {

response.setContentType("text/html;charset=utf-8");
/* 设置响应头允许ajax跨域访问 */
response.setHeader("Access-Control-Allow-Origin", "*");
/* 星号表示所有的异域请求都可以接受, */
response.setHeader("Access-Control-Allow-Methods", "GET,POST");

String formData = request.getParameter("formData");

List<testpojo> time3= apiService.searchbox(formData);
System.out.println("搜索====="+time3);
return time3;

}

这是前端小程序的
wx.request({

url: 'http://localhost:8089/api/searchbox' ,
data:{
formData:formData
},
method: "POST",
header: { 'content-type': 'application/x-www-form-urlencoded"' },

success: function (res) {
console.log(res.data)
that.setData({
re: res.data,
})

wx.showToast({
title: '已提交',
icon: 'success',
duration: 2000
})
}
})

123456[]
852[]
搜索=====[]
取不到值,是哪里错了,求大神帮指点

...全文
3661 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你打开F12看看请求带的有数据嘛,还有就是数据格式对嘛,有可能后端写错了呢
萧仁武 2020-11-25
  • 打赏
  • 举报
回复
你这个提交方式,把请求方式改为get试一下吧
心大自然宽 2020-11-25
  • 打赏
  • 举报
回复
引用 3 楼 Xiang_Gg 的回复:
修改一下mapper文件xml 把' %?%' 改为 "%"#{title}"%"
这个对了,改成''号就好
  • 打赏
  • 举报
回复
引用 3 楼 Xiang_Gg 的回复:
修改一下mapper文件xml 把' %?%' 改为 "%"#{title}"%"
Xiang_Gg 2020-11-25
  • 打赏
  • 举报
回复
修改一下mapper文件xml 把' %?%' 改为 "%"#{title}"%"

50,503

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧