SpringBoot + Maven

JDK:11
Eclipse:201903版本
Maven:apache-maven-3.5.2
MySQL:8.0.16

創建Maven工程

 

服務Path指定 / 指定HTML、JS、CSS文件
        application.properties

#指定HTML、JS、CSS文件
spring.mvc.static-path-pattern: /static/**
spring.resources.static-locations=classpath:/static/
#服務Path指定
server.servlet.context-path=/xxx

mybatis        

<dependency>
         <groupId>org.mybatis</groupId>
         <artifactId>mybatis</artifactId>
         <version>3.5.1</version>
</dependency>

SpringBoot與Mybatis整合:
        pom.xml            

<dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.0.1</version>
</dependency>
<resources>
         <resource>
             <directory>src/main/resources</directory>
             <includes>
                 <!--包含文件夾以及子文件夾下所有資源-->
                 <!--目的是mvn命令編譯時,包含static下的所有前臺文件-->
                 <include>**/*.*</include>
             </includes>
             <filtering>false</filtering>
         </resource>
         <resource>
             <directory>src/main/java</directory>
             <includes>
                 <!--如果沒有這部分,mvn命令編譯時Mybitas的XML不會導進來-->
                 <include>**/*.xml</include>
             </includes>
             <filtering>false</filtering>
         </resource>
     </resources>

 

        application.properties        

mybatis.config-locations=classpath:mybatis-config.xml
        mybatis.mapper-locations=classpath:com/**/mapper/*.xml

 log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="DEBUG">
            <AppenderRef ref="Console"/>
        </Root>
        <logger name="java.sql" level="DEBUG"></logger>
        <logger name="org.apache.ibatis" level="INFO"></logger>
    </Loggers>
</Configuration>

錯誤信息:

        java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more…

        解決方案:1。 修改pom文件,使用低版本MySQL5.*;
                 2。 如果使用MySQL8.0的高版本,在jdbc連接、驅動中添加&serverTimezone=UTC。
                     例子:jdbc:mysql://localhost:3306/XXXX?allowMultiQueries=true&serverTimezone=UTC

 完整的工程結構

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章