使用Spring Boot Mybatis 搞反向工程的步骤

网友投稿 460 2023-02-20

使用Spring Boot Mybatis 搞反向工程的步骤

使用Spring Boot Mybatis 搞反向工程的步骤

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

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

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

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

当前版本 MySQL 数据库为 5.7

主要根据注释来修改自己的内容

PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

connectionURL="jdbc:mysql://localhost:3306/springboot"

userId="root"

password="123456">

connectionURL="jdbc:mysql://localhost:3306/springboot"

userId="root"

password="123456">

targetProject="src/main/java">

targetProject="src/main/java">

http://

targetProject="src/main/java">

targetProject="src/main/java">

targetPackage="com.md.springboot.mapper" tahttp://rgetProject="src/main/java">

targetPackage="com.md.springboot.mapper" tahttp://rgetProject="src/main/java">

enableCountByExample="false"

enableUpdateByExample="false"

enableDeleteByExample="false"

enableSelectByExample="false"

selectByExampleQueryId="false"/>

此时会报错,如下

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

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

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

org.mybatis.generator

mybatis-generator-maven-plugin

1.3.6

GeneratorMapper.xml

true

true

4. 双击生成相关文件

5. 生成的文件

自动生成model/Student、实体类

以及StudentMapper,接口

StudentMapper.xml 具体对数据库的操作

这样方便我们使用,具体的下面详细介绍,注意看注释

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_sthttp://udent

set name = #{name,jdbcType=VARCHAR},

age = #{age,jdbcType=INTEGER}

where id = #{id,jdbcType=INTEGER}

以上就是使用Spring Boot Mybatis 搞反向工程的步骤的详细内容,更多关于Spring Boot Mybatis 搞反向工程的资料请关注我们其它相关文章!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:移动应用后端开发(移动应用开发前端)
下一篇:小程序跳转到其他小程序(小程序跳转到其他小程序再跳回来)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~