背景:使用postman模拟请求
问题1:controller中可以注入service层,service中的Dao层注入为null(在Dao层加了@Mapper注解,在Application加了@MapperScan还是不行)。
解决1:https://www.cnblogs.com/nongzihong/p/11350308.html
使用了第一种加@PostConstruct方法解决。
问题2:Invalid bound statement (not found)
解决2:是找不到mapper导致的。先排除application.yml配置中的mybatis-mapper-locations的路径是否是mapper.xml的路径。检查target的classes里有没有打包进去。xml的namespace路径对不对,最后再检查dao的方法是否存在,传参类型,返回类型有没有加,对不对。
问题3:插入数据库报错,Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #10 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型1111
解决3:看报错信息,#10,说明第10个参数不对,检查参数值是null,数据库表字段允许为空。检查xml中的参数名和传递的参数名,正确。在xml中,参数后面加jdbcType=VARCHAR eg:#{id,jdbcType=VARCHAR},问题解决。