迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:fount4j-generator开源软件地址:https://gitee.com/mwxx/fount4j-generator开源软件介绍:Fount4j GeneratorFount4j Generator 是使用 Java 语言编写的,基于 Beetl 模板引擎的数据库反向工程项目。内置 MyBatis 的 Entity、Dao、Mapper 文件模板。 特点
用法命令行方式启动
使用项目源码git clone 或者 zip 打包下载项目 使用项目 jar 包
项目依赖的库帮助配置文件对 YAML 配置文件不熟悉的可以先通过YAML 教程了解配置文件的语法。 # 需要加入到 classPath 中的 jar 包classPathEntry: - "./libs/h2-1.4.193.jar"dataSource: class: com.fount4j.generator.introspector.DataSourceIntrospector driverClass: org.h2.Driver url: jdbc:h2:file:./assets/data/fount4j-generator user: sa password: "" # 其他属性会在创建数据库连接时传入 DriverManager.getConnection(url, properties) 方法 # 如:MySQL 需要配置“useInformationSchema: "true"”才能获取到表的注释 otherProperty: ""# 模板配置template: # Beetl 配置文件的位置,默认从 ClassPath 加载文件,如以 file: 开头则以绝对路径加载配置 config: ./config/beetl.cfg # 模板根目录 root: ./template/# 基础解析器配置,继承 com.fount4j.generator.introspect.TableIntrospectorector 可以实现更多自定义操作tableIntrospector: com.fount4j.generator.introspector.extend.TableIntrospector# 表字段解析器columnIntrospector: com.fount4j.generator.introspector.extend.ColumnIntrospectorintrospectors: - # 解析器的类路径 class: com.fount4j.generator.introspector.extend.EntityIntrospector # 模板文件名以及解析结果在模板变量中的键值 infoKey: entity # 是否生成文件,有的解析器只负责解析参数,不生成文件 generate: true # 是否忽略数据库表的前缀,多个前缀使用“,”隔开,如“FT_,SYS_” # 配置该参数后,“FT_USER”表转换实体类名称时,按照表名为“USER”处理 ignoreTablePrefix: FT_ # 代码路径 resourcePath: E:\code\fount4j-generator\src\main\resources # 实体类包路径 packageName: com.fount4j.demo.entity # 实体类中要添加的导入,例如放在不同包下面的父类 imports: - com.fount4j.base.entity.BaseEntity - # 项目内部封装了 entity, dao, mapper 三种 type # 当配置了 type 时,可以不配置 class 以及 infoKey # type: entity 等同于 class: com.fount4j.generator.introspector.extend.EntityIntrospector infoKey: entity # type: dao 等同于 class: com.fount4j.generator.introspector.extend.DaoIntrospector infoKey: dao # type: mapper 等同于 class: com.fount4j.generator.introspector.extend.MyBatisMapperIntrospector infoKey: mapper type: dao resourcePath: ./src/main/resources packageName: com.fount4j.demo.dao # Dao 类名相对于 Entity 的后缀,如 Entity 为 User,那么 Dao 类的名字会是 UserDao nameSuffix: Dao # Dao 中要添加的导入,如 Spring 的 Repository 注解 imports: - org.springframework.stereotype.Repository - class: com.fount4j.generator.introspector.extend.MyBatisMapperIntrospector infoKey: mapper resourcePath: ./src/main/resources packageName: mappers.mysql nameSuffix: Mapper# 要生成的表tables: - # 表名,大小写需要与数据库一致 name: FT_USER # 表的 catalog catalog: "" # 表的 schema schema: PUBLIC - name: FT_CONFIG 文件自定义内容在文件中,以注释的方式,在自定义内容前后行增加 // <custom> 这是 Java 类中标注自定义区域的方式public String toString() { ...}// </custom> <!-- <custom> 这是 XML 中标注自定义区域的方式 --><select id="selectByParams" parameterType="java.util.Map" resultMap="BaseResultMap"> ...</select><!-- </custom> --> 修改模板内容修改模板前建议通过Beetl 官网了解本项目所使用的模板引擎相关知识。 生成的文件实体类:FtUser.javapackage com.fount4j.demo.entity;/** * 用户表<br> * FT_USER<br> * * @author Fount4j generator */public class FtUser { /** * 主键:用户ID<br> * ID BIGINT(19)<br> */ private Long id; ... /** * 登录名<br> * LOGIN_NAME VARCHAR(50)<br> */ private String loginName; /** * get 主键:用户ID<br> * ID BIGINT(19)<br> * * @return 主键:用户ID */ public Long getId() { return id; } ...} Dao 类:FtUserDao.javapackage com.fount4j.demo.dao;import com.fount4j.demo.entity.FtUser;/** * 用户表 Dao<br> * FT_USER<br> * * @author Fount4j generator */public interface FtUserDao { /** * 插入一条记录(忽略空列) * * @param record 用户表 * @return 影响的行数 */ int insertSelective(FtUser record); /** * 根据主键删除一条记录 * * @param key 主键 * @return 影响的行数 */ int deleteByPrimaryKey(Long key); /** * 更新一条记录 * * @param record 用户表 * @return 影响的行数 */ int updateByPrimaryKey(FtUser record); /** * 更新一条记录(不更新 NULL 的字段) * * @param record 用户表 * @return 影响的行数 */ int updateByPrimaryKeySelective(FtUser record); /** * 根据主键查询一条记录 * * @param key 主键 * @return 用户表 */ FtUser selectByPrimaryKey(Long key);} 映射文件:FtUserMapper.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="com.fount4j.demo.dao.FtUserDao"> <resultMap id="BaseResultMap" type="com.fount4j.demo.entity.FtUser"> <id column="ID" jdbcType="BIGINT" property="id"/><!-- 主键:用户ID --> <result column="LOGIN_NAME" jdbcType="VARCHAR" property="loginName"/><!-- 登录名 --> ... </resultMap> <sql id="Base_Column_List"> ID,CREATE_TIME,UPDATE_TIME,LOGIN_NAME,REAL_NAME,EMAIL,MOBILE,PASSWORD,STATUS </sql> <insert id="insertSelective" parameterType="com.fount4j.demo.entity.FtUser"> insert into FT_USER ( ID, <if test="loginName != null and loginName != ''"> LOGIN_NAME, </if> ... ) values ( #{id,jdbcType=BIGINT}, <if test="loginName != null and loginName != ''"> #{loginName,jdbcType=VARCHAR}, </if> ... ) </insert> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> delete from FT_USER where ID = #{id,jdbcType=BIGINT} </delete> <update id="updateByPrimaryKey" parameterType="com.fount4j.demo.entity.FtUser"> update FT_USER set LOGIN_NAME = #{loginName,jdbcType=VARCHAR}, ... where ID = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.fount4j.demo.entity.FtUser"> update FT_USER set <if test="loginName != null and loginName != ''"> LOGIN_NAME = #{loginName,jdbcType=VARCHAR}, </if> ... where ID = #{id,jdbcType=BIGINT} </update> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> select <include refid="Base_Column_List"/> from FT_USER where ID = #{id,jdbcType=BIGINT} </select></mapper> ![]() |
请发表评论