mybatis逆向生成映射文件实体类 单元测试test 增删改查方法
来源:互联网 发布:python zip函数 编辑:程序博客网 时间:2024/06/06 07:52
package cn.itcast.ssm.mapper;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.itcast.ssm.po.Items;
import cn.itcast.ssm.po.ItemsExample;
public class ItemsMapperTest {
private ApplicationContext applicationContext;
private ItemsMapper itemsMapper;
//在setUp这个方法得到spring容器
@Before
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
itemsMapper = (ItemsMapper) applicationContext.getBean("itemsMapper");
}
//根据主键删除
@Test
public void testDeleteByPrimaryKey() {
}
//插入
@Test
public void testInsert() {
//构造 items对象
Items items = new Items();
items.setName("手机");
items.setPrice(999f);
itemsMapper.insert(items);
}
//自定义条件查询
@Test
public void testSelectByExample() {
ItemsExample itemsExample = new ItemsExample();
//通过criteria构造查询条件 select * from where id=1 and name='笔记本3‘;
ItemsExample.Criteria criteria = itemsExample.createCriteria();
criteria.andNameEqualTo("笔记本3");
//可能返回多条记录
List<Items> list = itemsMapper.selectByExample(itemsExample);
System.out.println(list);
}
//根据主键查询
@Test
public void testSelectByPrimaryKey() {
Items items = itemsMapper.selectByPrimaryKey(1);
System.out.println(items);
}
//更新数据
@Test
public void testUpdateByPrimaryKey() {
//对所有字段进行更新,需要先查询出来再更新
Items items = itemsMapper.selectByPrimaryKey(1);
items.setName("水杯");
itemsMapper.updateByPrimaryKey(items);
//如果传入字段不空为才更新,在批量更新中使用此方法,不需要先查询再更新
//itemsMapper.updateByPrimaryKeySelective(record);
}
}
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.itcast.ssm.po.Items;
import cn.itcast.ssm.po.ItemsExample;
public class ItemsMapperTest {
private ApplicationContext applicationContext;
private ItemsMapper itemsMapper;
//在setUp这个方法得到spring容器
@Before
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
itemsMapper = (ItemsMapper) applicationContext.getBean("itemsMapper");
}
//根据主键删除
@Test
public void testDeleteByPrimaryKey() {
}
//插入
@Test
public void testInsert() {
//构造 items对象
Items items = new Items();
items.setName("手机");
items.setPrice(999f);
itemsMapper.insert(items);
}
//自定义条件查询
@Test
public void testSelectByExample() {
ItemsExample itemsExample = new ItemsExample();
//通过criteria构造查询条件 select * from where id=1 and name='笔记本3‘;
ItemsExample.Criteria criteria = itemsExample.createCriteria();
criteria.andNameEqualTo("笔记本3");
//可能返回多条记录
List<Items> list = itemsMapper.selectByExample(itemsExample);
System.out.println(list);
}
//根据主键查询
@Test
public void testSelectByPrimaryKey() {
Items items = itemsMapper.selectByPrimaryKey(1);
System.out.println(items);
}
//更新数据
@Test
public void testUpdateByPrimaryKey() {
//对所有字段进行更新,需要先查询出来再更新
Items items = itemsMapper.selectByPrimaryKey(1);
items.setName("水杯");
itemsMapper.updateByPrimaryKey(items);
//如果传入字段不空为才更新,在批量更新中使用此方法,不需要先查询再更新
//itemsMapper.updateByPrimaryKeySelective(record);
}
}
阅读全文
0 0
- mybatis逆向生成映射文件实体类 单元测试test 增删改查方法
- MyBatis映射文件--增删改查
- mybatis mapper.xml数据库映射生成java实体,增删改查sql语句
- mybatis逆向生成实体类,接口类,映射xml文件
- MyBatis逆向工程自动生成实体类和映射文件
- MyBatis 语句映射文件(2)增删改查、参数、缓存
- Mybatis用xml文件映射的增删查改
- Mybatis用xml文件映射的增删查改
- MyBatis自动生成实体类、DAO接口和Mapping映射文件的代码(逆向工程)
- MyEclipse逆向生成实体类和Hibernate映射文件
- MyEclipse逆向生成实体类和Hibernate映射文件
- MyEclipse逆向生成实体类和Hibernate映射文件
- MyEclipse逆向生成实体类和Hibernate映射文件
- MyEclipse逆向生成实体类和Hibernate映射文件
- eclipse 通过Hibernate 逆向生成实体类和映射文件
- Mybatis增删改查mapper文件写法
- MyBatis的增删改查方法
- MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
- Java8 新特性 函数式接口
- FFMPEG结构体分析:AVPacket
- 总结1-我跟书华大佬写的代码的区别
- 查找——树表的查找
- 关于 tomcat启动startup.bat一闪而过的问题
- mybatis逆向生成映射文件实体类 单元测试test 增删改查方法
- 413. Arithmetic Slices
- crack the coding interview 数组与字符串 1.2
- win7+ubuntu安装
- 虚拟化-传统-VMM
- POJ2431-C语言
- 微信 WCDB 正式开源——高效易用的移动数据库框架
- linux 常用命令
- ORACLE初学第二篇