zoukankan      html  css  js  c++  java
  • Spring Boot + Mybatis

    Idea创建Spring Boot项目基于Mybatis

    目录结构

     

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.2.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.nf147</groupId>
        <artifactId>platform</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>platform_back</name>
        <description>Policy Publishing Platform</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
    
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.1</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!--添加适用于生产环境的功能,如性能指标和监测等功能。 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!-- 数据库驱动以及数据库连接池-->
            <dependency>
                <groupId>org.mariadb.jdbc</groupId>
                <artifactId>mariadb-java-client</artifactId>
                <version>2.3.0</version>
            </dependency>
    
            <!--静态页面配置支持-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
    
            <!--连接池-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.0</version>
            </dependency>
    
            <!--热部署配置-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <dependencies>
                        <!-- spring热部署 -->
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>springloaded</artifactId>
                            <version>1.2.6.RELEASE</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    </project>

    application.properties

    server.port=8082
    # 数据源
    spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
    spring.datasource.url=jdbc:mariadb://localhost:3306/testdb
    spring.datasource.username=root
    spring.datasource.password=dz520123
    mybatis.typeAliasesPackage=com.nf147.platform.entity
    mybatis.mapperLocations=classpath:mappers/*.xml
    
    # 使用druid连接的配置
    filters:stat
    maxActive:20
    initialSize:1
    maxWait:60000
    minIdle:10
    maxIdle:15
    timeBetweenEvictionRunsMillis:60000
    minEvictableIdleTimeMillis:300000
    validationQuery:SELECT 1
    testWhileIdle:true
    testOnBorrow:false
    testOnReturn:false
    maxOpenPreparedStatements:20
    removeAbandoned:true
    removeAbandonedTimeout:1800
    logAbandoned:true
    
    # 定位模板的目录
    spring.mvc.view.prefix=classpath:/templates/
    # 给返回的页面添加后缀名
    spring.mvc.view.suffix=.html
    
    # jpa
    spring.jpa.database-platform=org.hibernate.dialect.MariaDB10Dialect
    # 监控
    management.endpoints.web.exposure.include=*
    # 使用druid数据源
    type=com.alibaba.druid.pool.DruidDataSource

    mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
    
    
    <configuration>
        <settings>
            <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
            <setting name="useGeneratedKeys" value="true" />
            <!-- 使用列别名替换列名 默认:true -->
            <setting name="useColumnLabel" value="true" />
            <!-- 开启驼峰命名转换:Table {create_time} -> Entity {createTime} -->
            <setting name="mapUnderscoreToCamelCase" value="true" />
            
            <setting name="logImpl" value="SLF4J"/>
        </settings>
    
        <plugins>
            <plugin interceptor="com.github.pagehelper.PageInterceptor" />
        </plugins>
    </configuration>
    Application
    package com.nf147.platform;
    
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    
    @SpringBootApplication
    @MapperScan("com.nf147.platform.dao")
    public class PlatformApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(PlatformApplication.class, args);
        }
    
    }

    其余根据自身Bean写就可以了

  • 相关阅读:
    四、Ubuntu16.04下TestLink的部署【测试管理必备工具】
    配置反向代理服务器
    三、Ubuntu16.04 安装Jira8.2.2(自带中文包)和破解
    二、Ubuntu16.04安装搜狗wps
    【C#实现漫画算法系列】-判断 2 的乘方
    [Entity Framework+MVC复习总结1]-WebForm与Asp.Net MVC
    【数据结构总结1】-数据结构的自述
    快速理解区块链
    CSS容器属性
    CSS background-clip 属性
  • 原文地址:https://www.cnblogs.com/dzcici/p/10290757.html
Copyright © 2011-2022 走看看