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


Java MyBatisSystemException类代码示例

本文整理汇总了Java中org.mybatis.spring.MyBatisSystemException的典型用法代码示例。如果您正苦于以下问题:Java MyBatisSystemException类的具体用法?Java MyBatisSystemException怎么用?Java MyBatisSystemException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testAddToConfigFalse

import org.mybatis.spring.MyBatisSystemException; //导入依赖的package包/类
@Test(expected = org.apache.ibatis.binding.BindingException.class)
public void testAddToConfigFalse() throws Throwable {
  try {
    // the default SqlSessionFactory in AbstractMyBatisSpringTest is created with an explicitly
    // set MapperLocations list, so create a new factory here that tests auto-loading the
    // config
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    // mapperLocations properties defaults to null
    factoryBean.setDataSource(dataSource);

    SqlSessionFactory sqlSessionFactory = factoryBean.getObject();

    find(new SqlSessionTemplate(sqlSessionFactory), false);
    fail("TestDao's mapper xml should not be loaded");
  } catch (MyBatisSystemException mbse) {
    // unwrap exception so the exact MyBatis exception can be tested
    throw mbse.getCause();
  } finally {
    // connection not used; force close to avoid failing in validateConnectionClosed()
    connection.close();
  }
}
 
开发者ID:lindzh,项目名称:mybatis-spring-1.2.2,代码行数:23,代码来源:MapperFactoryBeanTest.java

示例2: selectOne

import org.mybatis.spring.MyBatisSystemException; //导入依赖的package包/类
/**
 * 查询一条记录
 * 
 * @param arg0
 * @param arg1
 * @return
 */
public <M extends BaseBean> M selectOne(String arg0, M param) {
	if (param == null) {
		return null;
	}
	
	SqlSession session = openSession();
	M bean = null;
	try {
		bean = session.selectOne(arg0, param);
	} catch (MyBatisSystemException e) {
		if (e != null && e.getCause() instanceof TooManyResultsException) {
		} else {
			throw e;
		}
	}
	return bean;
}
 
开发者ID:ImKarl,项目名称:ccshop,代码行数:25,代码来源:BaseDao.java

示例3: defaultErrorHandler

import org.mybatis.spring.MyBatisSystemException; //导入依赖的package包/类
@ExceptionHandler(value = Exception.class)
@ResponseBody
public String defaultErrorHandler(HttpServletRequest req, HttpServletResponse res, Exception e) throws Exception {

    String url = req != null ? req.getRequestURI() : "";

    String estr_short = "ip=" + req.getRemoteAddr() + ", url=" + url;
    String estr_long = estr_short + ", e=" + e.toString();

    boolean jsondemo = false;
    boolean jsonreq = (req != null && req.getHeader("X-Requested-With") != null) ? true : false;
    boolean dberror = false;

    if (e instanceof JsonResponseDemoSiteErrorException) {
        jsondemo = true;
        logger.debug(estr_long);
    }
    else if (e instanceof JsonResponseException) {
        logger.warn(estr_long);
    }
    // path variableの型不一致、Validationエラー、意図しないパラメータ(脆弱性を狙った攻撃)
    else if (e instanceof TypeMismatchException || e instanceof BindException
            || e instanceof UnsatisfiedServletRequestParameterException) {
        logger.info(estr_long);
    }
    // DB障害
    else if (e instanceof MyBatisSystemException || e instanceof SQLException || e instanceof DataAccessException) {
        dberror = true;
        logger.info(estr_long);
    }
    else {
        logger.warn(estr_short, e);
    }

    if (jsondemo) {
        res.setStatus(HttpServletResponse.SC_OK);
        res.setContentType("application/json; charset=UTF-8");
        return "{\"demoSite\":true}";
    }
    else if (jsonreq) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        res.setContentType("application/json; charset=UTF-8");
        return "{\"error\":true}";
    }
    else if (dberror) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "db error";
    }
    else {
        res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
        res.setHeader("Location", contextPath);
        return "";
    }
}
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:55,代码来源:GlobalControllerExceptionHandler.java


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