通过建好的数据库表,自动生成代码,具备基本的增删查改,批量操作功能,不需要手写sql。
拉取生成器项目
git clone https://gitlab.tcsoft.info:8988/tcc-open-source/ofa-mybatis-generator.git
修改数据库配置
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://ip:port/db?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("user");
dsc.setPassword("password");
运行main方法
model:
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="OfaUser对象", description="用户表")
public class OfaUser implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "账号")
private String userName;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "手机号码")
private String mobile;
@ApiModelProperty(value = "邮件")
private String email;
@ApiModelProperty(value = "启用状态,1启动,0禁用")
private Integer enable;
@ApiModelProperty(value = "用户类型,0超管,1管理员,2普通用户")
private Integer userType;
@ApiModelProperty(value = "最后登录ip")
private String lastLoginIp;
@ApiModelProperty(value = "最后登录时间")
private LocalDateTime lastLoginTime;
private String createBy;
private LocalDateTime createTime;
private LocalDateTime updateTime;
@ApiModelProperty(value = "租户id")
private Long orgId;
controller:
@RestController
@RequestMapping("/admin/ofaUser")
public class OfaUserController extends BaseController {
}
service:
/**
* <p>
* 用户表 服务实现类
* </p>
*
* @author liuzhibin
* @since 2019-11-06
*/
@Service
public class OfaUserServiceImpl extends ServiceImpl<OfaUserMapper, OfaUser> implements IOfaUserService {
}
/**
* <p>
* 用户表 服务类
* </p>
*
* @author liuzhibin
* @since 2019-11-06
*/
public interface IOfaUserService extends IService<OfaUser> {
}
mapper:
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author liuzhibin
* @since 2019-11-06
*/
public interface OfaUserMapper extends BaseMapper<OfaUser> {
}
xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.tcc.ofa.admin.mapper.OfaUserMapper">
</mapper>