Comments (7)
This is an example which I use to register a pagination plugin (PageHelper) in pure Java config style. Though looks a bit bored, it's not so unacceptable in terms of the fact that you need to write it only once.
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource)
throws Exception {
SqlSessionFactoryBean sfb = new SqlSessionFactoryBean();
sfb.setDataSource(dataSource);
Properties prop = new Properties();
prop.setProperty("dialect", "mysql");
PageHelper pagePlugin = new PageHelper();
pagePlugin.setProperties(prop);
Interceptor[] plugins = {pagePlugin};
sfb.setPlugins(plugins);
SqlSessionFactory factory = sfb.getObject();
factory.getConfiguration().setMapUnderscoreToCamelCase(true);
return factory;
}
from spring-boot-starter.
Thanks.
Would have been nice if it was possible to do it by setting something in application.properties instead of overriding the bean creation.
from spring-boot-starter.
I am thinking to register all plugins automatically. Let try this approach. PR is welcome :)
from spring-boot-starter.
I'll see what I can do this weekend :-)
from spring-boot-starter.
Didn't get around to work in it yet.
While I'm at it, any idea of the best way to implement the configuration of settings the same way?
I've seen liukaitj's example about doing it. Is this the best approach?
SqlSessionFactory factory = sfb.getObject();
factory.getConfiguration().setMapUnderscoreToCamelCase(true);
instead of using mybatis-config.xml
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
from spring-boot-starter.
Actually if this works, why need to bring it inside?
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
The issue with #8 is it does not work by putting it in mybatis-config.xml
To quote the PageHelper example in here, I am doing this in mybatis-config.xml and it is working well:
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="pagehelper.SqlServer2012Dialect"/>
</plugin>
</plugins>
from spring-boot-starter.
As soon as you define mybatis-config.xml in the application.properties file, all other mybatis settings from that file are ignored.
from spring-boot-starter.
Related Issues (20)
- Result map to HashMap sometime response hex value HOT 3
- Consider defining a bean of type 'sample.mybatis.annotation.mapper.CityMapper' in your configuration. HOT 1
- Why is loading mapper.xml files extremely slow in AOT mode?
- Invalid bound statement (not found): I wondered why I hadn't found it all the time, and I double-checked that both matched HOT 1
- The latest springboot using mybatis-spring-stater 3.0.2 throw exception "Invalid value type for attribute 'factoryBeanObjectType': java.lang.String" HOT 3
- Excluding AutoConfigureTestDatabase doesn't work with MybatisTest's excludeAutoConfiguration
- MybatisCursorItemReader#open, close inherit deprecated method HOT 1
- Switch baseline to Spring Boot 3.2.x HOT 5
- Update to MyBatis Spring 3.0.3-SNAPSHOT for supporting Spring Boot 3.2
- Update to Spring Boot 2.7.x latest version on 2.3.x branch HOT 2
- Support JDK 22 on CI HOT 1
- Site distribution will be broken for the moment due to multi module
- Can I specify the databaseId directly? HOT 1
- When is the 3.0.3 release scheduled? HOT 3
- Unable to customize settings using ConfigurationCustomizer/SqlSessionFactoryBeanCustomizer
- Mapping error for some types ORA-03115 HOT 1
- Error access org.mybatis.spring.SqlSessionFactoryBean HOT 4
- Mybatis configuration of type aliases package path in yaml file does not take effect
- Incompatible type between Configuration SqlSessionFactoryBean and MybatisProperties HOT 4
- The MapperScannerConfigurer should support FactoryBeans HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot-starter.