spring boot 專案重新搭建----------1
阿新 • • 發佈:2018-12-21
1.在resources下建立favicon.ico(訪問的時候會有自己的小圖示)
2.在yml中@[email protected]
#當前伺服器版本 自動讀取MAVEN資訊 @[email protected]格式 version: @[email protected]
3配置分頁外掛
匯入依賴
<!--分頁外掛--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.6</version> </dependency>
@Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactory(@Qualifier("sqlDataSource") DataSource dataSource) throws Exception { final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); //新增分頁外掛 sessionFactory.setPlugins(plugins()); org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration(); config.setCallSettersOnNulls(settings.isCallSettersOnNulls()); sessionFactory.setConfiguration(config); return sessionFactory.getObject(); } private Interceptor[] plugins() { //分頁外掛設定 PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("reasonable", "true"); properties.setProperty("supportMethodsArguments", "true"); properties.setProperty("returnPageInfo", "check"); properties.setProperty("params", "count=countSql"); pageHelper.setProperties(properties); return new Interceptor[]{pageHelper}; }
設定外掛配置後,
PageHelper.startPage(pageNum,paegSize);
4.配置通用mapper
<!--通用mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.4</version> </dependency>
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <configurationFile> ${basedir}/src/main/resources/generatorConfig.xml </configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.29</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>4.0.0</version> </dependency> </dependencies> </plugin>
配置對應的generatorConfig.xml檔案
.yml配置
#通用mapper mapper: mappers: tk.mybatis.mapper.common.Mapper notEmpty: true
掃描器換成tk的
@tk.mybatis.spring.annotation.MapperScan
maven命令
mybatis-generator:generate