idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis

使用工具idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis

1、新建项目

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第1张图片

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第2张图片

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第3张图片

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第4张图片

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第5张图片

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第6张图片

说明:1、src为源码路径,开发主要在src下

    2、src/main/java下放java文件

    3、src/main/resources下放配置文件

    4、src/test/java下放test测试案例

    5、build.gradle文件:gradle配置文件

 

2.配置build.gradle文件

buildscript { // 第三方插件
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories { // maven仓库地址
maven{url 'http://xxxx/'} // 私库
mavenCentral()
}
dependencies { // 依赖项
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

buildscript中的声明是gradle脚本自身需要使用的资源

apply plugin: 'java' // java项目
apply plugin: 'eclipse' // eclipse开发环境构建,生成所需要的.project,.classpath等文件
apply plugin: 'org.springframework.boot'
jar {
baseName = 'shop-supplier'
version = '1.0.0-SNAPSHOT'
}
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories { // maven仓库地址
maven{url '私服地址'}
mavenCentral()
}

dependencies { // 依赖项
// web thymeleaf
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')

// test
testCompile('org.springframework.boot:spring-boot-starter-test')

//添加 google二维码
compile 'com.google.zxing:core:3.2.0'
}
3.配置mybatis

idea 2017.2开发,gradle构建项目,使用的技术有spring-boot、mybatis_第7张图片


mybatis-config.xml:mybatis配置文件
mybatis/mapper文件夹下时mybatis的mapper.xml文件


3.application.properties:项目配置文件,内容如下:
# 数据库配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dbname?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=round&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=1

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# mybatis配置
mybatis.config-location=classpath:mybatis-config.xml // 配置文件位置
mybatis.typeAliasesPackage=com.my.domain // 实体类包
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml // mapper文件位置
#log
logging.file=log.log
logging.level.com=info
logging.level.org=info
logging.level.com.my=debug
debug=true
logging.level.com.my.web = debug

4.mapper文件




  
  
    
    
    
  

  
  
  
    INSERT INTO 表名 (id, user_name) VALUES (#{属性id}, #{属性userName})