发表于: 2018-03-28 21:57:39
1 483
今天完成的事情:学习mybatis
结构
1,config
标准开头
configuation
typeAliases
enviroments default
enviroment id
transactionManager type = "JDBC"
dataSource type ="POOLED"
property name = "drver" value ="com.mysql.jdbc.Driver"
property name = "url"...
property name = "username"....
property name = "password"...
/dataSource
/enviroment
/enviroments
mappers
/configuration
2 category.xml
标准开头
mapper namespace = "包名"
select id = "listCategory" resultType = "category"
select * form 表名(此句为sql语句)
/select
/mapper
3category.java
class Category{
int id;
String name;
getId()
setId()
getName()
setName()
}
4test
public class TestMybatis {
public static void main(String[] args) throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session=sqlSessionFactory.openSession();
List<Category> cs=session.selectList("listCategory");
for (Category c : cs) {
System.out.println(c.getName());
}
}
}
顺便整理一下翻译
mapper 映射
transactionManager 事务管理
dataSource 数据源
property 属性
resource 资源
session 会话
明天计划的事情:继续学习mybatis
遇到的问题:对于脚本的引用方式不太明白,mybatis的很多方法名也不懂,还需要继续学习一个
收获:建立起了第一个测试项目
评论