基于maven的SpringBoot、SpringMVC、MyBatis的项目搭建

基于maven的SpringBoot、SpringMVC、MyBatis的项目搭建

一、创建一个maven项目:

基于maven的SpringBoot、SpringMVC、MyBatis的项目搭建_第1张图片

next基于maven的SpringBoot、SpringMVC、MyBatis的项目搭建_第2张图片

最后:项目基础目录(这是所有准备工作完成后的目录)

基于maven的SpringBoot、SpringMVC、MyBatis的项目搭建_第3张图片


二、项目一些简单的配置:

1、pom.xml:


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0modelVersion>
    
     
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.0.5.RELEASEversion>
    parent>

    <groupId>cn.itsourcegroupId>
    <artifactId>springboot_domeartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>springboot_domename>
    <description>Demo project for Spring Bootdescription>

    <properties>
        <java.version>1.8java.version>
    properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
        dependency>

        
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>1.1.1version>
        dependency>

        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>1.1.6version>
        dependency>

        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>5.1.38version>
        dependency>

        
        
        
         
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <version>1.16.18version>
        dependency>

        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
            <version>1.2.4version>
        dependency>

        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-configuration-processorartifactId>
            <optional>trueoptional>
        dependency>

    dependencies>

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

project>

2、主启动类:

@MapperScan(“cn.itsource.springboot_dome.mapper”):扫描mapper接口的路径

/**=================================================================
 * 步骤:
 *      1、@SpringBootApplication:申明主配置类
 *      2、@MapperScan("cn.itsource.springboot_dome.mapper"):扫描mapper接口的路径
 ==================================================================*/
@SpringBootApplication
@MapperScan("cn.itsource.springboot_dome.mapper")
public class SpringbootDomeApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootDomeApplication.class, args);
    }
}

3、application.yml:

#后台端口
server:
  port: 80

#连接
spring:
  #项目数据库的连接
  #注意:当只有一个连接(datasource)时,spring会默认连接,并且是使用 url
  #     当时当有两个连接时,需要一个连接配置类:QuartzDataSourceConfig,并且使用 jdbcUrl(这里你不需要注意)
  #
  # 这里注意要根据你的数据库信息更改数据
  datasource:
    username: root
    password: adminpass
    url: jdbc:mysql://localhost:3306/pethome?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
    driver-class-name: com.mysql.jdbc.Driver
    #使用这个DruidDataSource,必须在pom中使用 ————————》连接池:阿里的德鲁伊连接池 druid
    type: com.alibaba.druid.pool.DruidDataSource

#mybatis的mapper.xml路径
mybatis:
  mapper-locations: classpath:cn/itsource/pethome/*/mapper/*Mapper.xml
  #别名
  #type-aliases-package:

4、云共享:

​ 码云仓库:https://gitee.com/davise/springboot_dome

​ 码云下载地址:https://gitee.com/davise/springboot_dome.git
*/mapper/*Mapper.xml
#别名
#type-aliases-package:


### 4、云共享:

​	码云仓库:https://gitee.com/davise/springboot_dome

​	码云下载地址:https://gitee.com/davise/springboot_dome.git

你可能感兴趣的:(SpringBoot,java)