使用SpringBootMybatis怎么实现一个反向工程-创新互联

使用Spring Boot Mybatis 怎么实现一个反向工程?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

中山网站建设公司创新互联,中山网站设计制作,有大型网站制作公司丰富经验。已为中山上千多家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的中山做网站的公司定做!

1. 拷贝 Mybatis 反向工程配置文件到项目的根目录下

使用Spring Boot Mybatis 怎么实现一个反向工程

2. 根据项目及表的情况,修改 GeneratorMapper.xml 配置

  • 如果使用 高版本 , 驱动类变为:com.mysql.cj.jdbc.Driver

  • url 后面应该加属性 nullCatalogMeansCurrent=true ,否则生成有问题

当前版本 MySQL 数据库为 5.7
主要根据注释来修改自己的内容

 
 
 
   
   
 
 
 
   
   
     
     
       
     
     
     
     
 
 
 
 
     
     
       
       
     
 
 
 
 
     
     
       
     
 
 
 
 
 
     
     
       
     
 
 
 
 
 
     
     
 
 
   

此时会报错,如下

使用Spring Boot Mybatis 怎么实现一个反向工程

这个时候可以不用理会,项目也是会正常运行的

Spring Boot 理论+实战系列教程大家看这个:

3. 在pom.xml 文件中添加 mysql 反向工程依赖

 
   
     
     
      org.mybatis.generator 
      mybatis-generator-maven-plugin 
      1.3.6 
       
         
        GeneratorMapper.xml 
        true 
        true 
       
     
   

4. 双击生成相关文件

使用Spring Boot Mybatis 怎么实现一个反向工程

5. 生成的文件

自动生成model/Student、实体类
以及StudentMapper,接口
StudentMapper.xml 具体对数据库的操作
这样方便我们使用,具体的下面详细介绍,注意看注释

使用Spring Boot Mybatis 怎么实现一个反向工程

Student

package com.md.springboot.model; 
 
public class Student { 
  private Integer id; 
 
  private String name; 
 
  private Integer age; 
 
  public Integer getId() { 
    return id; 
  } 
 
  public void setId(Integer id) { 
    this.id = id; 
  } 
 
  public String getName() { 
    return name; 
  } 
 
  public void setName(String name) { 
    this.name = name; 
  } 
 
  public Integer getAge() { 
    return age; 
  } 
 
  public void setAge(Integer age) { 
    this.age = age; 
  } 
}

StudentMapper

package com.md.springboot.mapper; 
 
import com.md.springboot.model.Student; 
 
public interface StudentMapper { 
  int deleteByPrimaryKey(Integer id); 
 
  int insert(Student record); 
 
  int insertSelective(Student record); 
 
  Student selectByPrimaryKey(Integer id); 
 
  int updateByPrimaryKeySelective(Student record); 
 
  int updateByPrimaryKey(Student record); 
}

StudentMapper.xml

 
 
 
 
 
  
  
 
  
  
   
   
   
   
  
 
 
  
  
  id, name, age 
  
 
  
  select  
   
  from t_student 
  where id = #{id,jdbcType=INTEGER} 
  
 
  
  delete from t_student 
  where id = #{id,jdbcType=INTEGER} 
  
 
  
  insert into t_student (id, name, age 
   ) 
  values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} 
   ) 
  
 
 
  
  
  insert into t_student 
   
    
    id, 
    
    
    name, 
    
    
    age, 
    
   
   
    
    #{id,jdbcType=INTEGER}, 
    
    
    #{name,jdbcType=VARCHAR}, 
    
    
    #{age,jdbcType=INTEGER}, 
    
   
  
 
 
  
  update t_student 
   
    
    name = #{name,jdbcType=VARCHAR}, 
    
    
    age = #{age,jdbcType=INTEGER}, 
    
   
  where id = #{id,jdbcType=INTEGER} 
  
 
  
  update t_student 
  set name = #{name,jdbcType=VARCHAR}, 
   age = #{age,jdbcType=INTEGER} 
  where id = #{id,jdbcType=INTEGER} 
  

看完上述内容,你们掌握使用Spring Boot Mybatis 怎么实现一个反向工程的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文题目:使用SpringBootMybatis怎么实现一个反向工程-创新互联
文章网址:http://pwwzsj.com/article/dsejdo.html