SpringBoot 配置文件以及依賴 加上跨域配置文件

配置目錄:java

 

application.properties的配置git

#設置服務端口號
server.port = 8090

#配置數據源
spring.datasource.driver-class-name = org.mariadb.jdbc.Driver
spring.datasource.url = jdbc:mariadb://localhost:3306/數據庫名
spring.datasource.username = root
spring.datasource.password = 123456

#鏈接池
spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource

# 配置 mybatis
mybatis.config-location=classpath:mybatis/mybatis-config.xml
# 設置 別名類型包 (實體類)
mybatis.type-aliases-package=com.hjb.carsales.entity
# 設置 mybatis 映射 的 SQL語法 xml文件
mybatis.mapper-locations=classpath:mapper/*.xml

#設置日誌
logging.config=classpath:mybatis/logback-spring.xml

#JpaRepository save()加上下面一句話 才起做用
spring.jpa.hibernate.ddl-auto = update

#配置分頁
pagehelper.helper-dialect= mariadb
pagehelper.reasonable= true

#若是是mariadb,須要配置以下
spring.jpa.database-platform=org.hibernate.dialect.MariaDB10Dialect
View Code

 

generatorConfig.xml的配置github

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

    <!--<properties resource="application.properties" />-->

    <context id="main" targetRuntime="MyBatis3Simple">

        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
                        connectionURL="jdbc:mariadb://localhost:3306/數據庫名"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <javaModelGenerator targetPackage="com.hjb.carsales.entity" targetProject="src\main\java">
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mapper"  targetProject="src\main\resources">
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.hjb.carsales.dao"  targetProject="src\main\java">
        </javaClientGenerator>

        <table tableName="%">
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="ID" sqlStatement="JDBC" identity="true" />
        </table>
    </context>
</generatorConfiguration>
View Code

 

logback-spring.xml日誌配置web

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %msg%n
            </Pattern>
        </layout>
    </appender>

    <logger name="com.hjb.carsales.dao" level="TRACE" />

    <root level="error">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
View Code

 

mybatis-config.xml的配置spring

<?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="cacheEnabled" value="true"/>
    </settings>

    <!--<plugins>-->
        <!--<plugin interceptor="com.github.pagehelper.PageInterceptor" />-->
    <!--</plugins>-->

</configuration>
View Code

 

pom.xml依賴配置sql

<dependencies>
        <!--監控容器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- 資源庫 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!--視圖引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- 熱部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- Tomcat -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- springboot 自動配置 -->
        <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>
        <!--c3p0 鏈接池-->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
        <!--分頁-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.4</version>
        </dependency>
        <!--shiro-->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.4.0</version>
        </dependency>

    </dependencies>
View Code

 

插件的配置數據庫

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>

                <configuration>
                    <configurationFile>${basedir}/src/main/resources/mybatis/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>org.mariadb.jdbc</groupId>
                        <artifactId>mariadb-java-client</artifactId>
                        <version>2.3.0</version>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>
    </build>
View Code

 

跨域配置文件apache

@Configuration
public class CorsFiter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.setHeader("Access-Control-Allow-Origin","http://localhost:8080");
        response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS");
        response.setHeader("Access-Control-Allow-Credentials","true");
        response.setHeader("Access-Control-Max-Age","3600");
        response.setHeader("Access-Control-Allow-Headers","X-Requested-with,Content-Type");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }
}
View Code
相關文章
相關標籤/搜索