此段代码导出excel功能在swagger里调试可以下载正常打开excel,从前台页面调用接口时确无法打开文件报错信息如下,打开之后也是一堆乱码
一开始以为时用流传输,转化的流出现了问题,可是swagg能打开说明流没有问题,于是猜测是和前台进行交互的过程中出现问题,仔细排查后发现前端传参用的是Post而后端用的是Get,统一Get传参后问题解决
———————————————————————————————————————————
在编写过程中经常遇到的报错:
NullPointerException: null 空指针
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null
总结了一下这个报错我遇到的原因有以下几点:
1、字符串变量未初始化
2、接口类型的对象没有用具体的类初始化
3、当一个对象的值为空时,没有判空
Unparseable date: "XXXX"
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.text.ParseException: Unparseable date: "202004"] with root cause java.text.ParseException: Unparseable date: "202004"
原因:数据库存储的字段数据类型与传过来的数据类型不一样
Parameter 'XXXX' not found. Available parameters are [XXX, param1]
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'job_id' not found. Available parameters are [userinformation, param1]] with root cause org.apache.ibatis.binding.BindingException: Parameter 'job_id' not found. Available parameters are [userinformation, param1]
参数传递错误,出现的原因:接口方法没用@Param注解
For input string: "XXX"
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NumberFormatException: For input string: "string"] with root cause java.lang.NumberFormatException: For input string: "string"
参数类型转换时报错:把不符合数字格式的字符串转换为数字时抛出的格式化异常;
Expected one result (or null) to be returned by selectOne(), but found: XX
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 12] with root cause org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 12
实际的返回数据条数超出设定的返回条数
Invalid bound statement (not found)
ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.httech.hrms.mapper.cdp.PromotionInfoMapper.getAllInformationWithErr] with root cause org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.httech.hrms.mapper.cdp.PromotionInfoMapper.getAllInformationWithErr
原因:xml里面的namespace不对 或者id和mapper里面的方法名不一样,或者parameterType对应不上
---------------------------------------------------------------------------------------------------------------------------
2021/12/8
pom文件不能随便改
要善用工具类(列表判空要用
CollectionUtil.isEmpty(list)
不能用list.size==0
如果list==null 则会报错
)
多个字段list拼接为一个字段list
list1.forEach(i ->{ list2.add(i.getZ013_015_SAP_MATNR()); list2.add(i.getZ019_SAP_MATNR()); list2.add(i.getDC_SAP_MATNR()); });
一个service层只能调用一个数据源,如果要操作其他数据源要调用其他service层
配置主数据源后service层要用@DS注解切换数据源
-----------------------------------------------------------------------------------------------------------
遍历list时不能对原List进行操作修改,无论是删除和添加,因为如果在遍历中一直向集合中新增加元素,会造成死循环的,还有就是如果在遍历过程中删除元素,会造成数组下表越界等问题。
要先创建一个临时集合然后再通过遍历将需要移除的元放到临时集合中,最后再整体从原始集合中删除。