Eclipse搭建springBoot进阶篇-SpringBoot+Mybatis

Eclipse搭建springBoot入门篇 

https://blog.csdn.net/qq_17025903/article/details/85675839

在入门篇了搭建了一个简单的SpringBoot的Demo,在进阶篇将真正引入实战,也就是能支撑基本的企业中小型项目开发。

本次通过springBoot+Mybatis+maven等搭建一个适用于开发中小型项目的简单架构

pom文件 需要更新maven 的jar,对java包进行下载。



	4.0.0

	com.kero99
	springBoot_YGC
	0.0.1-SNAPSHOT
	jar

	springBoot_YGC
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.0.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter
			
				
					org.springframework.boot
					spring-boot-starter-logging
				
			
		
		 
		 
        org.slf4j
        slf4j-nop
        1.7.25
     

		

		
		
		
		    org.springframework.boot
		    spring-boot-starter-aop
		
		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
		
		
		
		
		
		
		
		
			org.springframework.boot
			spring-boot-devtools
			
			true
		
		
		
			org.springframework.boot
			spring-boot-configuration-processor
			true
		

		
		
			org.springframework.boot
			spring-boot-starter-freemarker
		
		
		
		
			org.springframework.boot
			spring-boot-starter-thymeleaf
		
		
		
			com.alibaba
			druid
			1.1.0
		

		
			mysql
			mysql-connector-java
			5.1.41
		

		
		
		    org.mybatis.spring.boot
		    mybatis-spring-boot-starter
		    1.3.1
		
		
		
		    tk.mybatis
		    mapper-spring-boot-starter
		    1.2.4
		
		
		
		    com.github.pagehelper
		    pagehelper-spring-boot-starter
		    1.2.3
		

		
			com.alibaba
			druid-spring-boot-starter
			1.1.9
		

		
			org.mybatis.generator
			mybatis-generator-core
			1.3.2
			compile
			true
		
		
		
		
			org.springframework.boot
			spring-boot-starter-data-redis
		
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	



application.properties

配置了redis,mybaits数据库连接及mapper映射位置以及freemarker和thymeleaf用来做动态html页面


#spring.thymeleaf.chche=true

spring.devtools.restart.enabled=false

spring.devtools.restart.additional-paths=src/main/java

restart.include.mapper=/mapper-[\\w-\\.]+jar
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar

#spring.devtools.restart.exclude=static/**,public/**

#spring.devtools.restart.exclude=WEB-INF/**


spring.redis.database=1

spring.redis.host=127.0.0.1

spring.redis.port=6379 

spring.redis.password=

spring.redis.pool.max-active=1000

spring.redis.pool.max-wait=10000;

spring.redis.pool.max-idle=10

spring.redis.pool.min-idle=2

spring.redis.timeout=10000





spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.initial-size=1
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=20
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.stat-view-servlet.allow=true



# mybatis 
mybatis.type-aliases-package=com.kero99.pojo
mybatis.mapper-locations=classpath:mapper/*.xml

mapper.mappers=com.kero99.utils.BaseMapper
mapper.not-empty=false
mapper.identity=MYSQL

pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql



#spring.messages.basename=i18n/messages
#spring.messages.cache-seconds=3600
#spring.messages.encoding=UTF-8



spring.mvc.static-path-pattern=/static/**


# freemarker

spring.freemarker.template-loader-path=classpath:/templates
#关闭缓存,即时刷新,上线生成环境需要改为true
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl



# thymeleaf



spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html


#关闭缓存,即时刷新,上线生成环境需要改为true
spring.thymeleaf.cache=false



#server.port=8081
#server.context-path=/kero99
server.session-timeout=60
#server.address=192.168.1.2
#server.tomcat.max-threads=250
server.tomcat.uri-encoding=UTF-8
#server.tomcat.basedir=H:/springboot-tomcat-tmp
#server.tomcat.access-log-enabled=true
#server.tomcat.access-log-pattern=
#server.tomcat.accesslog.directory=
#logging.path=H:/springboot-tomcat-tmp
#logging.file=myapp.log


需要在util下创建 BaseMapper用来做api函数查询--优点不用写sql 傻瓜式查询比较方便,但是复杂查询建议用xml,这里我俩种都有集成。

/**
 * 基础Mapper类
 * @author kero99
 */
public interface BaseMapper extends Mapper, MySqlMapper {
    //TODO
    //FIXME 特别注意,该接口不能被扫描到,否则会出错
}

generatorConfig.xml  一个快速生成方法、类、xml、实体的工具可以大幅度提高生产速度。





    
        
        

        
            
        

        
        

        
        

		
        

		
        


		

这里需要写到对应的包下

package com.kero99.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

public class GeneratorDisplay {

	public void generator() throws Exception{

		List warnings = new ArrayList();
		boolean overwrite = true;
		//指定 逆向工程配置文件
		File configFile = new File("generatorConfig.xml"); 
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(configFile);
		DefaultShellCallback callback = new DefaultShellCallback(overwrite);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
				callback, warnings);
		myBatisGenerator.generate(null);

	} 
	
	public static void main(String[] args) throws Exception {
		try {
			GeneratorDisplay generatorSqlmap = new GeneratorDisplay();
			generatorSqlmap.generator();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}

项目整体结构

Eclipse搭建springBoot进阶篇-SpringBoot+Mybatis_第1张图片

 持续关注哦,后续会分享项目源码,以及springBoot+MyBatis的升级版集成springCloud实现微服务的搭建。

更新后的 

SpringBoot架构演进之SpringCloud集成eureka构建高可用项目

SpringBoot+Mybatis搭建之采坑记录(持续更新...)

SpringBoot下多文件上传详解例子

SpringBoot文件上传简单Demo

 

你可能感兴趣的:(程序式界)