本文整理汇总了Java中org.apache.ibatis.session.SqlSession.getMapper方法的典型用法代码示例。如果您正苦于以下问题:Java SqlSession.getMapper方法的具体用法?Java SqlSession.getMapper怎么用?Java SqlSession.getMapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.session.SqlSession
的用法示例。
在下文中一共展示了SqlSession.getMapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertyById
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Override
public PropertyBean getPropertyById(int id) {
SqlSession sqlSession = MybatisSqlSession.getSqlSession();
PropertyBean propertyBean = new PropertyBean();
try {
PropertyDao propertyDao = sqlSession.getMapper(PropertyDao.class);
propertyBean = propertyDao.getPropertyById(id);
} catch (Exception e) {
// e.printStackTrace();
// logger.error(e.getStackTrace());
} finally {
sqlSession.close();
}
return propertyBean;
}
示例2: testSelectByExample3
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void testSelectByExample3() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
CountryExample example = new CountryExample();
example.createCriteria().andCountrynameLike("A%");
example.or().andIdGreaterThan(100);
example.setDistinct(true);
List<Country> countries = mapper.selectByExample(example);
//查询总数
Assert.assertEquals(true, countries.size() > 83);
} finally {
sqlSession.close();
}
}
示例3: testSelectByExample4
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
@Test
public void testSelectByExample4() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Country ct = new Country();
ct.setCountryname("China");
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Example example = new Example(Country.class);
example.createCriteria().andGreaterThan("id", 20).andEqualTo(ct);
List<Country> countries = mapper.selectByExample(example);
//查询总数
System.out.println(countries.get(0).toString());
Assert.assertEquals(1, countries.size());
} finally {
sqlSession.close();
}
}
示例4: testUpdateByPrimaryKeySelective
import org.apache.ibatis.session.SqlSession; //导入方法依赖的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();
}
}
示例5: testDynamicInsertAll
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 插入空数据,id不能为null,会报错
*/
@Test
public void testDynamicInsertAll() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
Country2 country2 = new Country2();
country2.setCountrycode("CN");
Assert.assertEquals(1, mapper.insert(country2));
country2 = mapper.select(country2).get(0);
Assert.assertNotNull(country2);
Assert.assertEquals(1, mapper.deleteByPrimaryKey(country2.getId()));
} finally {
sqlSession.close();
}
}
示例6: getUserById
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static User getUserById(String userId) {
if (StringUtil.stringIsNull(userId)) {
return null;
}
SqlSession sqlSession = null;
User user;
try {
sqlSession = MybatisManager.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
user = userMapper.selectByPrimaryKey(userId);
if (user == null) {
MybatisManager.log.warn("通过userId:" + userId + "获取用户为空");
}
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("获取用户异常", e);
return null;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
return user;
}
示例7: getOrderRecordById
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static OrderRecordExt getOrderRecordById(String orderRecordId) {
if (StringUtil.stringIsNull(orderRecordId)) {
return null;
}
SqlSession sqlSession = null;
OrderRecordExt orderRecord;
try {
sqlSession = MybatisManager.getSqlSession();
OrderRecordMapperExt orderRecordMapper = sqlSession.getMapper(OrderRecordMapperExt.class);
orderRecord = orderRecordMapper.selectByPrimaryKey(orderRecordId);
if (orderRecord == null) {
MybatisManager.log.warn("通过orderRecordId:" + orderRecordId + "获取支付记录为空");
}
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("获取支付记录异常", e);
return null;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
return orderRecord;
}
示例8: testINDENTITYInsert
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 插入完整数据
*/
@Test
public void testINDENTITYInsert() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryIMapper mapper = sqlSession.getMapper(CountryIMapper.class);
CountryI country = new CountryI();
country.setCountrycode("CN");
Assert.assertEquals(1, mapper.insert(country));
//ID会回写
Assert.assertNotNull(country.getId());
//删除插入的数据,以免对其他测试产生影响
Assert.assertEquals(1, mapper.deleteByPrimaryKey(country.getId()));
} finally {
sqlSession.close();
}
}
示例9: testInsert
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 插入完整数据
*/
//该方法测试需要mysql或者h2数据库,所以这里注释掉
//@Test
public void testInsert() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Country country = new Country();
country.setCountrycode("CN");
country.setCountryname("天朝");
int count = mapper.insertUseGeneratedKeys(country);
Assert.assertEquals(1, count);
Assert.assertNotNull(country.getId());
} finally {
sqlSession.rollback();
sqlSession.close();
}
}
示例10: testDynamicSelectZero
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 查询不存在的结果
*/
@Test
public void testDynamicSelectZero() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
Country country = new Country();
country.setCountrycode("CN");
country.setCountryname("天朝");//实际上是 China
List<Country> countryList = mapper.select(country);
Assert.assertEquals(0, countryList.size());
} finally {
sqlSession.close();
}
}
示例11: testDynamicInsertAll
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 插入空数据,id不能为null,会报错
*/
@Test
public void testDynamicInsertAll() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
Country2 country2 = new Country2();
country2.setCountrycode("CN");
Assert.assertEquals(1, mapper.insertSelective(country2));
country2 = mapper.select(country2).get(0);
Assert.assertNotNull(country2);
Assert.assertEquals(1, mapper.deleteByPrimaryKey(country2.getId()));
} finally {
sqlSession.close();
}
}
示例12: getUserByEmail
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static User getUserByEmail(String userEmail) {
if (StringUtil.stringIsNull(userEmail)) {
return null;
}
SqlSession sqlSession = null;
try {
sqlSession = MybatisManager.getSqlSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
UserCriteria userCriteria = new UserCriteria();
UserCriteria.Criteria criteria = userCriteria.createCriteria();
criteria.andUserEmailEqualTo(userEmail);
List<User> userList = userMapper.selectByExample(userCriteria);
if (userList == null || userList.size() == 0) {
MybatisManager.log.warn("通过userEmail:" + userEmail + "获取用户为空");
return null;
}
return userList.get(0);
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("获取用户异常", e);
return null;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
}
示例13: testDynamicSelectCount
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 查询全部
*/
@Test
public void testDynamicSelectCount() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
//查询总数
Assert.assertEquals(183, mapper.selectCount(new Country()));
} finally {
sqlSession.close();
}
}
示例14: createToken
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
public static Token createToken(String userId) {
if (StringUtil.stringIsNull(userId)) {
return null;
}
Token token = new Token();
Date date = new Date();
token.setTokenCreateTime(date);
token.setTokenUpdateTime(date);
Date expireTime = new Date(date.getTime() + CommonConfigUCenter.TOKEN_EXPIRE_TIME);
token.setTokenExpireTime(expireTime);
token.setUserId(userId);
token.setTokenId(IdUtil.getUuid());
SqlSession sqlSession = null;
try {
sqlSession = MybatisManager.getSqlSession();
TokenMapper tokenMapper = sqlSession.getMapper(TokenMapper.class);
int result = tokenMapper.insert(token);
if (result == 0) {
MybatisManager.log.warn("创建token失败");
return null;
}
sqlSession.commit();
return token;
} catch (Exception e) {
if (sqlSession != null) {
sqlSession.rollback();
}
MybatisManager.log.error("创建token异常", e);
return null;
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
}
示例15: testDynamicUpdateByPrimaryKeyAllByNull
import org.apache.ibatis.session.SqlSession; //导入方法依赖的package包/类
/**
* 入参为null时更新全部
*/
@Test
public void testDynamicUpdateByPrimaryKeyAllByNull() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
mapper.updateByPrimaryKey(null);
} finally {
sqlSession.close();
}
}