商品修改功能开发

  9.1 需求

操作流程:

1、进入商品查询列表页面

2、点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询)

  要修改的商品从数据库查询,根据商品id(主键)查询商品信息

3、在商品修改页面,修改商品信息,修改后,点击提交

  9.2 开发mapper

mapper:

  根据id查询商品信息

  根据id更新Items表的数据

不用开发了,使用逆向工程生成的代码。

ItemsMapper.java

  1. package cn.itcast.ssm.mapper;
  2.  
  3. import cn.itcast.ssm.po.Items;
  4. import cn.itcast.ssm.po.ItemsExample;
  5. import java.util.List;
  6. import org.apache.ibatis.annotations.Param;
  7.  
  8. public interface ItemsMapper {
  9. int countByExample(ItemsExample example);
  10.  
  11. int deleteByExample(ItemsExample example);
  12.  
  13. int deleteByPrimaryKey(Integer id);
  14.  
  15. int insert(Items record);
  16.  
  17. int insertSelective(Items record);
  18.  
  19. List<Items> selectByExampleWithBLOBs(ItemsExample example);
  20.  
  21. List<Items> selectByExample(ItemsExample example);
  22.  
  23. Items selectByPrimaryKey(Integer id);
  24.  
  25. int updateByExampleSelective(@Param("record") Items record, @Param("example") ItemsExample example);
  26.  
  27. int updateByExampleWithBLOBs(@Param("record") Items record, @Param("example") ItemsExample example);
  28.  
  29. int updateByExample(@Param("record") Items record, @Param("example") ItemsExample example);
  30.  
  31. int updateByPrimaryKeySelective(Items record);
  32.  
  33. int updateByPrimaryKeyWithBLOBs(Items record);
  34.  
  35. int updateByPrimaryKey(Items record);
  36. }

ItemsMapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="cn.itcast.ssm.mapper.ItemsMapper" >
  4. <resultMap id="BaseResultMap" type="cn.itcast.ssm.po.Items" >
  5. <id column="id" property="id" jdbcType="INTEGER" />
  6. <result column="name" property="name" jdbcType="VARCHAR" />
  7. <result column="price" property="price" jdbcType="REAL" />
  8. <result column="pic" property="pic" jdbcType="VARCHAR" />
  9. <result column="createtime" property="createtime" jdbcType="TIMESTAMP" />
  10. </resultMap>
  11. <resultMap id="ResultMapWithBLOBs" type="cn.itcast.ssm.po.Items" extends="BaseResultMap" >
  12. <result column="detail" property="detail" jdbcType="LONGVARCHAR" />
  13. </resultMap>
  14. <sql id="Example_Where_Clause" >
  15. <where >
  16. <foreach collection="oredCriteria" item="criteria" separator="or" >
  17. <if test="criteria.valid" >
  18. <trim prefix="(" suffix=")" prefixOverrides="and" >
  19. <foreach collection="criteria.criteria" item="criterion" >
  20. <choose >
  21. <when test="criterion.noValue" >
  22. and ${criterion.condition}
  23. </when>
  24. <when test="criterion.singleValue" >
  25. and ${criterion.condition} #{criterion.value}
  26. </when>
  27. <when test="criterion.betweenValue" >
  28. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  29. </when>
  30. <when test="criterion.listValue" >
  31. and ${criterion.condition}
  32. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  33. #{listItem}
  34. </foreach>
  35. </when>
  36. </choose>
  37. </foreach>
  38. </trim>
  39. </if>
  40. </foreach>
  41. </where>
  42. </sql>
  43. <sql id="Update_By_Example_Where_Clause" >
  44. <where >
  45. <foreach collection="example.oredCriteria" item="criteria" separator="or" >
  46. <if test="criteria.valid" >
  47. <trim prefix="(" suffix=")" prefixOverrides="and" >
  48. <foreach collection="criteria.criteria" item="criterion" >
  49. <choose >
  50. <when test="criterion.noValue" >
  51. and ${criterion.condition}
  52. </when>
  53. <when test="criterion.singleValue" >
  54. and ${criterion.condition} #{criterion.value}
  55. </when>
  56. <when test="criterion.betweenValue" >
  57. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  58. </when>
  59. <when test="criterion.listValue" >
  60. and ${criterion.condition}
  61. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  62. #{listItem}
  63. </foreach>
  64. </when>
  65. </choose>
  66. </foreach>
  67. </trim>
  68. </if>
  69. </foreach>
  70. </where>
  71. </sql>
  72. <sql id="Base_Column_List" >
  73. id, name, price, pic, createtime
  74. </sql>
  75. <sql id="Blob_Column_List" >
  76. detail
  77. </sql>
  78. <select id="selectByExampleWithBLOBs" resultMap="ResultMapWithBLOBs" parameterType="cn.itcast.ssm.po.ItemsExample" >
  79. select
  80. <if test="distinct" >
  81. distinct
  82. </if>
  83. <include refid="Base_Column_List" />
  84. ,
  85. <include refid="Blob_Column_List" />
  86. from items
  87. <if test="_parameter != null" >
  88. <include refid="Example_Where_Clause" />
  89. </if>
  90. <if test="orderByClause != null" >
  91. order by ${orderByClause}
  92. </if>
  93. </select>
  94. <select id="selectByExample" resultMap="BaseResultMap" parameterType="cn.itcast.ssm.po.ItemsExample" >
  95. select
  96. <if test="distinct" >
  97. distinct
  98. </if>
  99. <include refid="Base_Column_List" />
  100. from items
  101. <if test="_parameter != null" >
  102. <include refid="Example_Where_Clause" />
  103. </if>
  104. <if test="orderByClause != null" >
  105. order by ${orderByClause}
  106. </if>
  107. </select>
  108. <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
  109. select
  110. <include refid="Base_Column_List" />
  111. ,
  112. <include refid="Blob_Column_List" />
  113. from items
  114. where id = #{id,jdbcType=INTEGER}
  115. </select>
  116. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  117. delete from items
  118. where id = #{id,jdbcType=INTEGER}
  119. </delete>
  120. <delete id="deleteByExample" parameterType="cn.itcast.ssm.po.ItemsExample" >
  121. delete from items
  122. <if test="_parameter != null" >
  123. <include refid="Example_Where_Clause" />
  124. </if>
  125. </delete>
  126. <insert id="insert" parameterType="cn.itcast.ssm.po.Items" >
  127. insert into items (id, name, price,
  128. pic, createtime, detail
  129. )
  130. values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=REAL},
  131. #{pic,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{detail,jdbcType=LONGVARCHAR}
  132. )
  133. </insert>
  134. <insert id="insertSelective" parameterType="cn.itcast.ssm.po.Items" >
  135. insert into items
  136. <trim prefix="(" suffix=")" suffixOverrides="," >
  137. <if test="id != null" >
  138. id,
  139. </if>
  140. <if test="name != null" >
  141. name,
  142. </if>
  143. <if test="price != null" >
  144. price,
  145. </if>
  146. <if test="pic != null" >
  147. pic,
  148. </if>
  149. <if test="createtime != null" >
  150. createtime,
  151. </if>
  152. <if test="detail != null" >
  153. detail,
  154. </if>
  155. </trim>
  156. <trim prefix="values (" suffix=")" suffixOverrides="," >
  157. <if test="id != null" >
  158. #{id,jdbcType=INTEGER},
  159. </if>
  160. <if test="name != null" >
  161. #{name,jdbcType=VARCHAR},
  162. </if>
  163. <if test="price != null" >
  164. #{price,jdbcType=REAL},
  165. </if>
  166. <if test="pic != null" >
  167. #{pic,jdbcType=VARCHAR},
  168. </if>
  169. <if test="createtime != null" >
  170. #{createtime,jdbcType=TIMESTAMP},
  171. </if>
  172. <if test="detail != null" >
  173. #{detail,jdbcType=LONGVARCHAR},
  174. </if>
  175. </trim>
  176. </insert>
  177. <select id="countByExample" parameterType="cn.itcast.ssm.po.ItemsExample" resultType="java.lang.Integer" >
  178. select count(*) from items
  179. <if test="_parameter != null" >
  180. <include refid="Example_Where_Clause" />
  181. </if>
  182. </select>
  183. <update id="updateByExampleSelective" parameterType="map" >
  184. update items
  185. <set >
  186. <if test="record.id != null" >
  187. id = #{record.id,jdbcType=INTEGER},
  188. </if>
  189. <if test="record.name != null" >
  190. name = #{record.name,jdbcType=VARCHAR},
  191. </if>
  192. <if test="record.price != null" >
  193. price = #{record.price,jdbcType=REAL},
  194. </if>
  195. <if test="record.pic != null" >
  196. pic = #{record.pic,jdbcType=VARCHAR},
  197. </if>
  198. <if test="record.createtime != null" >
  199. createtime = #{record.createtime,jdbcType=TIMESTAMP},
  200. </if>
  201. <if test="record.detail != null" >
  202. detail = #{record.detail,jdbcType=LONGVARCHAR},
  203. </if>
  204. </set>
  205. <if test="_parameter != null" >
  206. <include refid="Update_By_Example_Where_Clause" />
  207. </if>
  208. </update>
  209. <update id="updateByExampleWithBLOBs" parameterType="map" >
  210. update items
  211. set id = #{record.id,jdbcType=INTEGER},
  212. name = #{record.name,jdbcType=VARCHAR},
  213. price = #{record.price,jdbcType=REAL},
  214. pic = #{record.pic,jdbcType=VARCHAR},
  215. createtime = #{record.createtime,jdbcType=TIMESTAMP},
  216. detail = #{record.detail,jdbcType=LONGVARCHAR}
  217. <if test="_parameter != null" >
  218. <include refid="Update_By_Example_Where_Clause" />
  219. </if>
  220. </update>
  221. <update id="updateByExample" parameterType="map" >
  222. update items
  223. set id = #{record.id,jdbcType=INTEGER},
  224. name = #{record.name,jdbcType=VARCHAR},
  225. price = #{record.price,jdbcType=REAL},
  226. pic = #{record.pic,jdbcType=VARCHAR},
  227. createtime = #{record.createtime,jdbcType=TIMESTAMP}
  228. <if test="_parameter != null" >
  229. <include refid="Update_By_Example_Where_Clause" />
  230. </if>
  231. </update>
  232. <update id="updateByPrimaryKeySelective" parameterType="cn.itcast.ssm.po.Items" >
  233. update items
  234. <set >
  235. <if test="name != null" >
  236. name = #{name,jdbcType=VARCHAR},
  237. </if>
  238. <if test="price != null" >
  239. price = #{price,jdbcType=REAL},
  240. </if>
  241. <if test="pic != null" >
  242. pic = #{pic,jdbcType=VARCHAR},
  243. </if>
  244. <if test="createtime != null" >
  245. createtime = #{createtime,jdbcType=TIMESTAMP},
  246. </if>
  247. <if test="detail != null" >
  248. detail = #{detail,jdbcType=LONGVARCHAR},
  249. </if>
  250. </set>
  251. where id = #{id,jdbcType=INTEGER}
  252. </update>
  253. <update id="updateByPrimaryKeyWithBLOBs" parameterType="cn.itcast.ssm.po.Items" >
  254. update items
  255. set name = #{name,jdbcType=VARCHAR},
  256. price = #{price,jdbcType=REAL},
  257. pic = #{pic,jdbcType=VARCHAR},
  258. createtime = #{createtime,jdbcType=TIMESTAMP},
  259. detail = #{detail,jdbcType=LONGVARCHAR}
  260. where id = #{id,jdbcType=INTEGER}
  261. </update>
  262. <update id="updateByPrimaryKey" parameterType="cn.itcast.ssm.po.Items" >
  263. update items
  264. set name = #{name,jdbcType=VARCHAR},
  265. price = #{price,jdbcType=REAL},
  266. pic = #{pic,jdbcType=VARCHAR},
  267. createtime = #{createtime,jdbcType=TIMESTAMP}
  268. where id = #{id,jdbcType=INTEGER}
  269. </update>
  270. </mapper>

  9.3 开发service

