本文整理汇总了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();
}
}
示例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;
}
示例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 "";
}
}