Springboot+MyBatis+SqlMapper 灰太狼 2022-02-20 02:50 222阅读 0赞 1.[搭建Springboot+Mybatis+连接池框架][Springboot_Mybatis] 2.引入SqlMapper依赖 <dependency> <groupId>com.github.abel533</groupId> <artifactId>mapper</artifactId> <version>2.3.0</version> </dependency> 3.新建一个Bean为SqlSessionFactory @1.新建一个Class @Configuration public class SqlSessionFactoryConfig { @Autowired DataSource dataSource; @Bean @Primary public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean bean=new SqlSessionFactoryBean(); bean.setDataSource(dataSource);//更多参数请自行注入 return bean.getObject(); } } 4.新建一个requestMapper并调用Service @Service public class TestService { @Autowired SqlSessionFactory sqlSessionFactory; @Autowired TestMapper testMapper; public List<Map> queryAllStudent(Map<String, Object> value) { SqlSession session=sqlSessionFactory.openSession(); SqlMapper sqlMapper=new SqlMapper(session); String sql="<script>" + "select * from studentinfo " + "where 1=1 " + "<if test=\"stuno!=null\">" + "and stuno=#{stuno}" + "</if>" + "</script>"; List<Map> maps=sqlMapper.selectList(sql, value, Map.class); return maps; } } 5.处理数据 [Springboot_Mybatis]: https://blog.csdn.net/weixin_40429030/article/details/89377506
还没有评论,来说两句吧...