您当前的位置: 首页 >  spring

java持续实践

暂无认证

  • 3浏览

    0关注

    746博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

微信小程序day05_03之搭建SpringBoot分层项目

java持续实践 发布时间:2019-04-18 19:52:49 ,浏览量:3

文章目录
      • 一.搭建父工程
      • 二 .创建common模块
      • 三. 创建pojo模块
      • 四. 创建mapper 模块
      • 五. 创建service模块
      • 六. 创建mini-api模块
      • 七.启动项目进行测试

一.搭建父工程

搭建父工程thc-videos-dev . 具体的搭建过程, 可以参考我的另外一篇文章, 链接如下 https://blog.csdn.net/qq_33229669/article/details/88670997

pom文件的内容如下



    4.0.0

    com.thc
    thc-videos-dev
    1.0-SNAPSHOT
    
        thc-videos-dev-common
        thc-videos-dev-pojo
        thc-videos-dev-mapper
        thc-videos-dev-service
        thc-videos-dev-mini-api
    

    pom

    微信小程序-实战
    
        小程序
        maven
        springmvc
        springboot
        mybatis
        mybatis-pagehelper
        redis
        ffmpeg
        druid
        mariadb/mysql
        zookeeper音频操作
    

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

    
        UTF-8
        UTF-8
        1.8
    

二 .创建common模块

在第一步的基础上, 创建common 子模块, 其pom文件的内容如下



    
        thc-videos-dev
        com.thc
        1.0-SNAPSHOT
    
    4.0.0

    thc-videos-dev-common

    
        UTF-8
    

    
        
            org.springframework.boot
            spring-boot-starter
            
                
                
                    org.springframework.boot
                    spring-boot-starter-logging
                
            
        

        
        
            org.springframework.boot
            spring-boot-starter-log4j
            1.3.8.RELEASE
        

        
        
            org.springframework.boot
            spring-boot-starter-aop
        

        
            org.springframework.boot
            spring-boot-starter-web
            
            
        

        
        
            org.springframework.boot
            spring-boot-configuration-processor
            true
        

        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

        
        
            com.alibaba
            druid
            1.1.0
        
        
            com.alibaba
            druid-spring-boot-starter
            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
        

        
        
            commons-codec
            commons-codec
            1.11
        
        
            org.apache.commons
            commons-lang3
            3.4
        
        
            org.apache.commons
            commons-io
            1.3.2
        

        
        
            io.springfox
            springfox-swagger2
            2.4.0
        
        
            io.springfox
            springfox-swagger-ui
            2.4.0
        

        
        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
            redis.clients
            jedis
            2.9.0
        
        
            org.springframework.data
            spring-data-redis
            1.8.7.RELEASE
        

        
        
            org.apache.curator
            curator-framework
            4.0.0
        
        
            org.apache.zookeeper
            zookeeper
            3.4.11
        
        
            org.apache.curator
            curator-recipes
            4.0.0
        
    

三. 创建pojo模块

其pom文件的内容如下



    
        thc-videos-dev
        com.thc
        1.0-SNAPSHOT
    
    4.0.0

    thc-videos-dev-pojo

    
        
            com.thc
            thc-videos-dev-common
            1.0-SNAPSHOT
        
    

四. 创建mapper 模块

其pom文件的内容如下



    
        thc-videos-dev
        com.thc
        1.0-SNAPSHOT
    
    4.0.0

    thc-videos-dev-mapper
    
        
            com.thc
            thc-videos-dev-pojo
            1.0-SNAPSHOT
        

    

五. 创建service模块

其pom文件的内容如下



    
        thc-videos-dev
        com.thc
        1.0-SNAPSHOT
    
    4.0.0

    thc-videos-dev-service

    
        
            com.thc
            thc-videos-dev-mapper
            1.0-SNAPSHOT
        
    

六. 创建mini-api模块

其pom文件的内容如下



    
        thc-videos-dev
        com.thc
        1.0-SNAPSHOT
    
    4.0.0

    thc-videos-dev-mini-api

    
        
            com.thc
            thc-videos-dev-service
            1.0-SNAPSHOT
        
    

在此模块中,创建启动类

package com.thc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * 类名称:Application
 * 类描述:启动类
 *
 * @author:
 * 创建时间:2019/4/18 19:22
 * Version 1.0
 */
@SpringBootApplication
public class Application {

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

创建一个Controller 接口用于测试

package com.thc.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类名称:HelloWorldController
 * 类描述:Controller 测试类
 *
 * @author:
 * 创建时间:2019/4/18 19:31
 * Version 1.0
 */
@RestController
public class HelloWorldController {
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}

在此模块中的resources目录中,创建application.properties 文件, 内容如下

############################################################
#
# REDIS 配置
#
############################################################
# Redis数据库索引(默认为0)
#spring.redis.database=1
## Redis服务器地址
#spring.redis.host=192.168.1.209
## Redis服务器连接端口
#spring.redis.port=6379
## Redis服务器连接密码(默认为空)
#spring.redis.password=imooc
## 连接池最大连接数(使用负值表示没有限制)
#spring.redis.pool.max-active=1000
## 连接池最大阻塞等待时间(使用负值表示没有限制)
#spring.redis.pool.max-wait=-1
## 连接池中的最大空闲连接
#spring.redis.pool.max-idle=10
## 连接池中的最小空闲连接
#spring.redis.pool.min-idle=2
## 连接超时时间(毫秒)
#spring.redis.timeout=0


############################################################
#
# 配置数据源相关	使用阿里巴巴的 druid 数据源
#
############################################################
spring.datasource.url=jdbc:mysql://118.24.145.136:3306/javaweixin6-video-dev
spring.datasource.username=root
spring.datasource.password=utry1234
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 配置
mybatis.type-aliases-package=com.imooc.pojo
mybatis.mapper-locations=classpath:mapper/*.xml
# 通用 Mapper 配置
mapper.mappers=com.imooc.utils.MyMapper
mapper.not-empty=false
mapper.identity=MYSQL
# 分页插件配置
pagehelper.helperDialect=mysql
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql



# 文件上传配置
spring.http.multipart.maxFileSize=100Mb
spring.http.multipart.maxRequestSize=1000Mb

############################################################
#
# Server 服务端相关配置
#
############################################################
# 配置api端口号
server.port=8081

############################################################
# Server - tomcat 相关常用配置
############################################################
# tomcat的URI编码
server.tomcat.uri-encoding=UTF-8
七.启动项目进行测试

运行启动类,启动项目,可以看到项目运行在8081端口 在浏览器中输入http://localhost:8081/hello 响应的数据如下 ,代表成功响应了数据

关注
打赏
1658054974
查看更多评论
立即登录/注册

微信扫码登录

0.0437s