十三、mcg-helper业务系统单表业务模块自动化生成xml映射文件

版权声明:mcg-helper交流群:619815829,开源地址:https://github.com/mcg-helper/mcg-helper,欢迎转载: https://blog.csdn.net/LoginandPwd/article/details/77452902

           本节教程主要讲解如果生成xml,示例中以生成mybatis的xml为例,当然如果你想生成hibernate的xml、其他语言框架xml映射、自定义xml文件都可以,可以借鉴一下本节教程,我们来看看流程图中运用到哪些控件:

            红色方框标记之前教程已讲解过的控件,绿色方框标记本节要讲解的控件

            用到了一个data控件、两个JS脚本控件、一个文本控件,在上节《生成model类》教程中讲解了data、JS脚本、文本三个控件的使用,各控件间都只有一个父级,在本示例中涉及多父级的场景,可以看见文本控件有两个父级控件,均是JS脚本控件,意图是想复用生成model类的JS脚本控件的运行值,省去重复的工作。本节教程中用到的四个控件,在上节教程中已经讲解两个控件,下面我们主要讲解新的JS脚本控件和文本控件,如下图红色方框:

                   1、JS脚本控件,主要来看看源代码,如下图所示


                  其运行值为:

{
	"daoScript":{
		"modelPackageName":"com.mcghelper.model",
		"daoFileName":"McgHelperUserDao.java",
		"daoPackageName":"com.mcghelper.dao",
		"modelClassName":"McgHelperUser",
		"daoClassName":"McgHelperUserDao",
		"primary":{
			"type":"Integer",
			"classField":"userId"
		}
	}
}

                 2、文本控件,主要看一下源代码的实现,mybatis的xml映射相对内容较多,这里就截两个图参考




                mybatis的xml官方生成映射文件,内容虽多,但相当规范,而且里面的规律太多太多。当然,也有每个公司都不一定是用的官方工具来生成,而且针对公司业务所自定义的,也是很是规律,我们只需要通填充类名,类包路径、类字段、表字段、表字段类型、程序字段类型,这里就不多说了,都是freemaker的最基本用法,把相应地方的值填充相应的值即可。该组件运行值如下:

<?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.mcghelper.dao.McgHelperUserDao">
  <resultMap id="BaseResultMap" type="com.mcghelper.model.McgHelperUser">
			<id column="user_id" jdbcType="INT" property="userId" />
			<result column="user_name" jdbcType="VARCHAR" property="userName" />
			<result column="user_pwd" jdbcType="VARCHAR" property="userPwd" />
  </resultMap>

  <sql id="Base_Column_List">
		user_id,
		user_name,
		user_pwd
  </sql>

  <select id="selectByExample" parameterType="com.mcghelper.model.McgHelperUser" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    'true' as QUERYID,
    <include refid="Base_Column_List" />
    from mcg_helper_user
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="limitStart > -1">
      limit ${limitStart} , ${limitEnd}
    </if>
  </select>  
  
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from mcg_helper_user
    where id = #{id,jdbcType=INTEGER}
  </delete>  
  
  <insert id="insertSelective" parameterType="com.mcghelper.model.McgHelperUser">
    insert into mcg_helper_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
		  <if test="userId != null">
			user_id,
		  </if>		
		  <if test="userName != null">
			user_name,
		  </if>		
		  <if test="userPwd != null">
			user_pwd,
		  </if>		
    </trim>  
    <trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="userId != null">
				#{userId,jdbcType=INT},
			</if>
			<if test="userName != null">
				#{userName,jdbcType=VARCHAR},
			</if>
			<if test="userPwd != null">
				#{userPwd,jdbcType=VARCHAR},
			</if>
    </trim>
  </insert>
  
  <update id="updateByPrimaryKeySelective" parameterType="com.mcghelper.model.McgHelperUser">
    update mcg_helper_user 
    <set>
			<if test="userId != null">
				user_id = #{userId,jdbcType=INT},
			</if>
			<if test="userName != null">
				user_name = #{userName,jdbcType=VARCHAR},
			</if>
			<if test="userPwd != null">
				user_pwd = #{userPwd,jdbcType=VARCHAR},
			</if>
   
    </set>
    where id = #{userId,jdbcType=Integer}
  </update>  

            到此,xml映射文件就生成结束了,通过二节教程,我想大家应该熟悉mcg-helper的使用了吧。

        mcg-helper的使用指南:http://blog.csdn.net/loginandpwd/article/details/76944900
        mcg-helper研发小助手发布v1.0.0-beta版本:http://blog.csdn.net/loginandpwd/article/details/77447363
        mcg-helper研发小助手软件介绍:http://blog.csdn.net/loginandpwd/article/details/77751566
        生成model类:http://blog.csdn.net/loginandpwd/article/details/77448277
        生成xml映射文件:http://blog.csdn.net/loginandpwd/article/details/77452902
        生成dao接口:http://blog.csdn.net/loginandpwd/article/details/77452927
        生成service接口:http://blog.csdn.net/loginandpwd/article/details/77452946
        生成serviceImpl实现类:http://blog.csdn.net/loginandpwd/article/details/77452979
        生成controller控制类:http://blog.csdn.net/loginandpwd/article/details/77452993
        生成html页面:http://blog.csdn.net/loginandpwd/article/details/77453013
        生成js文件:http://blog.csdn.net/loginandpwd/article/details/77453024

猜你喜欢

转载自blog.csdn.net/LoginandPwd/article/details/77452902
今日推荐