凭感觉总会少做一两个步骤,导致改的慢,以后想不起来可以对照着改
#比如,增加一个字段
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>
提交方法获取参数
提交方法设置参数