从0到1项目解决问题经验-JAVA后端

问题1:


org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): net.pingfang.esm.feature.auth.service.LoginService.login


解决方案:


可能是因为MapperScan写的配置不对。当我用
 

@MapperScan(basePackages = {"net.pingfang.esm.feature.*.mapper"}, sqlSessionFactoryRef = "masterSqlSessionFactory")
这种方式就能正确调用接口,但是用
@MapperScan(basePackages = {"net.pingfang.esm.feature.**"}, sqlSessionFactoryRef = "masterSqlSessionFactory")

这种方式就会报错

原因分析:
扫描范围扩大后,可能会引入其他配置冲突。例如,不同的 Mapper 接口可能依赖不同的 SqlSessionFactory,而 @MapperScan 里指定了 sqlSessionFactoryRef = "masterSqlSessionFactory",可能会造成某些 Mapper 接口无法正确绑定到对应的 SqlSessionFactory。

问题2:

后端添加的请求头数据,前端一直拿不到,打印日志一直是undefined

后端代码如下:
 

response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, StandardCharsets.UTF_8.name()));
response.addHeader("test", "testCode");

前端代码如下:

const test = response.headers['test'];
const test2 = response.headers.get('test');
const contentDisposition = response.headers.get('content-disposition');
const contentDisposition2 = response.headers.get('Content-Disposition');
const contentDisposition3 = response.headers.get('contentDisposition');
console.log('test===', test);
console.log('test2===', test2);
console.log('contentDisposition===', contentDisposition);
console.log('contentDisposition2===', contentDisposition2);
console.log('contentDisposition3===', contentDisposition3);

报错信息如下:

解决方案:
 

// 允许前端访问的响应头-否则前端拿不到需要的请求头数据
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition, test");

问题分析
  1. 跨域问题:若前后端的域名、端口或者协议不同,浏览器会遵循同源策略,限制对响应头的访问。
  2. CORS 配置问题:服务器端要设置 Access-Control-Expose-Headers 响应头,以此告知浏览器哪些自定义响应头可以被访问。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Oliver_LaVine

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值