public class SchemaSqlSessionFactoryBean extends SqlSessionFactoryBean {
}
package org.dysd.dao.mybatis.schema;
import org.apache.ibatis.executor.ErrorContext;
import org.apache.ibatis.session.Configuration;
import org.springframework.core.NestedIOException;
import org.springframework.core.io.Resource;
import org.springframework.util.xml.XmlValidationModeDetector;
public class SchemaSqlSessionFactoryBean extends SqlSessionFactoryBean {
@Override
protected void doParseSqlMapperResource(Configuration configuration, Resource mapperLocation)
throws NestedIOException {
int mode = detectValidationMode(mapperLocation);
if(mode == XmlValidationModeDetector.VALIDATION_DTD){//如果是DTD,使用Mybatis官方的解析
super.doParseSqlMapperResource(configuration, mapperLocation);
}else{
try {
// 使用Schema校验
this.doParseSqlMapperResourceWithSchema(configuration, mapperLocation);
} catch (Exception e) {
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
} finally {
ErrorContext.instance().reset();
}
}
}
protected void doParseSqlMapperResourceWithSchema(Configuration configuration, Resource mapperLocation){
}
private int detectValidationMode(Resource mapperLocation) throws NestedIOException {
int mode = -1;
try {
XmlValidationModeDetector detector = new XmlValidationModeDetector();
mode = detector.detectValidationMode(mapperLocation.getInputStream());
} catch (Exception e) {
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
} finally {
ErrorContext.instance().reset();
}
return mode;
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xsd:schema xmlns="http://dysd.org/schema/sqlmapper" targetNamespace="http://dysd.org/schema/sqlmapper" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0">
<xsd:simpleType name="statementType"> <xsd:restriction base="xsd:token"> <xsd:enumeration value="STATEMENT" /> <xsd:enumeration value="PREPARED" /> <xsd:enumeration value="CALLABLE" /> </xsd:restriction> </xsd:simpleType>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有