當前位置: 首頁>>代碼示例>>Java>>正文


Java SqlSessionFactoryBean.setTypeAliasesPackage方法代碼示例

本文整理匯總了Java中org.mybatis.spring.SqlSessionFactoryBean.setTypeAliasesPackage方法的典型用法代碼示例。如果您正苦於以下問題:Java SqlSessionFactoryBean.setTypeAliasesPackage方法的具體用法?Java SqlSessionFactoryBean.setTypeAliasesPackage怎麽用?Java SqlSessionFactoryBean.setTypeAliasesPackage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mybatis.spring.SqlSessionFactoryBean的用法示例。


在下文中一共展示了SqlSessionFactoryBean.setTypeAliasesPackage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

    //mybatis配置
    Properties prop = new Properties();
    prop.setProperty("mapUnderscoreToCamelCase", "true");

    sqlSessionFactoryBean.setConfigurationProperties(prop);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.tc.ly.bean");

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath:mapper/*.xml");

    sqlSessionFactoryBean.setMapperLocations(resources);
    sqlSessionFactoryBean.setDataSource(dataSource);

    return sqlSessionFactoryBean;
}
 
開發者ID:hadesvip,項目名稱:ly-security,代碼行數:20,代碼來源:MybatisConfig.java

示例2: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Primary
@Bean(name = "test1dbSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("test1db") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    factoryBean.setTypeAliasesPackage("com.maxplus1.demo.entity");
    factoryBean.setMapperLocations(
            new PathMatchingResourcePatternResolver().getResources("classpath:mapper/test1db/*.xml"));
    return factoryBean.getObject();
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:11,代碼來源:Test1dbConfig.java

示例3: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory( @Autowired DynamicDataSource dynamicDataSource ) {
	try {
		SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
		sessionFactory.setDataSource(dynamicDataSource);
		sessionFactory.setTypeAliasesPackage(this.typeAliasesPackage);
		sessionFactory.setMapperLocations( new PathMatchingResourcePatternResolver().getResources(mapperLocations) );
		sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation));
		
		PageHelper pageHelper = new PageHelper();
		Properties props = new Properties();
		props.setProperty("reasonable", "false");
		props.setProperty("supportMethodsArguments", "true");
		props.setProperty("returnPageInfo", "check");
		props.setProperty("params", "count=countSql");
		pageHelper.setProperties(props);

		sessionFactory.setPlugins(new Interceptor[] { pageHelper });

		return sessionFactory.getObject();
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:chxfantasy,項目名稱:micro-service-sample,代碼行數:26,代碼來源:SessionFactoryConfig.java

示例4: SqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
    @Primary
    public SqlSessionFactory SqlSessionFactory(@Qualifier("datasource") DataSource dataSource
            , ApplicationContext applicationContext) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

        // accur Could not resolve type alias in running jar
        sqlSessionFactoryBean.setVfs(SpringBootVFS.class);

        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setMapperLocations(
                applicationContext.getResources("classpath:META-INF/mappers/*.xml")
        );
        sqlSessionFactoryBean.setConfigLocation(
                applicationContext.getResource("classpath:META-INF/mybatis-config.xml")
        );
//        sqlSessionFactoryBean.setConfigurationProperties(mybatisProperties());
        sqlSessionFactoryBean.setTypeAliasesPackage("com.pineone.icbms.so.interfaces.database.model");

        return sqlSessionFactoryBean.getObject();
    }
 
開發者ID:iotoasis,項目名稱:SO,代碼行數:22,代碼來源:DatabaseConfig.java

示例5: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(roundRobinDataSouceProxy());
    sqlSessionFactoryBean.setTypeAliasesPackage(this.typeAliasesPackage);
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(this.mapperLocations));
    sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:jinping125,項目名稱:read-write-sever,代碼行數:12,代碼來源:MybatisConfig.java

示例6: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean("sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
	sessionFactory.setDataSource(dataSource());
	sessionFactory.setConfiguration(configuration());
	sessionFactory.setTypeAliasesPackage(entityBasePackage);
	sessionFactory.setTypeAliasesSuperType(AbstractEntity.class);
	sessionFactory.setMapperLocations(getResources(mapperResources));
	OffsetLimitInterceptor offserInterceptor = new OffsetLimitInterceptor();
	offserInterceptor.setDialect(new MySQLDialect());
	MapperInterceptor mapperInterceptor = new MapperInterceptor();
	Properties properties = new Properties();
	properties.setProperty("mappers", mappers);
	properties.setProperty("IDENTITY", dialect);
	mapperInterceptor.setProperties(properties);
	sessionFactory.setPlugins(new Interceptor[] { offserInterceptor ,mapperInterceptor});
	return sessionFactory.getObject();
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:19,代碼來源:MyBatisConfig.java

示例7: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() throws EasyTestException {
    // 原寫法
    //   SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    // 這樣做. 沒辦法mock到. 於是使用工廠方法
    SqlSessionFactoryBean bean = getSqlSessionFactoryBeanInstance();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage("com.zhu8fei.**.mybatis.model");

    try {
        return bean.getObject();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new EasyTestException(e.getMessage(), e);
    }
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:17,代碼來源:MybatisConfig.java

示例8: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public static SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTypeAliasesPackage(MODEL_PACKAGE);

    //配置分頁插件,詳情請查閱官方文檔
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("pageSizeZero", "true");//分頁尺寸為0時查詢所有紀錄不再執行分頁
    properties.setProperty("reasonable", "true");//頁碼<=0 查詢第一頁,頁碼>=總頁數查詢最後一頁
    properties.setProperty("supportMethodsArguments", "true");//支持通過 Mapper 接口參數來傳遞分頁參數
    pageHelper.setProperties(properties);

    //添加插件
    factory.setPlugins(new Interceptor[]{pageHelper});

    //添加XML目錄
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    return factory.getObject();
}
 
開發者ID:pandboy,項目名稱:pingguopai,代碼行數:23,代碼來源:MybatisConfigurer.java

示例9: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name="sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() {
    try {
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sessionFactory.setMapperLocations(resolver.getResources(mapperLocations));
        
        PageInterceptor pageInterceptor = new MysqlPageInterceptor();
        sessionFactory.setPlugins(new Interceptor[]{pageInterceptor});
        return sessionFactory.getObject();
    } catch (Exception e) {
        logger.warn("Could not confiure mybatis session factory", e);
        return null;
    }
}
 
開發者ID:lemon-china,項目名稱:lemon-dubbo-message,代碼行數:19,代碼來源:MybatisConfiguration.java

示例10: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
/**
 * 根據數據源創建SqlSessionFactory
 */
