美文网首页
SpringBoot+Mysql 搭建后端(含model/ser

SpringBoot+Mysql 搭建后端(含model/ser

作者: 李鼎JohnLi | 来源:发表于2020-02-16 11:07 被阅读0次

    1,maven 项目搭建

    具体可以百度,不在赘述.

    POM 代码:

    <?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>
    
    <groupId>xt_001</groupId>
    
    <artifactId>xt_demo</artifactId>
    
    <version>1.0-SNAPSHOT</version>
    
    <parent>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-starter-parent</artifactId>
    
    <version>2.1.6.RELEASE</version>
    
    </parent>
    
    <dependencies>
    
    <dependency>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-starter-web</artifactId>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-starter-jdbc</artifactId>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.mybatis.spring.boot</groupId>
    
    <artifactId>mybatis-spring-boot-starter</artifactId>
    
    <version>2.0.1</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>mysql</groupId>
    
    <artifactId>mysql-connector-java</artifactId>
    
    <version>5.1.47</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    
    <version>2.1.0.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-devtools</artifactId>
    
    <version>2.0.0.RELEASE</version>
    
    </dependency>
    
    <dependency>
    
    <groupId>com.alibaba</groupId>
    
    <artifactId>fastjson</artifactId>
    
    <version>1.2.41</version>
    
    </dependency>
    
    </dependencies>
    
    <build>
    
    <plugins>
    
    <plugin>
    
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-maven-plugin</artifactId>
    
    </plugin>
    
    </plugins>
    
    <resources>
    
    <!-- IDEA-解决: org.apache.ibatis.binding.BindingException:Invalid bound statement (not found) -->
    
               <resource>
    
    <directory>src/main/java</directory>
    
    <includes>
    
    <include>**/*.xml</include>
    
    </includes>
    
    </resource>
    
    </resources>
    
    </build>
    
    </project>
    
    

    2.新建如截图文件夹

    image

    application.yml:

    spring:
    
     profiles:
    
       active: dev
    

    application-dev.yml:

    server:
    
    port:8084
    
    spring:
    
    datasource:
    
    username: root
    
    password: mysql
    
    url: jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=UTC&useSSL=false
    
    driver-class-name: com.mysql.jdbc.Driver
    
    thymeleaf:
    
    cache:false
    
        prefix: classpath:/templates/
    
    suffix: .html
    
    encoding: UTF-8
    
    servlet:
    
    content-type: text/html
    
    mode: HTML5
    
    mybatis:
    
    #  mapper 文件夹在resources 路径下时:
    
      mapper-locations: classpath:mapper/*.xml
    
    #  mapper 文件夹在package  com.xt 路径下时
    
    #  mapper-locations: classpath:mapper/*Mapper.xml
    
    #  mapper-locations: classpath:com/xt/mapper/*Mapper.xml
    
      type-aliases-package: com.xt.entity
    

    application-prd.yml:

    可以拷贝application-dev.yml

    3.AppMain.java 代码:

    package com.xt;
    
    import org.mybatis.spring.annotation.MapperScan;
    
    import org.springframework.boot.SpringApplication;
    
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    
    @MapperScan("com.xt.dao")
    
    public class AppMain {
    
    public static void main(String[] args) {
    
    SpringApplication.run(AppMain.class);
    
    }
    
    }
    

    @MapperScan("com.xt.dao") 作用可以百度

    4.关于easy-code plugin 用法(根据MySQL数据库表,直接生成entity/service/serviceImpl/dao/mapper):

    可以参考 https://www.cnblogs.com/chafe/p/9506001.html

    也可以百度 idea easycode plugin

    方法二:

    https://github.com/838934287/mvc-generate-tool 也可以下载该小工具,修改下MySQL URL 即可使用,也很方面,并且template也可以自己修改.

    相关文章

      网友评论

          本文标题:SpringBoot+Mysql 搭建后端(含model/ser

          本文链接:https://www.haomeiwen.com/subject/belpfhtx.html