私信发送成功
Watch Star Fork

darkidiot / CodeHelperJava

①可视化数据库连接配置 ②自动生成service及dao层代码:支持Mapper和sqlSession两种配置风格 ③代码结构简单、零依赖、可简单个性化定制
克隆/下载
DarkIdiot 最后提交于 2017-07-21 22:23 modify readme.md for recommend.
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
2017-06-28 17:00
2017-06-27 17:41
Loading...
README.md 1.98 KB

Mybatis 代码生成小工具

  • 可视化数据库连接配置
  • ②自动生成service及dao层代码

ps:支持Mapper和sqlSession两种配置风格

  • ③代码结构简单、零依赖、可简单个性化定制

Usage:

    git clone https://git.oschina.net/darkidiot/CodeHelper.git
    java -jar ./CodeHelper/dist/CodeHelper.jar

How to Customize Your own CodeHelper?

Code Review:

Java:

    private String getMyBatisCode(Table table, String pack, String author) throws Exception {
		String xml = Util.read(getDaoTemplateLocation());
		String daoTemplate = Util.matchs(xml, "<class>([\\w\\W]+?)</class>", 1).get(0);
        ... ... ...
        return daoTemplate.toString();
	}

xml:

<mapper namespace="#class.package#.mapper.#class.name#Mapper">
    <resultMap id="BaseResultMap" type="#class.package#.model.#class.name#">
		#columns.mapping#
	</resultMap>
    ... ... ...
	<sql id="tb">
		#table.name#
	</sql>
    
	<sql id="cols_all">
		#id#, <include refid="cols_exclude_id" />
	</sql>
    ... ... ...
	<select id="load" parameterType="long" resultMap="BaseResultMap">
		SELECT
		<include refid="cols_all" />
		FROM
		<include refid="tb" />
		WHERE #id# = #{id}
	</select>
	... ... ...
	<insert id="create" parameterType="#class.package#.model.#class.name#">
	    INSERT INTO 
	    <include refid="tb" /> (<include refid="cols_all"/>)
	    VALUES(<include refid="vals_all"/>)
	</insert>
	... ... ...
	<update id="update" parameterType="#class.package#.model.#class.name#">
	    UPDATE <include refid="tb" />
	    <set>
	    	#commaIfEntrys#
	    </set>
	    WHERE #id# = #idVal#
	</update>
	... ... ...
	<delete id="delete" parameterType="long">
		DELETE FROM <include refid="tb" />
		WHERE #id# = #{id}
	</delete>	
</mapper>

You can modify above code for generate any code on the basis of your mind.

End

项目点评 ( 13 )

你可以在登录后,对此项目发表评论

4_float_left_people 4_float_left_close