本文整理汇总了Java中tk.mybatis.mapper.mapper.UserInfoMapper类的典型用法代码示例。如果您正苦于以下问题:Java UserInfoMapper类的具体用法?Java UserInfoMapper怎么用?Java UserInfoMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInfoMapper类属于tk.mybatis.mapper.mapper包,在下文中一共展示了UserInfoMapper类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDelete
import tk.mybatis.mapper.mapper.UserInfoMapper; //导入依赖的package包/类
/**
* 主要测试删除
*/
@Test
public void testDelete() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
//查询总数
Assert.assertEquals(5, mapper.selectCount(new UserInfo()));
//查询100
UserInfo userInfo = mapper.selectByPrimaryKey(1);
//根据主键删除
Assert.assertEquals(1, mapper.deleteByPrimaryKey(1));
//查询总数
Assert.assertEquals(4, mapper.selectCount(new UserInfo()));
//插入
Assert.assertEquals(1, mapper.insert(userInfo));
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例2: testUpdateByPrimaryKey
import tk.mybatis.mapper.mapper.UserInfoMapper; //导入依赖的package包/类
/**
* 根据主键全更新
*/
@Test
public void testUpdateByPrimaryKey() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
UserInfo userInfo = mapper.selectByPrimaryKey(2);
Assert.assertNotNull(userInfo);
userInfo.setUsertype(null);
userInfo.setEmail("[email protected]");
//不会更新username
Assert.assertEquals(1, mapper.updateByPrimaryKey(userInfo));
userInfo = mapper.selectByPrimaryKey(userInfo);
Assert.assertNull(userInfo.getUsertype());
Assert.assertEquals("[email protected]", userInfo.getEmail());
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例3: testUpdateByPrimaryKeySelective
import tk.mybatis.mapper.mapper.UserInfoMapper; //导入依赖的package包/类
/**
* 根据主键更新非null
*/
@Test
public void testUpdateByPrimaryKeySelective() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
UserInfo userInfo = mapper.selectByPrimaryKey(1);
Assert.assertNotNull(userInfo);
userInfo.setUsertype(null);
userInfo.setEmail("[email protected]");
//不会更新username
Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(userInfo));
userInfo = mapper.selectByPrimaryKey(1);
Assert.assertEquals("1", userInfo.getUsertype());
Assert.assertEquals("[email protected]", userInfo.getEmail());
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例4: testInsert
import tk.mybatis.mapper.mapper.UserInfoMapper; //导入依赖的package包/类
/**
* 新增
*/
@Test
public void testInsert() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
UserInfo userInfo = new UserInfo();
userInfo.setUsername("abel533");
userInfo.setPassword("123456");
userInfo.setUsertype("2");
userInfo.setEmail("[email protected]");
Collection collection = sqlSession.getConfiguration().getMappedStatements();
for (Object o : collection) {
if(o instanceof MappedStatement){
MappedStatement ms = (MappedStatement) o;
if (ms.getId().contains("UserInfoMapper.insert")) {
System.out.println(ms.getId());
}
}
}
Assert.assertEquals(1, mapper.insert(userInfo));
Assert.assertNotNull(userInfo.getId());
Assert.assertTrue((int) userInfo.getId() >= 6);
Assert.assertEquals(1,mapper.deleteByPrimaryKey(userInfo));
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例5: testSelect
import tk.mybatis.mapper.mapper.UserInfoMapper; //导入依赖的package包/类
/**
* 查询
*/
@Test
public void testSelect() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
UserInfoMapper mapper = sqlSession.getMapper(UserInfoMapper.class);
UserInfo userInfo = new UserInfo();
userInfo.setUsertype("1");
List<UserInfo> userInfos = mapper.select(userInfo);
Assert.assertEquals(3, userInfos.size());
} finally {
sqlSession.close();
}
}