当前位置: 首页>>代码示例>>Java>>正文


Java UserInfoAbleMapper.selectByPrimaryKey方法代码示例

本文整理汇总了Java中tk.mybatis.mapper.mapper.UserInfoAbleMapper.selectByPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:Java UserInfoAbleMapper.selectByPrimaryKey方法的具体用法?Java UserInfoAbleMapper.selectByPrimaryKey怎么用?Java UserInfoAbleMapper.selectByPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tk.mybatis.mapper.mapper.UserInfoAbleMapper的用法示例。


在下文中一共展示了UserInfoAbleMapper.selectByPrimaryKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsert

import tk.mybatis.mapper.mapper.UserInfoAbleMapper; //导入方法依赖的package包/类
/**
 * 新增
 */
@Test
public void testInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoAbleMapper mapper = sqlSession.getMapper(UserInfoAbleMapper.class);
        UserInfoAble userInfo = new UserInfoAble();
        userInfo.setUsername("abel533");
        userInfo.setPassword("123456");
        userInfo.setUsertype("2");
        userInfo.setEmail("[email protected]");//insert=false

        Assert.assertEquals(1, mapper.insert(userInfo));

        Assert.assertNotNull(userInfo.getId());
        Assert.assertEquals(6, (int) userInfo.getId());

        userInfo = mapper.selectByPrimaryKey(userInfo.getId());
        //email没有插入
        Assert.assertNull(userInfo.getEmail());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:28,代码来源:TestBasicAble.java

示例2: testUpdateByPrimaryKey

import tk.mybatis.mapper.mapper.UserInfoAbleMapper; //导入方法依赖的package包/类
/**
 * 根据主键全更新
 */
@Test
public void testUpdateByPrimaryKey() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoAbleMapper mapper = sqlSession.getMapper(UserInfoAbleMapper.class);
        UserInfoAble userInfo = mapper.selectByPrimaryKey(2);
        Assert.assertNotNull(userInfo);
        userInfo.setUsertype(null);
        userInfo.setEmail("[email protected]");
        userInfo.setAddress("这个地址不会更新进去");//update=false
        //不会更新username
        Assert.assertEquals(1, mapper.updateByPrimaryKey(userInfo));

        userInfo = mapper.selectByPrimaryKey(userInfo);
        Assert.assertNull(userInfo.getUsertype());
        Assert.assertNotEquals("这个地址不会更新进去", userInfo.getAddress());
        Assert.assertEquals("[email protected]", userInfo.getEmail());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:26,代码来源:TestBasicAble.java

示例3: testUpdateByPrimaryKeySelective

import tk.mybatis.mapper.mapper.UserInfoAbleMapper; //导入方法依赖的package包/类
/**
 * 根据主键更新非null
 */
@Test
public void testUpdateByPrimaryKeySelective() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoAbleMapper mapper = sqlSession.getMapper(UserInfoAbleMapper.class);
        UserInfoAble userInfo = mapper.selectByPrimaryKey(1);
        Assert.assertNotNull(userInfo);
        userInfo.setUsertype(null);
        userInfo.setPassword(null);
        userInfo.setAddress("这个地址不会更新进去");
        //不会更新username
        Assert.assertEquals(1, mapper.updateByPrimaryKeySelective(userInfo));

        userInfo = mapper.selectByPrimaryKey(1);
        Assert.assertEquals("1", userInfo.getUsertype());
        Assert.assertEquals("12345678", userInfo.getPassword());
        Assert.assertNotEquals("这个地址不会更新进去", userInfo.getAddress());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:26,代码来源:TestBasicAble.java


注:本文中的tk.mybatis.mapper.mapper.UserInfoAbleMapper.selectByPrimaryKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。