springboot + gradle +mybatis +thymeleaf 搭建项目

9 篇文章 0 订阅
4 篇文章 0 订阅

首先是gradle的配置

group 'zhanSystem'
version '1.0-SNAPSHOT'

apply plugin: 'java'


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springVersion")
    }
}

apply plugin: 'org.springframework.boot'

dependencies {

    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("tk.mybatis:mapper-spring-boot-starter:2.0.3")

    compile project(':common-utils')
    compile("org.springframework.boot:spring-boot-starter:$springVersion")
    compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:$mybatisVersion")
    compile("org.springframework.boot:spring-boot-starter-data-redis:$springVersion")
    compile("mysql:mysql-connector-java:$mysqlDriverVersion")
    compile("org.mybatis.caches:mybatis-ehcache:$mybatisEhcacheVersion")
    compile("org.projectlombok:lombok:1.18.0")
    compile("javax.persistence:persistence-api:1.0")
    compile("org.apache.commons:commons-lang3:3.3")
    compile("org.apache.commons:commons-collections4:4.1")
    compile ("commons-beanutils:commons-beanutils:1.9.1")
    compile ("org.springframework.boot:spring-boot-devtools")
    compile group: 'org.apache.poi', name: 'poi', version: '3.12'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.12'
    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'
    /*引入外部JAR包,包文件过大,下载较慢*/
    compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.1'
    compile files('lib/stanford-corenlp-3.9.1-javadoc.jar')
    compile files('lib/stanford-corenlp-3.9.1-models.jar')
    compile files('lib/stanford-corenlp-3.9.1-sources.jar')
    compile files('lib/xom.jar')
    testCompile("org.springframework.boot:spring-boot-starter-test:$springVersion")
}

application.properties配置

spring.profiles.active=dev


#环境变量
server.max-http-header-size=10240
#服务端口
server.port=8069
#mybatis配置
mybatis.mapperLocations = classpath:mapper/*.xml
mybatis.type-aliases-package = com.zhan.model


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


#日志级别
logging.level.com.zhan.config = info
logging.level.com.zhan.controller = info
logging.level.com.zhan.domain = info
logging.level.com.zhan.mapper = debug
logging.level.com.zhan.service = info
logging.level.com.zhan.utils = info
logging.path=/data/logs/TpoWords

#日志颜色
spring.output.ansi.enabled=always


## 数据源配置
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://0.0.0.0:3306/wordsdb?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username =
spring.datasource.password =


启动类

package com.zhan;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import tk.mybatis.spring.annotation.MapperScan;




/**
 * 项目启动类
 * @author bean.zhang
 * @date 2018-07-13
 */
@EnableTransactionManagement
@SpringBootApplication
@MapperScan(basePackages = "com.zhan.mapper")
public class TpoWordApplication {

    public static void main(String[] args) {
        SpringApplication.run(TpoWordApplication.class, args);
    }
}

项目的目录结构

使用Spring Boot、MySQL、MyBatisThymeleaf开发一个Web应用,可以按照以下步骤进行: 1. **项目初始化**: 创建一个新的Spring Boot项目,通常使用Maven或Gradle作为构建工具。 2. **添加依赖**: 在`pom.xml`(Maven)或`build.gradle`(Gradle)中添加相应的依赖: - Spring Web: 提供HTTP服务基础 - Spring Data JPA: 集成数据库操作 - MySQL Driver: 连接MySQL数据库 - MyBatis: 数据访问框架,用于持久层操作 - Thymeleaf: 前端模板引擎,用于HTML页面渲染 ```xml <!-- Maven --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- Gradle --> implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'mysql:mysql-connector-java' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' ``` 3. **配置数据库**: 在`application.properties`或`application.yml`中设置数据库连接信息。 4. **创建实体类**: 根据数据库表结构生成Java实体类,例如`User.java`。 5. **MyBatis配置**: 在`mybatis-config.xml`或使用@Configuration和@Mapper接口定义数据库操作映射。 6. **创建Service层**: 创建业务逻辑处理类,如`UserService.java`,并注入MyBatis的SqlSession。 7. **Controller层**: 使用Spring的@RestController注解创建控制器,处理HTTP请求,调用Service方法。 8. **Thymeleaf视图**: 创建HTML模板文件(`.html`),使用Thymeleaf标签进行数据绑定和条件渲染。 9. **启动应用**: 执行`mvn spring-boot:run`或`gradle bootRun`命令,启动应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值