maven资源过滤:
src/main/resources
***.xml
true
src/main/java
***.xml
true
mybatis-config.xml配置文件格式:
mybatis映射sql语句:
select * from Blog where id = #{id}
mybatis工具类:
public class MybatisUtils {
private static SqlSessionFactory sqlSessionFactory;
static {
try {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
public static SqlSession getSqlSession(){
return sqlSessionFactory.openSession();
}
}
数据库配置文件db.properties:
driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/spring?useSSL=true&useUnicode=true&characterEncoding=UTF-8 username=root password=666666QIU



