保存信息 是找不到对应的方法
在invoke方法组装sqlmand的时候,MappedStatement没有组装成功,始终是0
解决方法:
将mybatis的sqlSessionFactory替换成mybatis-plusd的MybatisSqlSessionFactoryBean
//原配置文件
package com.mybatis.plus.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = "com.mybatis.plus.mapper.mds", sqlSessionTemplateRef = "firstSqlSessionTemplate")
public class DB1DataSourceConfig {
@Bean(name = "firstDataSource")
@ConfigurationProperties(prefix = "spring.datasource.durid.db1")
public DataSource testDataSource() {
return DataSourceBuilder.create().build();
}
// 原配置,需要替换SqlSessionFactory
@Bean(name = "firstSqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("firstDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/ssj/*.xml"));
return bean.getObject();
}
@Bean(name = "firstTransactionManager")
public DataSourceTransactionManager testTransactionManager(@Qualifier("firstDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "firstSqlSessionTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("firstSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
// 替换以后配置文件
package com.mybatis.plus.config;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
@MapperScan(basePackages = "com.mybatis.plus.mapper*", sqlSessionTemplateRef = "firstSqlSessionTemplate")
public class DBmdsDataSourceConfig {
@Bean(name = "firstDataSource")
@ConfigurationProperties(prefix = "spring.datasource.druid.mds")
public DataSource testDataSource() {
DataSource d = DruidDataSourceBuilder.create().build();
return DruidDataSourceBuilder.create().build();
}
@Bean(name = "firstSqlSessionFactory")
public MybatisSqlSessionFactoryBean testSqlSessionFactory(@Qualifier("firstDataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean ();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mds/*.xml"));
return bean;
}
@Bean(name = "firstTransactionManager")
public DataSourceTransactionManager testTransactionManager(@Qualifier("firstDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "firstSqlSessionTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("firstSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}