学习ssm笔记收集

在resources包下的文件资源,在xml中使用都需要加上classpath:前缀,java源文件可以直接输入路径

配置文件需要:

  mybatis的全局配置文件mybatis-config.xml

  spring配置文件:spring-dao.xml

  接口映射文件:xxx.xml

spring-dao:

1、数据库相关的配置
2、数据库连接池的配置
3、配置SqlSessionFactory对象:
    注入数据库连接池,
    配置MyBatis全局配置文件,
    扫描entity包,
    扫描sql配置文件(mapper需要的xml文件)
4、配置扫描Dao接口包,动态实现Dao接口
    注入sqkSessionFactory
    给出需要扫描Dao接口包

 

在写mapper的时候,sql语句中的查询语句select必须要指定返回值的类型

junit测试类需要加上

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/xxx.xml")//spring的配置文件

  

原文地址:https://www.cnblogs.com/shigeng/p/8918142.html