原始dao开发(和spring整合后)前提准备:users表字段有idnameage一、创建mapper.xml在config下新建包sqlMapping,用于存储映射文件。1、在包sqlMapping下新建userMapper.xml映射文件selectid=getUserByIdparameterType=java.lang.IntegerresultType=ssm.bean.UserSELECT*FROMusersWHEREid=#{value}/select2、在Configuration.xml中加载此mapper.xmlmappersmapperresource=sqlMapping/userMapper.xml//mappers二、创建dao(实现类继承SqlSessionDaoSupport)1、新建包ssm.daopublicinterfaceUserDao{publicUsergetUserById(intid)throwsException;}2、让UserDaoImpl继承SqlSessionDaoSupportpublicclassUserDaoImplextendsSqlSessionDaoSupportimplementsUserDao{publicUsergetUserById(intid)throwsException{//继承SqlSessionDaoSupport,通过this.getSqlSession()得到sqlSessionSqlSessionsqlSession=this.getSqlSession();Useruser=sqlSession.selectOne(sqlMapping.userMapper.getUserById,id);returnuser;}}dao接口实现类需要注入SqlSessionFactory,通过spring进行注入。这里使用spring声明配置方式,配置dao的bean。3、在application.xml中配置!--原始dao接口--beanid=userDaoclass=ssm.dao.UserDaoImpl!--ref:SqlSessionFactorybean的id--propertyname=sqlSessionFactoryref=sqlSessionFactory//bean三、测试程序classTest{publicstaticvoidmain(String[]args){ApplicationContextapplicationContext=newClassPathXmlApplicationContext(classpath:spring/applicationContext.xml);UserDaouserDao=(UserDao)applicationContext.getBean(userDao);//调用userDao的方法Useruser=userDao.getUserById(1);System.out.println(user);}}