快速修改ssm项目的增删改查

凭感觉总会少做一两个步骤,导致改的慢,以后想不起来可以对照着改

#比如,增加一个字段

1.页面新增<input>

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

2.提交方法获取参数

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.后台接口中,pojo接收对象新增属性

/**
 * 场地名
 */
private String imgUrl;

4.修改mapper中sql

sql片段新增数据库字段
<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>

插入语句新增value获取

   <!-- 保存当对象 -->
<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.修改mapper查询映射

<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.修改更新语句

<!-- 修改-->
<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.编辑回显

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

8.编辑提交,同新增一样

增加标签<input>

提交方法获取参数

提交方法设置参数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值