接口功能:

  根据id查询商品信息

  修改商品信息

ItemsServiceImpl.java

  9.4 开发controller

方法:

  商品信息修改页面显示

  商品信息修改提交

ItemsController.java

添加成功页面

修改修改链接

修改页面editItems.jsp:

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title>修改商品信息</title>
  10.  
  11. </head>
  12. <body>
  13.  
  14. <form id="itemForm"
  15. action="${pageContext.request.contextPath }/items/editItemsSubmit.action"
  16. method="post">
  17. <input type="hidden" name="id" value="${itemsCustom.id }" /> 修改商品信息:
  18. <table width="100%" border=1>
  19. <tr>
  20. <td>商品名称</td>
  21. <td><input type="text" name="name" value="${itemsCustom.name }" /></td>
  22. </tr>
  23. <tr>
  24. <td>商品价格</td>
  25. <td><input type="text" name="price"
  26. value="${itemsCustom.price }" /></td>
  27. </tr>
  28. <tr>
  29. <td>商品生产日期</td>
  30. <td><input type="text" name="createtime"
  31. value="<fmt:formatDate value="${itemsCustom.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>" /></td>
  32. </tr>
  33. <%-- <tr>
  34. <td>商品图片</td>
  35. <td>
  36. <c:if test="${item.pic !=null}">
  37. <img src="/pic/${item.pic}" width=100 height=100/>
  38. <br/>
  39. </c:if>
  40. <input type="file" name="pictureFile"/>
  41. </td>
  42. </tr> --%>
  43. <tr>
  44. <td>商品简介</td>
  45. <td><textarea rows="3" cols="30" name="detail">${itemsCustom.detail }</textarea>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td colspan="2" align="center"><input type="submit" value="提交" />
  50. </td>
  51. </tr>
  52. </table>
  53. </form>
  54. </body>
  55. </html>

测试:访问http://localhost:8080/springmvc_mybatis1217/editItems.action

SpringMVC由浅入深day01_9商品修改功能开发的更多相关文章

  1. 后台商品搜索功能开发SQL

    在做后台的商品搜索功能开发时遇到了一些问题记录下来 版本一 <select id="SelectByNameAndParentId resultMap="Base_resul ...

  2. springMVC学习(4)-商品修改(RequestMapping解释、controller返回值)

    一.需求: 操作流程: 1.进入商品查询列表页面 2.点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询) 3.在商品修改页面,修改商品信息,修改后,点击提交 代码: ItemsMap ...

  3. SpringMVC学习记录四——功能开发及参数绑定

    9       商品修改功能开发 9.1      需求 操作流程: 1.进入商品查询列表页面 2.点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询) 要修改的商品从数据库查询,根据 ...

  4. SpringMVC由浅入深day02_1课程安排_2包装类型pojo参数绑定_3集合类型绑定

    springmvc第二天 高级知识 复习: springmvc框架: DispatcherServlet前端控制器:接收request,进行response HandlerMapping处理器映射器: ...

  5. springmvc学习笔记(10)-springmvc注解开发之商品改动功能

    springmvc学习笔记(10)-springmvc注解开发之商品改动功能 标签: springmvc springmvc学习笔记10-springmvc注解开发之商品改动功能 需求 开发mappe ...

  6. SpringMVC学习记录五——功能开发及参数处理

    15       包装类型pojo参数绑定 15.1      需求 商品查询controller方法中实现商品查询条件传入. 15.2      实现方法 第一种方法:在形参中 添加HttpServ ...

  7. SpringMVC由浅入深day02_5数据回显_6异常处理器

    5 数据回显 5.1 什么数据回显 表单提交失败需要再回到表单页面重新填写,原来提交的数据需要重新在页面上显示. 5.2 pojo数据回显方法 1.springmvc默认对pojo数据进行回显. po ...

  8. [5] 微信公众号开发 - 微信支付功能开发(网页JSAPI调用)

    1.微信支付的流程 如下三张手机截图,我们在微信网页端看到的支付,表面上看到的是 "点击支付按钮 - 弹出支付框 - 支付成功后出现提示页面",实际上的核心处理过程是: 点击支付按 ...

  9. 微信公众号开发 [05] 微信支付功能开发(网页JSAPI调用)

    1.微信支付的流程 如下三张手机截图,我们在微信网页端看到的支付,表面上看到的是 "点击支付按钮 - 弹出支付框 - 支付成功后出现提示页面",实际上的核心处理过程是: 点击支付按 ...

