Spring JDBC 随笔

Spring 框架,借助 JdbcTemplate 类来简化 java 访问 database。

完成一个增查改删(CRUD)的基本功能,借助下面 5 个角色来共同来完成。

1. object class : 定义数据记录的对象模型

2. Mapper class : 实现 RowMapper<object> 接口,通过 mapRow 方法,定义数据记录和 object 直接的关系

3. DAO Interface : 定义数据访问的接口

4. Implementation class of DAO : 实现 DAO Interface, 提供具体数据访问方法

5. xml file : 定义数据库配置(例如,username, password),定义 Implementation class of DAO 的一个 bean

 

最后,业务逻辑文件,调用第五步中的 bean 来操作 database。

参考资料:

Spring JDBC 示例, 极客学院

Spring JDBC Example, tutorialspoint

How to Define a MySql datasource bean via XML in Spring, stackOverFlow

 

posted @ 2016-03-21 22:59  TonyYPZhang  阅读(132)  评论(0编辑  收藏  举报