切换springboot框架数据映射不到
来源:15-8 Echarts的动态化验证
qq_小萌新iii_0
2020-06-26
老师,我在使用ssm切换成springboot框架的时候,遇到结果集数据映射不到,启动springboot应用没有报错,然后我的bean实体的属性名和数据库的列名是一致的,当我执行查询返回一个集合,集合里面有对象,记录的大小也没错,但是集合里面的所有对象都是空的,导致数据都为null,不知道出啥问题了?恳望老师帮忙解决一下!!!(ps:数据库的表的列名和我实体的属性名是一致,反复检查了几遍)
写回答
1回答
-
同学好,是不是映射配置不对呀,对比一下SSM形态和后面的springboot形态,控制台输出的sql是否一致,然后同学说的集合为null,是否进行过比对,可以提供一下相关的截图,最好有SSM和springboot的比较。然后对比下dao的配置
SessionFactoryConfiguration.java
package com.imooc.o2o.config.dao; import java.io.IOException; import javax.sql.DataSource; import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @Configuration public class SessionFactoryConfiguration { // mybatis-config.xml配置文件的路径 private static String mybatisConfigFile; @Value("${mybatis_config_file}") public void setMybatisConfigFile(String mybatisConfigFile) { SessionFactoryConfiguration.mybatisConfigFile = mybatisConfigFile; } // mybatis mapper文件所在路径 private static String mapperPath; @Value("${mapper_path}") public void setMapperPath(String mapperPath) { SessionFactoryConfiguration.mapperPath = mapperPath; } // 实体类所在的package @Value("${type_alias_package}") private String typeAliasPackage; @Autowired private DataSource dataSource; /** * 创建sqlSessionFactoryBean 实例 并且设置configtion 设置mapper 映射路径 设置datasource数据源 * * @return * @throws IOException */ @Bean(name = "sqlSessionFactory") public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); // 设置mybatis configuration 扫描路径 sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(mybatisConfigFile)); // 添加mapper 扫描路径 PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPath; sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath)); // 设置dataSource sqlSessionFactoryBean.setDataSource(dataSource); // 设置typeAlias 包扫描路径 sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasPackage); return sqlSessionFactoryBean; } }
012020-06-28
相似问题