spring boot(23) : springboot-mybatis-mysql web服务构建

简单 springboot-mybatis-mysql 构建web服务

版本

  • springboot : 2.0.3.RELEASE
  • mybatis : 1.3.1

项目结构

springboot-start
    src
        java
            cn.nordrassil.start.controller
                SystemController.java 
            cn.nordrassil.start.repository.entity
            cn.nordrassil.start.repository.mapper
            Application.java
        reposources
            mapper
            application.properties
    pom.xml

pom.xml



    4.0.0

    cn.nordrassil
    springboot-start
    1.0-SNAPSHOT


    jar

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

    
        1.8
        1.3.1
        2.9.8
    

    
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            ${mybatis-spring-boot.version}
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            mysql
            mysql-connector-java
            runtime
        
        
            com.fasterxml.jackson.core
            jackson-databind
            ${jackson.version}
        
        
            com.fasterxml.jackson.core
            jackson-core
            ${jackson.version}
        
    

    
        springboot-start
        
            
                src/main/java
                
                    **/*.yml
                    **/*.properties
                    **/*.xml
                
                false
            
            
                src/main/resources
                
                    **/*.yml
                    **/*.properties
                    **/*.xml
                
                false
            
        
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                    cn.nordrassil.start.Application
                    ZIP
                    true
                
                
                    
                        
                            repackage
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    true
                
            
        
    


application.properties

server.port=8001

mybatis.configuration.map-underscore-to-camel-case=true
mybatis.mapper-locations=classpath:mapper/*.xml

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8&useSSL=false&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=root

Application.java

package cn.nordrassil.start;

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

@SpringBootApplication(scanBasePackages = {"cn.nordrassil.start"})
@MapperScan(basePackages = {"cn.nordrassil.start.repository.mapper"})
public class Application {

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

SystemController.java

package cn.nordrassil.start.controller;

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

/**
 * @Auther: liyue
 * @Date: 2020/4/27 15:13
 * @Description:
 */
@RestController
public class SystemController {

    public final static String SUCCESS = "SUCCESS";

    @RequestMapping("/live")
    public String live() {
        return SUCCESS;
    }
}

logback-spring.xml



    
    
    

    

    
    
    
    

    
    

    
    
        
            
            DEBUG
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    

    
    
        ${LOG_FILE_DIR}/${appName}.log
        true
        
        
            
            30
            
            500MB
            
            20GB
            ${HIS_LOG_FILE_DIR}/${appName}.%d{yyyy-MM-dd}.log.%i.gz
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%logger{36}:%line|%thread|%X{traceId}|%msg%n
        
    

    
        
        
        
        0
        1024
        true
        
    

    
        
            
        
    

    
        
            
        
    

运行

直接运行 Application.java即可启动项目

测试

访问下面地址获得反馈既说明运行成功

http://127.0.0.1:8001/live

打包

项目根路径下执行如下命令即可完成打包

mvn clean package

部署

打包之后在 targe 文件夹中会生成.jar文件,执行如下命令即可完成部署

nohup java -jar springboot-start.jar  &

END。

你可能感兴趣的:(#,springboot,springboot,mybatis,mysql,web服务构建)