@Bean
public SqlSessionFactory sqlSessionFactory(AbstractRoutingDataSource routingDataSource) throws Exception {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(routingDataSource);// 指定數據源(這個必須有,否則報錯)
    // 下邊兩句僅僅用於*.xml文件,如果整個持久層操作不需要使用到xml文件的話(隻用注解就可以搞定),則不加
    factoryBean.setTypeAliasesPackage("com.tangcheng.datasources.aop.model");// 指定基包
    factoryBean.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml"));//
    return factoryBean.getObject();
}
 
開發者ID:helloworldtang,項目名稱:springboot-multi-datasource,代碼行數:14,代碼來源:MyBatisConfig.java

示例11: createSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory createSqlSessionFactory() throws Exception {
    SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
    fb.setDataSource(roundRobinDataSouceProxy());
    fb.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
    fb.setTypeAliasesPackage(typeAliasesPackage);
    return fb.getObject();
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:9,代碼來源:SqlSessionConfiguration.java

示例12: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
	SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
	factory.setDataSource(dataSource);
	if (StringUtils.hasText(this.properties.getConfig())) {
		factory.setConfigLocation(
				this.resourceLoader.getResource(this.properties.getConfig()));
	} else {
		if (this.interceptors != null && this.interceptors.length > 0) {
			factory.setPlugins(this.interceptors);
		}
		factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
		factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
		factory.setMapperLocations(this.properties.getMapperLocations());
	}
	return factory.getObject();
}
 
開發者ID:tinyoculus,項目名稱:Dynamic-data-sources,代碼行數:19,代碼來源:MybatisAutoConfiguration.java

示例13: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
/**
 * 將mybatis的sqlSessionFactory交給spring管理
 */
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    sessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml"));
    sessionFactory.setTypeAliasesPackage("com.fly.**.model");
    return sessionFactory;
}
 
開發者ID:heikehuan,項目名稱:fly4j,代碼行數:14,代碼來源:MybatisConfiguration.java

示例14: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactoryBean() throws EasyMallTestException {
        // 原寫法
        //   SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        // 這樣做. 沒辦法mock到. 於是使用工廠方法
        SqlSessionFactoryBean bean = getSqlSessionFactoryBeanInstance();
        bean.setDataSource(dataSource);
        bean.setTypeAliasesPackage("com.zhu8fei.**.mybatis.model");

        //分頁插件
        // PageInterceptor pageHelper = new PageInterceptor();
        //FIXME 配置沒有修改並不是同一個page插件, 通用字段插件沒有引入
//        Properties properties = new Properties();
//        properties.setProperty("reasonable", "true");
//        properties.setProperty("supportMethodsArguments", "true");
//        properties.setProperty("returnPageInfo", "check");
//        properties.setProperty("params", "count=countSql");
//        pageHelper.setProperties(properties);
        //添加插件
        bean.setPlugins(new Interceptor[]{});
        try {
            return bean.getObject();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new EasyMallTestException(e.getMessage(),e);
        }
    }
 
開發者ID:easymall,項目名稱:easymall,代碼行數:28,代碼來源:MybatisConfig.java

示例15: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() throws EasyMallCoreException{
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage("com.zhu8fei.**.mybatis.model");

    //添加插件
    bean.setPlugins(new Interceptor[]{});
    try {
        return bean.getObject();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new EasyMallCoreException(e);
    }
}
 
開發者ID:easymall,項目名稱:easymall,代碼行數:16,代碼來源:MybatisConfig.java


注:本文中的org.mybatis.spring.SqlSessionFactoryBean.setTypeAliasesPackage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。