springmvc_mybatis1208的基本注释(edit)

本文解析了一个用于修改商品信息的JSP页面代码,包括表单字段、错误消息展示及图片预览等功能。同时展示了控制器方法如何接收请求参数并调用业务层方法获取商品详情。

1

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改商品信息</title>

</head>
<body> 
<!-- 显示错误信息 -->
<c:if test="${allErrors!=null }">
	<c:forEach items="${allErrors }" var="error">
	${ error.defaultMessage}<br/>
</c:forEach>
</c:if>

<form id="itemForm" action="${pageContext.request.contextPath }/items/editItemsSubmit.action" method="post" enctype="multipart/form-data">
	<input type="hidden" name="id" value="${items.id }"/>
	修改商品信息:
	<table width="100%" border=1>
	<tr>
		<td>商品名称</td>
		<td><input type="text" name="name" value="${items.name }"/></td>
	</tr>
	<tr>
		<td>商品价格</td>
		<td><input type="text" name="price" value="${items.price }"/></td>
	</tr>
	<tr>
		<td>商品生产日期</td>
		<td><input type="text" name="createtime" value="<fmt:formatDate value="${items.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/></td>
	</tr>
	<tr>
		<td>商品图片</td>
		<td>
			<c:if test="${items.pic !=null}">
				<img src="/pic/${items.pic}" width=100 height=100/>
				<br/>
			</c:if>
			<input type="file"  name="items_pic"/> 
		</td>
	</tr>
	<tr>
		<td>商品简介</td>
		<td>
		<textarea rows="3" cols="30" name="detail">${items.detail }</textarea>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" value="提交"/>
	</td>
	</tr>
</table>

</form>
</body>

</html>


2

	@请求映射(值=“/editItems”,方法 = {请求方法.POST,
			请求方法.GET})
	方法头	返回类型	方法名(参数类型	参数变量1,
			@请求参数(值 = “id”,必要  = 真)参数类型	参数变量2)
			抛	异常 {
	
		对象类型	定义变量	=	业务层接口.实例方法名(变量2);
		
		变量1.加属性(字符串,对象);
		
		返回	“视图路径”;
	}
	
	@RequestMapping(value="/deitItems", method = { RequestMethod.POST,
			RequestMethod.GET })
	public String editItems(Model model,
			@RequestParam(value="id", required = true) Integer items_id)
			throws Exception {
		
		ItemsCustom itemsCustom = itemsService.findItemsById(items_id);
		
		model.addAttribute("items", itemsCustom);
		
		return "items/editItems";
	}


3

public ItemsCustom findItemsById(Integer id) throws Exception;

	@Override
	public ItemsCustom findItemsById(Integer id) throws Exception {
		
		Items items = itemsMapper.selectByPrimaryKey(id);
		if(items==null){
			throw new CustomException("修改的商品信息不存在!");
		}
		//中间对商品信息进行业务处理
		//....
		//返回ItemsCustom
		ItemsCustom itemsCustom = null;
		//将items的属性值拷贝到itemsCustom
		if(items!=null){
			itemsCustom = new ItemsCustom();
			BeanUtils.copyProperties(items, itemsCustom);
		}
		
		
		return itemsCustom;
		
	}


4

Items selectByPrimaryKey(Integer id);

<sql id="Base_Column_List" >
    id, name, price, pic, createtime
  </sql>
  <sql id="Blob_Column_List" >
    detail
  </sql>
  <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from items
    where id = #{id,jdbcType=INTEGER}
  </select>


5

6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值