项目异常统计

标题SQLException:数据库SQL异常

Cause: java.sql.SQLException: Illegal mix of collations (utf16_general_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation 'UNION'
; uncategorized SQLException; SQL state [HY000]; error code [1267]; Illegal mix of collations (utf16_general_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation 'UNION'; nested exception is java.sql.SQLException: Illegal mix of collations (utf16_general_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation 'UNION'

在这里插入图片描述
查资料知道是多表联查过程中,设计表时字符串varchar类型字段选择编码方式时不一致导致的:(utf16_general_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT)
解决方式:统一2个数据库的编码格式
GlobalExceptionHandler : Springboot全局异常处理GlobalExceptionHandler

二:请求方式错误

	Request method 'GET' not supported错误:{}
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

在这里插入图片描述

解决后:在这里插入图片描述

三:MySQLIntegrityConstraintViolationException

1.意思是违反了数据库的完整性约束,在表中建立了唯一索引

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'state' in where clause is ambiguous
; ]; Column 'state' in where clause is ambiguous; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'state' in where clause is ambiguous 

在这里插入图片描述
2.异常原因:
仔细分析一下,原来就是是因为插入的新数据,与表的主键唯一约束产生了冲突,也就是新数据的主键在表中已经存在了,不能重复插入同样的数据
3.解决方法:
1.第一种方案,将表中原有的相关记录删除,再重新插入即可;
2.第二种方案,可以考虑修改表的主键约束(不建议修改原有约束)。
3.第三种方案,检查sql语句

四.前端解析参数错误:

在这里插入图片描述@ResponseBody
@PostMapping(“updateState”)
@ApiOperation(“手动更新执行排产单状态”)
public R updateApsPlanState(@RequestBody List planNumberList){
apsPlanService.updateApsPlanState(planNumberList);
return R.ok();
}

@PostMapping(value = "exportPlanDetail", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ApiOperation("导出排产产品信息")
public R exportPlanDetail(@RequestBody ExportPo exportPo, HttpServletResponse response){
    apsPlanService.exportPlanDetail(exportPo.getPlanNumber(), exportPo.getLine(), response);
    return R.ok();
}

接口做的是数据库查询数据导出到Excel表操作,开始我想的是导出完成以后给前端一个Code值,一个返回值信息。

public void exportPlanDetail(String planNumber,String line, HttpServletResponse response) {
        String sheetName = StrUtil.format("{}{}排产详情表", planNumber, line);
        String fileName = StrUtil.format("{}{}.xlsx", planNumber, line);
        List<CommonParse> commonParseList = commonParseDao.selectList(new LambdaQueryWrapper<CommonParse>()
                .eq(CommonParse::getPlanNumber, planNumber).eq(CommonParse::getLinePlan, line));
        CustomException.throwByList(commonParseList, "获取排产信息失败,请稍后重试");
        SXSSFWorkbook wb = FileUtil.createEuropeanFile(commonParseList,sheetName);
        OutputStream os = null;
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
            response.setHeader("content-Type","application/vnd.ms-excel");
            response.setCharacterEncoding("UTF-8");
            os = response.getOutputStream();
            wb.write(os);
            os.flush();
        } catch (Exception e) {
            log.warn("导出",e);
        }finally {
            if (wb != null){
                wb.dispose();
            }
            try {
                if (os != null){
                    os.close();
                }
            } catch (IOException e){
                log.warn("导出",e);
            }
        }
    }

但业务层这里已经把返回值的参数类型重新定义了,造成上述的BUG,结果虽然正确,但日志服务报错。

在这里插入图片描述

修复这个BUG,不要返回值即可

   @PostMapping(value = "exportPlanDetail", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ApiOperation("导出排产产品信息")
    public void exportPlanDetail(@RequestBody ExportPo exportPo, HttpServletResponse response){
        apsPlanService.exportPlanDetail(exportPo.getPlanNumber(), exportPo.getLine(), response);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值