首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

ibatis跟spring的整合

2012-11-06 
ibatis和spring的整合ibatis和Spring整合的详细例子,数据库用的是mysql,开发环境是Eclipse3.2:1.首先把用

ibatis和spring的整合
  ibatis和Spring整合的详细例子,数据库用的是mysql,开发环境是Eclipse3.2:
1.首先把用到的包导入进来,此例用的是spring-framework-1.2.7,iBATIS_DBL-2.1.7.597,mysql的数
据库连接包用的是mysql-connector-java-5.0.3-bin.jar.

2.建POJO类,在此我们用的是一个Student类.



5.jdbc.properties文件,存储数据库连接的driver,url,username,password等信息,

7.StudentDaoSqlMap 是一个DAO,它负责和数据库的交互,在这里实现了查询单条记录和插入单条记录的功能.
package cn.itcast;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Client {public static void main(String[] args) {ApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");StudentDaoSqlMap studentDao = (StudentDaoSqlMap) factory.getBean("studentDao");//插入一个studentStudent student = new Student();student.setFirstname("tian");student.setLastname("xiangdong");studentDao.insertStudent(student);//查询出id是1的Student对象.//Student student = studentDao.getStudent(1);//System.out.println(student.getId());//System.out.println(student.getFirstname());//System.out.println(student.getLastname());}}

热点排行