springboot+maven+mybatis+mysql实现增删查改1

1、搭建一个springboot项目

new project---》spring initializr---》next

springboot+maven+mybatis+mysql实现增删查改1_第1张图片

适当修改group和artifact,然后next

springboot+maven+mybatis+mysql实现增删查改1_第2张图片

这个页面勾选自己需要的,不勾选也行,我这里是没勾选,依赖通过maven添加

springboot+maven+mybatis+mysql实现增删查改1_第3张图片

点击finish,一个springboot项目就创建成功了

springboot+maven+mybatis+mysql实现增删查改1_第4张图片

2、生成逆向工程

创建目录

springboot+maven+mybatis+mysql实现增删查改1_第5张图片

pom.xml文件



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.18.RELEASE
         
    
    com.jie
    book
    0.0.1-SNAPSHOT
    book
    Demo project for Spring Boot

    
        1.8
    

    
        
        
            org.springframework.boot
            spring-boot-starter-cache
        

        
        
            org.springframework.boot
            spring-boot-starter-data-redis
        


        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
        
            mysql
            mysql-connector-java
            5.1.46
        

        
        
            com.alibaba
            fastjson
            1.2.47
        

        
            net.sourceforge.nekohtml
            nekohtml
            1.9.22
        

        
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.2
        

        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.0
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


application.properties文件

spring.datasource.platform=mysql
spring.datasource.url=jdbc:mysql://localhost/books
spring.datasource.username=root
spring.datasource.password=970817
spring.datasource.driverClassName=com.mysql.jdbc.Driver

server.port=8080
server.session-timeout=30
server.tomcat.uri-encoding=UTF-8

#####springboot 整合 mybatis
mybatis.mapper-locations=classpath:/com/jie/book/mapper/*Mapper.xml
mybatis.config-location=classpath:/com/jie/book/mapper/config/mybatis-config.xml
#####定义别名
mybatis.type-aliases-package=com.jie.book.domain

###Thymeleaf配置
spring.thymeleaf.prefix=classpath:/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=LEGACYHTML5
###过滤中文乱码
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true

添加逆向工程所需的文件

mybatis-config.xml文件



    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    

    
        
        
        
        
        
    

    
    
    
    
    


 

generator.xml文件





    
    
    
        
            
            
            
            
        

        

        
            
        

        
        
            
            
        



        
            
        

        
        
            
            
        

        
        
        
        
        


        
MyBatisGeneratorUtils.java文件
package com.jie.book.util;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MyBatisGeneratorUtils {
    public static void main(String[] args) {
        try {
            System.out.println("start generator ...");
            List warnings = new ArrayList();
            boolean overwrite = true;
            File configFile = new File(MyBatisGeneratorUtils.class.getResource("/generator.xml").getFile());
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
            System.out.println("end generator!");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

运行MyBatisGeneratorUtils,生成

springboot+maven+mybatis+mysql实现增删查改1_第6张图片

接下来就是写代码了,后面有空了在写!

完善后的代码请看https://blog.csdn.net/qq_41534115/article/details/99679186

你可能感兴趣的:(springboot)