mybatis使用逆向工程出现重复错误
异常报告:
Error creating bean with name ‘org.mybatis.spring.SqlSessionFactoryBean#0’ defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [D:\JAVA\IdeaProjects\Maven_SSM\target\classes\mapper\DepartmentMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.at.dao.DepartmentMapper.BaseResultMap
分析原因:
查看逆向工程生成mapper的xml,由于没有删除上次使用逆向工程的xml文件,导致再次运行逆向工程后,会在原来基础上添加,导致sql语句的id重复,故而出错。只要删除重复部分即可,或在每次使用逆向工程前删除上次生成的也行。