在给用Mybatis逆向生成的JavaBean添加上无参构造器和全参构造器后,:
测试给数据库增删改查时,出现了报错问题:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\JavaCode\furn-ssm\target\classes\mapper\FurnMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [E:\JavaCode\furn-ssm\target\classes\mapper\FurnMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for furn.dao.FurnMapper.BaseResultMap
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\JavaCode\furn-ssm\target\classes\mapper\FurnMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [E:\JavaCode\furn-ssm\target\classes\mapper\FurnMapper.xml]’. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for furn.dao.FurnMapper.BaseResultMap
报错原因:
自己闲的没事逆向了很多次,每次虽然JavaBean和JavaBeanExample都会重新覆盖,但是mapper下的FurnMapper.xml文件不会重新覆盖,而是在原来的基础上继续append。
这样就相当于在FurnMapper.xml文件中有很多重复的东西,其中一个就是BaseResultMap。
解决方法
所以需要你把FurnMapper.xml删除,然后重新逆向一下。然后重新添加无参和全参构造器。然后就直接去增删改查就可以了
不需要点多次的逆向。