转载请注明出处哈:http://carlosfu.iteye.com/blog/2238662
1. 定义sql映射xml文件:
3. 单元测试:
package com.sohu.tv.test.base; import java.io.IOException; import java.io.Reader; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; /** * mybatis测试基类 * * @author leifu * @Date 2015年7月28日 * @Time 上午10:59:03 */ public class BaseTest { protected static SqlSessionFactory sessionFactory; /** * mybatis基础配置 */ protected final static String MYBATIS_CONF = "mybatis-base.xml"; @BeforeClass public static void setUp() throws IOException { Reader reader = Resources.getResourceAsReader(MYBATIS_CONF); sessionFactory = new SqlSessionFactoryBuilder().build(reader); } }
package com.sohu.tv.test.mapper; import java.util.List; import org.apache.ibatis.session.SqlSession; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.sohu.tv.bean.Player; import com.sohu.tv.mapper.PlayerDao; /** * mybatis-xml方式配置 * * @author leifu * @Date 2015年7月28日 * @Time 上午9:54:07 */ public class PlayerMapperXmlTestV2 extends BaseTest { private SqlSession sqlSession; @Before public void before() { sqlSession = sessionFactory.openSession(true); } @After public void after() { sqlSession.close(); } @Test public void testGetPlayer() { PlayerDao playerDao = sqlSession.getMapper(PlayerDao.class); Player player = playerDao.getPlayerById(2); System.out.println(player); } @Test public void testInsertPlayer() { PlayerDao playerDao = sqlSession.getMapper(PlayerDao.class); playerDao.savePlayer(new Player(-1, "cr7", 30)); } @Test public void testDeletePlayer() { PlayerDao playerDao = sqlSession.getMapper(PlayerDao.class); playerDao.deletePlayer(3); } @Test public void testUpdatePlayer() { PlayerDao playerDao = sqlSession.getMapper(PlayerDao.class); playerDao.updatePlayer(new Player(3, "cafu", 45)); } @Test public void testSelectAllPlayers() { PlayerDao playerDao = sqlSession.getMapper(PlayerDao.class); List<Player> playerList = playerDao.selectAllPlayers(); if (playerList != null && !playerList.isEmpty()) { System.out.println("playerList size: " + playerList.size()); for (Player player : playerList) { System.out.println(player); } } } }
4. 操作视频:
相关推荐
mybatis-plus-sample-crud: 完整 CRUD 示例 mybatis-plus-sample-wrapper: 条件构造器示例 mybatis-plus-sample-pagination: 分页功能示例 mybatis-plus-sample-active-record: ActiveRecord示例 mybatis-plus-...
MyBatis-CRUD-Annotation.zip
mybatis 增强工具包,简化 CRUD 操作。
基于插件方式生成连接数据库里的crud,基于插件方式生成连接数据库里的crud,基于插件方式生成连接数据库里的crud
mybatis单表查询。
springmvc:简化的替换映射器类示例(Spring MVC版本) mybatis-plus-sample-generator:代码生成器示例mybatis-plus-sample-crud:完整的CRUD示例mybatis-plus-sample-wrapper:条件构造器示例mybatis加上样本分页...
特性:无侵入、损耗小、强大的CRUD操作,支持lambda 形势调用、支持多种数据库,支持主键自动生成、支持ActiveRecord模式,支持自定义全局通用操作、支持关键词自动转义,内置代码生成器、内置分页插件、内置性能...
mybatis代码生成器,简单的CRUD
通用 Service CRUD 封装IService接口,进一步封装 CRUD 采用 get 查询单行 remove 删除 list 查询集合 page 分页 前缀命名方式区分 Mapper 层避免混淆, 泛型 T 为任意实体对象 建议如果存在自定义通用 Service 方法...
springboot-mybatis-mysql-easyui实现了简单的增删改查操作,适合初学者学习
本项目基于Maven搭建的,使用MyBatis3.2.5 开发的一个CRUD示例项目
手把手视频详细讲解项目开发全过程,需要的小伙伴自行百度网盘下载,链接见附件,永久有效。 课程简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高...
Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作,无侵入:Mybatis-Plus 在 Mybatis 的基础上进行扩展,只做增强不做改变,引入 Mybatis-Plus 不会对您现有的 Mybatis 构架产生任何影响,而且 MP 支持所有 ...
spring-data-mongodb增强工具包,简化 CRUD 操作,提供类mybatis plus的数据库操作。传统关系型数据库及围绕它们构建的orm在项目开发中有很多难用的痛点,而mongodb这种文档性数据库的出现,完美的解决了sql数据库在...
MyBatis-CRUD.zip
mybatis 增强工具包,简化 CRUD 操作。Mybatis-Plus 在 Mybatis 的基础上进行扩展,只做增强不做改变,引入 Mybatis-Plus 不会对您现有的 Mybatis 构架产生任何影响,而且 MP 支持所有 Mybatis 原生的特性。仅仅依赖...
Code generator for MyBatis and iBATIS. It will generate code for all versions of MyBatis, and versions of iBATIS after version 2.2.0. It will introspect a database table (or many tables) and will ...
maven-springboot-mysql-thymeleaf-mybatis-CRUD增删改查完整版