小雷三分钟-Gradle急速上手构建完整项目(二)

该博客在上一节的基础上,详细介绍了如何使用Gradle为Java项目添加数据控制层,涉及MySQL数据库的配置、DAO层、Service层、Controller层的代码编写以及实体类的创建。通过这些步骤,项目成功启动并完成了验证。
摘要由CSDN通过智能技术生成

在上一节基础上增加数据控制层(mysql)

话不多说,直接上干货

增加的目录结构如下:
在这里插入图片描述
新增依赖配置如下

configurations.all {
    exclude group: "org.slf4j", module: "slf4j-log4j12"
    exclude group: "log4j", module: "log4j"
}
buildscript {
    ext {
        springBootVersion = '1.4.0.BUILD-SNAPSHOT'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/plugins-snapshot" }
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }

    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:0.6.0.BUILD-SNAPSHOT"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE"
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
    baseName = 'TESTBOOT'
    version =  '1.0.0'
}

repositories {
    mavenCentral()
}
//JDK版本
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    //providedCompile("org.springframework.boot:spring-boot-starter-tomcat")
    compile group: 'com.alibaba', name: 'druid', version:'0.2.15'
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-jdbc")
    compile("org.springframework.boot:spring-boot-starter-amqp")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-test")
    compile("org.springframework:spring-tx")
    compile("org.mybatis:mybatis-spring:1.2.5")
    compile("org.mybatis:mybatis:3.3.1")
    compile("io.springfox:springfox-swagger2:2.2.2")
    compile("io.springfox:springfox-swagger-ui:2.2.2")
    compile("org.apache.httpcomponents:httpclient:4.5.1")
    compile('com.alibaba:fastjson:1.2.47')
    compile('mysql:mysql-connector-java:5.1.18')
    compile('com.google.zxing:core:3.2.1')

    compile "ch.qos.logback:logback-classic:1.1.3"
    compile "org.slf4j:log4j-over-slf4j:1.7.13"
    compile fileTree(dir: './libs', include: '*.jar')
    testCompile("junit:junit")
}

//添加以下配置
task wrapper(type: Wrapper) {
    gradleVersion = '3.4'
}

如果有自己的自定义包直接放到libs文件夹内,刷新gradle即可;
在这里插入图片描述
增加数据库配置信息application-dev.properties

#数据源配置
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ant?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
#验证连接的有效性
spring.datasource.test-while-idle=true
#获取连接时候验证,会影响性能
spring.datasource.test-on-borrow=true
#在连接归还到连接池时是否测试该连接
spring.datasource.test-on-return=true
spring.datasource.validation-query=SELECT 1 FROM DUAL
#空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
spring.datasource.time-between-eviction-runs-millis=300000
#连接池空闲连接的有效时间 ,设置30分钟
spring.datasource.min-evictable-idle-time-millis=1800000
spring.datasource.max-idle=20
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
spring.datasource.jdbc-interceptors=ConnectionState;SlowQueryReport(threshold=0)
#开发环境端口配置
server.port=8725
#log4j日志输出配置
logging.level.org.apache.ibatis=DEBUG
logging.level.org.springframework.jdbc=DEBUG
logging.level.org.springframework.boot=DEBUG
logging.level.java.sql.Connection=DEBUG
logging.level.java.sql.Statement=DEBUG
logging.level.java.sql.PreparedStatement=DEBUG
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

增加dao层代码

package com.ant.app.dao;

import com.ant.app.entity.AboutUs;
import org.apache.ibatis.annotations.Select;<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值