使用mybatis开发原始dao
来源:互联网 发布:天界五行进阶数据 编辑:程序博客网 时间:2024/05/01 16:53
@Overridepublic User findUserById(int id) throws Exception {// 根据SqlSessionFactory创建SqlSessionSqlSession sqlSession = sqlSessionFactory.openSession();// 通过sqlSession查询用户信息(发起数据库操作)// 第一个参数statement:指定mapper映射文件中statement的id,指定 时需要前边加上statement所属的命名空间// 第二个参数parameter,指定 输入参数// selectOne返回的是单条记录,如果select返回多条记录(list集合),使用selectOne会报错// 根据映射文件中的resultType指定输出类型User user = sqlSession.selectOne("test.findUserById", id);// 遍历查询结果// System.out.println(user);return user;}
@Overridepublic List<User> findUserList() throws Exception {// 根据SqlSessionFactory创建SqlSessionSqlSession sqlSession = sqlSessionFactory.openSession();// 通过sqlSession查询用户信息(发起数据库操作)// 第一个参数statement:指定mapper映射文件中statement的id,指定 时需要前边加上statement所属的命名空间// 第二个参数parameter,指定 输入参数// selectOne返回的是单条记录,如果select返回多条记录(list集合),使用selectOne会报错// 根据映射文件中的resultType指定输出类型// 查询用户列表// selectList表示查询一个结果集(可以是一条或多条)List<User> list = sqlSession.selectList("test.findUserList", "lzqiang");System.out.println(list.size());return list;}
@Overridepublic void insertUser(User user) throws Exception {// 根据SqlSessionFactory创建SqlSessionSqlSession sqlSession = sqlSessionFactory.openSession();sqlSession.insert("test.insertUser", user);sqlSession.commit();sqlSession.close();}
0 0
- 使用mybatis开发原始dao
- 原始DAO开发mybatis
- Mybatis(原始dao开发)
- mybatis-使用原始dao
- Mybatis原始的dao开发
- MyBatis原始Dao开发方式
- Mybatis-Dao层开发之原始dao
- mybatis 原始dao开发存在的问题
- mybatis 用原始的dao方法开发
- mybatis开发原始dao的方式
- Mybatis开发原始Dao(即有Dao的实现)
- Mybatis开发dao的方法--原始dao篇
- mybatis--开发Dao--原始dao方式和Mapper代理方式
- mybatis(6)--mybatis开发dao之原始开发
- mybatis(7)--使用mapper代理开发代替原始的dao开发
- 使用Mybatis开发Dao
- 使用Mybatis开发Dao
- mybatis 原始dao开发和mapper代理开发的比较
- uva 108 Maximum Sum 最大子矩阵和
- 102Binary Tree Level Order Traversal (java)
- light oj 1013 LCS 应用
- 类成员函数指针
- 网上处方药物手册Rxlist 及其药学信息资源
- 使用mybatis开发原始dao
- 仿qq未读消息
- 深入理解JVM性能调优
- XPath语法
- 直接插入排序算法
- 第一篇CSDN博客
- Java线程的5种状态及切换(透彻讲解)
- html5开发利器——sublimetext2+emmet插件
- uncaught syntaxerror unexpected token )