之前有写过一篇文章通过RuoYi自动生成SpringBoot项目代码,这篇文章有介绍如何通过RuoYi框架来自动生成相关的SpringBoot代码。但并不是所有的小伙伴都会去下载RuoYi这一套框架代码去获取domain、mapper以及mapping,特此本人再推荐一款很实用并且也容易上手的工具“MybatisGenerator”自动代码生成器,下面将对此做详细的介绍和说明。
1. 文件下载2. 相关配置
(1)数据库驱动包位置(2)数据库链接URL、用户名和密码(3)要生成哪些表 3. 使用方法4. 效果展示
(1)FacilitySideSlopeYH.java(2)FacilitySideSlopeYHMapper.java(3)FacilitySideSlopeYHMapper.xml 5. 结束语
1. 文件下载通过如下地址获取代码生成器工具:
链接: https://pan.baidu.com/s/1saqGTkpSSrNNNfMm6YCjHw?pwd=4guf
提取码: 4guf
得到压缩包文件解压到指定的磁盘后显示如下:
打开generatorConfig.xml配置文件,配置好相关的位置信息。
如下图所示有3个地方需要注意:
即我们使用的是什么数据库,我们就得用什么数据库的驱动jar包,这个在下载文件中已经包含了,拿来直接用即可;
(2)数据库链接URL、用户名和密码这里链接我们的本地地址或者服务器地址都可以,只要是数据库的URL能对应表的名字也没错就行,在将你的用户名和密码均填写正确即可;
(3)要生成哪些表只需要将我们的表名与我们数据库表名保持一致,domainObjectName通过自己的定义即可。
3. 使用方法
(1)切换到配置文件夹位置,打开cmd,输入“生成文件语句.txt”中的代码生成语句:
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
(2)回车运行,显示如下语句,证明所需代码自动生成完毕!
MyBatis Generator finished successfully, there were warnings.4. 效果展示 (1)FacilitySideSlopeYH.java
package com.hncr.asset.domain;
import java.math.BigDecimal;
import java.util.Date;
public class FacilitySideSlopeYH {
private Long id;
private String sideSlopeCode;
private String sideSlopeName;
private String routeCode;
private String routeName;
private String roadSectionCode;
private String trafficDirection;
private String centerStake;
private String startStake;
private Float centerLongitude;
private Float centerLatitude;
private String endStake;
private BigDecimal startLongitude;
private BigDecimal startLatitude;
private BigDecimal endLongitude;
private BigDecimal endLatitude;
private String linkid;
private String picturePath;
private Double slopeLength;
private String slopeType;
private String fillOrCut;
private String maintenanceUnit;
private String remark;
private Integer isDelete;
private String remark1;
private String remark2;
private String remark3;
private String creater;
private Date createTime;
private String updator;
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSideSlopeCode() {
return sideSlopeCode;
}
public void setSideSlopeCode(String sideSlopeCode) {
this.sideSlopeCode = sideSlopeCode == null ? null : sideSlopeCode.trim();
}
public String getSideSlopeName() {
return sideSlopeName;
}
public void setSideSlopeName(String sideSlopeName) {
this.sideSlopeName = sideSlopeName == null ? null : sideSlopeName.trim();
}
public String getRouteCode() {
return routeCode;
}
public void setRouteCode(String routeCode) {
this.routeCode = routeCode == null ? null : routeCode.trim();
}
public String getRouteName() {
return routeName;
}
public void setRouteName(String routeName) {
this.routeName = routeName == null ? null : routeName.trim();
}
public String getRoadSectionCode() {
return roadSectionCode;
}
public void setRoadSectionCode(String roadSectionCode) {
this.roadSectionCode = roadSectionCode == null ? null : roadSectionCode.trim();
}
public String getTrafficDirection() {
return trafficDirection;
}
public void setTrafficDirection(String trafficDirection) {
this.trafficDirection = trafficDirection == null ? null : trafficDirection.trim();
}
public String getCenterStake() {
return centerStake;
}
public void setCenterStake(String centerStake) {
this.centerStake = centerStake == null ? null : centerStake.trim();
}
public String getStartStake() {
return startStake;
}
public void setStartStake(String startStake) {
this.startStake = startStake == null ? null : startStake.trim();
}
public Float getCenterLongitude() {
return centerLongitude;
}
public void setCenterLongitude(Float centerLongitude) {
this.centerLongitude = centerLongitude;
}
public Float getCenterLatitude() {
return centerLatitude;
}
public void setCenterLatitude(Float centerLatitude) {
this.centerLatitude = centerLatitude;
}
public String getEndStake() {
return endStake;
}
public void setEndStake(String endStake) {
this.endStake = endStake == null ? null : endStake.trim();
}
public BigDecimal getStartLongitude() {
return startLongitude;
}
public void setStartLongitude(BigDecimal startLongitude) {
this.startLongitude = startLongitude;
}
public BigDecimal getStartLatitude() {
return startLatitude;
}
public void setStartLatitude(BigDecimal startLatitude) {
this.startLatitude = startLatitude;
}
public BigDecimal getEndLongitude() {
return endLongitude;
}
public void setEndLongitude(BigDecimal endLongitude) {
this.endLongitude = endLongitude;
}
public BigDecimal getEndLatitude() {
return endLatitude;
}
public void setEndLatitude(BigDecimal endLatitude) {
this.endLatitude = endLatitude;
}
public String getlinkid() {
return linkid;
}
public void setlinkid(String linkid) {
this.linkid = linkid == null ? null : linkid.trim();
}
public String getPicturePath() {
return picturePath;
}
public void setPicturePath(String picturePath) {
this.picturePath = picturePath == null ? null : picturePath.trim();
}
public Double getSlopeLength() {
return slopeLength;
}
public void setSlopeLength(Double slopeLength) {
this.slopeLength = slopeLength;
}
public String getSlopeType() {
return slopeType;
}
public void setSlopeType(String slopeType) {
this.slopeType = slopeType == null ? null : slopeType.trim();
}
public String getFillOrCut() {
return fillOrCut;
}
public void setFillOrCut(String fillOrCut) {
this.fillOrCut = fillOrCut == null ? null : fillOrCut.trim();
}
public String getMaintenanceUnit() {
return maintenanceUnit;
}
public void setMaintenanceUnit(String maintenanceUnit) {
this.maintenanceUnit = maintenanceUnit == null ? null : maintenanceUnit.trim();
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Integer getIsDelete() {
return isDelete;
}
public void setIsDelete(Integer isDelete) {
this.isDelete = isDelete;
}
public String getRemark1() {
return remark1;
}
public void setRemark1(String remark1) {
this.remark1 = remark1 == null ? null : remark1.trim();
}
public String getRemark2() {
return remark2;
}
public void setRemark2(String remark2) {
this.remark2 = remark2 == null ? null : remark2.trim();
}
public String getRemark3() {
return remark3;
}
public void setRemark3(String remark3) {
this.remark3 = remark3 == null ? null : remark3.trim();
}
public String getCreater() {
return creater;
}
public void setCreater(String creater) {
this.creater = creater == null ? null : creater.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdator() {
return updator;
}
public void setUpdator(String updator) {
this.updator = updator == null ? null : updator.trim();
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
(2)FacilitySideSlopeYHMapper.java
package com.hncr.asset.mapper;
import com.hncr.asset.domain.FacilitySideSlopeYH;
public interface FacilitySideSlopeYHMapper {
int deleteByPrimaryKey(Long id);
int insert(FacilitySideSlopeYH record);
int insertSelective(FacilitySideSlopeYH record);
FacilitySideSlopeYH selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(FacilitySideSlopeYH record);
int updateByPrimaryKey(FacilitySideSlopeYH record);
}
(3)FacilitySideSlopeYHMapper.xml
5. 结束语id, side_slope_code, side_slope_name, route_code, route_name, road_section_code, traffic_direction, center_stake, start_stake, center_longitude, center_latitude, end_stake, start_longitude, start_latitude, end_longitude, end_latitude, linkid, picture_path, slope_length, slope_type, fill_or_cut, maintenance_unit, remark, is_delete, remark1, remark2, remark3, creater, create_time, updator, update_time
上述自动生成的三层代码能够实现基本的增删改查需求,其他的业务场景只需要在这些代码基础上进行更改即可,我们在开发中其实很多都是重复式的机械运动,上道了以后就会发现这样的工具生成出的代码能节省我们开发的不少时间。后续要做的大部分工作就是将我们的Service层的业务实现写明白,Controller层映射条件写清楚即可。具体也可以将上述的内容与基于SpringBoot_后端接口流程和SpringBoot_实现基本增删改查(前后端分离版)两篇文章结合着看,效果更佳呀!!!
路过的小伙伴,如果博文有帮助到你解决问题,可以点赞+关注一波呀~本人将会持续更新相关学习博文,感谢您的支持哦!!!



