springboot+mybatis-plus集成swagger开发

1.mybatisplus报Invalid bound statement (not found)错误的解决方法 

解决方法:检查application.yml配置文件中mybais-plus的配置是否正确。

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

mybatis-plus:
  # 禁止大写变小写时自动添加下划线
  map-underscore-to-camel-case: false
  log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mybatis/*Mapper.xml

mybatis-plus 的配置要从spring中独立出来,否则会报错。

MybatisPlus报错:BindingException: Invalid bound statement (not found): com...XxxMapper.insert_Stephen·You的博客-CSDN博客_mybatisplus bindingexception: invalid bound statem

2.org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决方案: swagger2 和springboot的版本是否不兼容,降低swagger的版本,修改yml配置;

Spring Boot版本Swagger 版本
2.6.53.0.0

解决方案之‘Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoi_技术宅星云的博客-CSDN博客

修改application.yml 配置:

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

【swagger2】Spring Boot 配置swagger2_Ryan-Ren的博客-CSDN博客_springboot配置swagger2

3. javaweb下载文件时中文名称乱码,在网上查了很多资料,对文件名称进行了url编码处理,但是在swagger接口上下载文件后,文件名称还是编码后的乱码文件名,通过升级swagger版本由2升级为3后,问题解决。下载代码如下:


    public ResponseEntity<byte[]> download(String fileName) {
        ResponseEntity<byte[]> responseEntity = null;
        InputStream in = null;
        ByteArrayOutputStream out = null;
        try {
            in = new FileInputStream(fileName);
            out = new ByteArrayOutputStream();
            IOUtils.copy(in, out);
            //封装返回值
            byte[] bytes = out.toByteArray();
            HttpHeaders headers = new HttpHeaders();
            try {
                File file = new File(fileName);
                fileName = file.getName();
                fileName = URLEncoder.encode(fileName, "UTF-8");

                headers.add("Content-Disposition", "attachment;filename=" + fileName);
            } catch (Exception e) {
                e.printStackTrace();
            }
            headers.setContentLength(bytes.length);
            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
            headers.setAccessControlExposeHeaders(Arrays.asList("*"));

            responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseEntity;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值