Spring Boot配置所需要的jar包

Java 发表评论
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- 分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- alibaba的druid数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.9</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!--jsp依赖,试图解析器使用-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>compile</scope>
        </dependency>
        <!--热更新,热加载,不用每次重启启动类-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
            <scope>true</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>
    </dependencies>

配置jar包完成后 一共有76个在左边的External Libraries中数一下,

 

在application.properties中配置:

#mybatis起别名
mybatis.type-aliases-package=com.test.po//自己创建的po层。
#jdbc
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/emp?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true
#spring.datasource.username=root
#spring.datasource.password=ROOT

#spring-boot整合Druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/emp?allowMultiQueries=true&autoReconnect=true 
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driverClassName=com.mysql.jdbc.Driver

#dataSource Pool configuration
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000   
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.exceptionSorter=true
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.filters=stat,wall,log4j
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
spring.datasource.useGlobalDataSourceStat=true


#设置jsp 访问资源前缀
spring.mvc.view.prefix=/WEB-INF/views/
#设置jsp 访问资源后缀
spring.mvc.view.suffix=.jsp


   

//在SpringbootMybatis01Application类中配置一下注解
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.test.dao")
public class SpringbootMybatis01Application {

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

在创建Spring Boot中 没有webapp,需要自己创建!!!!

然后运行SpringbootMybatis01Application类,

如果最后显示出了“2018-07-25 20:28:18.218  INFO 2540 — [  restartedMain] com.test.SpringbootMybatis01Application  : Started SpringbootMybatis01Application in 3.256 seconds (JVM running for 4.172)”这样一句话,就说明Spring Boot就创建成功了!!

 

总结:在创建此项目过程中,一定要用心,不然会出现很多不必要的Bug,

在写SQL语句的时候,如果两个表之间有相同的字段,我们需要给他们取别名,以作区分。

所有配置及注解都要小心,不要配错,不然很麻烦,

小编这里就遇到了上面说的问题,但后来给他们取了别名之后,问题就解决了!

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

昵称 *