Quick Modification of Additions, Deletions and Revisions of ssm Projects

Keywords: SQL JSON less Fragment

Feeling will always do one or two less steps, resulting in slow change, later can not remember to change the contrast.

# For example, add a field

1. Add < input > to the page

<input type="file" id="f" name="imageFile" οnchange="uploadImage(this,'img','form-article-add');" style="display:none"/>

2. Submitting method to obtain parameters

var imgSrc = $("#img").attr("src");
var ss = imgSrc.split("/");
var imgUrl = ss[ss.length - 2] + "/" + ss[ss.length - 1];
$.ajax({
    url: serverIP + "ad-space",
    type: 'post',
    contentType: 'application/json',
    dataType: 'json',
    data: JSON.stringify({
        "useUnit": useUnit, "spaceType": spaceType, "createdTime": createdTime
        , "useTime": useTime, "groundStatus": groundStatus, "groundAddr": groundAddr
        , "groundUse": groundUse, "orgId": pId, "spaceName": spaceName
        , "imgUrl": imgUrl
    }),
    beforeSend: function () {
    },
    success: function (data) {
        alert(data.msg);
    }
});

3. In the background interface, new attributes are added to the pojo receiving object

/**
 * Place name
 */
private String imgUrl;

4. Modify sql in mapper

sql Fragment Added Database Fields
<sql id="mainColumns">
 `id`,`use_unit`,`space_type`,`created_time`,`use_time`
 ,`maintenance_time`,`ground_status`,`ground_addr`,`ground_user`
 ,`org_id`,`space_name`,`img_url`
 </sql>

Insert statement add value acquisition

   <!-- Save as an object -->
<insert id="save" parameterType="cn.admin.entity.Space" useGeneratedKeys="true" keyProperty="id">
   INSERT INTO
   <include refid="tableName"/>
   (<include refid="mainColumns"/>)      
       VALUES
    (#{id},#{useUnit},#{spaceType},#{createdTime},#{useTime},#{maintenanceTime},#{groundStatus},#{groundAddr},#{groundUse},#{orgId},#{spaceName}
    ,#{imgUrl})
</insert>

5. Modify mapper query mapping

<resultMap type="cn.admin.entity.Space" id="spaceMapper">
    <result column="id" property="id" />        
    <result column="use_unit" property="useUnit" />
    <result column="space_type" property="spaceType" />
    <result column="created_time" property="createdTime"/>
    <result column="use_time" property="useTime"/> 
    <result column="maintenance_time" property="maintenanceTime"/> 
    <result column="ground_status" property="groundStatus"/> 
    <result column="ground_addr" property="groundAddr"/> 
    <result column="ground_user" property="groundUse"/>                   
    <result column="space_name" property="spaceName"/>
    <result column="img_url" property="imgUrl"/>
</resultMap>

6. Modify update statements

<!-- modify-->
<update id="update" parameterType="cn.admin.entity.Space">
    UPDATE
    <include refid="tableName"/>         
    <set>      
        <if test='null != useUnit and ""!= useUnit'>
            `use_unit` = #{useUnit},
        </if>
        <if test='null != groundAddr and ""!= groundAddr'>
            `ground_addr` = #{groundAddr},
        </if>
        <if test='null != spaceType and ""!= spaceType'>
            `space_type` = #{spaceType},
        </if>
        <if test='null != createdTime and ""!= createdTime'>
            `created_time` = #{createdTime},
        </if>            
        <if test='null != useTime and ""!= useTime'>
            `use_time` = #{useTime},
        </if>
        <if test='null != maintenanceTime and ""!= maintenanceTime'>
            `maintenance_time` = #{maintenanceTime},
        </if>            
        <if test='null != groundStatus and ""!= groundStatus'>
            `ground_status` = #{groundStatus},
        </if>
        <if test='null != groundUse and ""!= groundUse'>
            `ground_user` = #{groundUse}
        </if>
        <if test='null != imgUrl and ""!= imgUrl'>
            `img_url` = #{imgUrl}
        </if>
    </set>
    <where>
        `id` = #{id}
    </where>      
</update>

7. Editorial echo

$("#img").attr("src",serverIP + data.imgUrl);

8. Editor submission, as new

Add label < input >

Submit method to obtain parameters

Submit method setting parameters

Posted by mentalist on Mon, 30 Sep 2019 17:06:26 -0700