随机推荐

  1. .net类中静态方法的继承

    父类中的静态方法,继承的子类能不能调用?一直在这里有疑惑,即使在下面的测试之后,也只是得到了结论,不明原理. class ClsParent { public static void ShowSth( ...

  2. 实战c++中的string系列--string与char*、const char *的转换(data() or c_str())

    在project中,我们也有非常多时候用到string与char*之间的转换,这里有个一我们之前提到的函数 c_str(),看看这个原型: const char *c_str(); c_str()函数 ...

  3. 汉字转拼音首字母的java实现

    工作中经常会遇到的一些排序问题,比如 按汉字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路: 1. 获得汉字 2. 将汉字转换成首字母,并记录下(必要时保存到数据库) 3. 按首字母进行 ...

  4. jquery 异步处理

    <!DOCTYPE html> <head> <script type="text/javascript" src="jquery-1.12 ...

  5. Spring Cloud 获取注册中心所有服务以及服务下的所有实例

    注册中心现有服务与实例数: 在任意客户端填写如下代码: /** * import org.springframework.cloud.client.ServiceInstance; * import ...

  6. Q_UNUSED() 方法的使用

    Q_UNUSED() 没有实质性的作用,用来避免编译器警告 //比如说 int testFunc(int a, int b, int c, int d) { int e; return a+b+c; ...

  7. modelsim 出现此错误怎么办

    笔者的电脑装成了win8的系统,然后像平常一样打开modelsim,这时跳出如下图的界面: 笔者的modelsim之前是安装过的,所以这个界面已经说明,当前的许可证没有安装好.解决上述问题的办法是重新 ...

  8. Pandas DataFrame 函数应用和映射

    apply Numpy 的ufuncs通用函数(元素级数组方法)也可用于操作pandas对象: 另一个常见的操作是,将函数应用到由各列或行所形成的一维数组上.Dataframe的apply方法即可实现 ...

  9. (笔记)Linux下的静态库和动态库使用详解

    库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行.库分静态库和动态库两种. 一.静态库和动态库的区别 1. 静态函数库 这类库的名字一般是libxxx.a:利用静态函数库编译成的文件比 ...

  10. Java注解Annotation学习笔记

    一.自定义注解 1. 使用关键字 @interface 2. 默认情况下,注解可以修饰 类.方法.接口等. 3. 如下为一个基本的注解例子: //注解中的成员变量非常像定义接口 public @int ...