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