springMVC--SSM整合
来源:互联网 发布:鞋子折痕淘宝不让退 编辑:程序博客网 时间:2024/06/11 13:54
SSM整合
需求
实现商品查询列表,从mysql数据库查询商品信息。
一、导入jar包
导入spring(包含springmvc),mybatis,mybatis-spring整合。数据库驱动,jstl,c3p0管理数据源,log4j.
二、配置文件
web.xml:
加载springMVC配置文件
加载spirng配置文件
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>springmvc19_day01_01</display-name> <filter> <filter-name>oscache</filter-name> <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class> <init-param> <param-name>time</param-name> <param-value>3600</param-value> </init-param> <init-param> <param-name>scope</param-name> <param-value>application</param-value> </init-param> </filter> <filter-mapping> <filter-name>oscache</filter-name> <url-pattern>/items/*</url-pattern> </filter-mapping> <filter> <filter-name>characterEncoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 加载spring配置文件 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 默认加载方式 默认加载必须规范: * 文件命名:servlet-name-servlet.xml====springmvc-servlet.xml * 路径规范:必须在WEB-INF目录下面 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list></web-app>
springmvc.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"><context:component-scan base-package="cn.itcast"></context:component-scan><!-- annotation-driven:默认创建了多个对象:RequestMappingHandlerMapping,RequestMappingHandlerAdapter也就提供对json格式支持 --><mvc:annotation-driven/><!-- 配置sprigmvc视图解析器:解析逻辑试图 后台返回逻辑试图:index 视图解析器解析出真正物理视图:前缀+逻辑试图+后缀====/WEB-INF/jsps/index.jsp --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsps/"></property><property name="suffix" value=".jsp"></property></bean><!-- 文件上传解析器 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="10240000"></property></bean><!--拦截器 --><mvc:interceptors><!--多个拦截器,顺序执行 --><mvc:interceptor><mvc:mapping path="/**"/><bean class="cn.itcast.interceptor.Interceptor1"></bean></mvc:interceptor><mvc:interceptor><mvc:mapping path="/**"/><bean class="cn.itcast.interceptor.Interceptor2"></bean></mvc:interceptor></mvc:interceptors></beans>
beans.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"><context:component-scan base-package="cn.itcast"></context:component-scan><!-- 第一步:配置数据源 --><context:property-placeholder location="classpath:jdbc.properties" /><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="jdbcUrl" value="${jdbc.url}"></property><property name="driverClass" value="${jdbc.driver}"></property><property name="user" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!-- 第二步:创建sqlSessionFactory。生产sqlSession --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:sqlMapConfig.xml"></property></bean><!-- 配置mybatis接口代理开发* 接口类名和映射文件必须同名* 接口类和映射文件必须在同一个目录 下* 映射文件namespace名字必须是接口的全类路径名* 接口的方法名必须和映射Statement的id一致 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.itcast.dao"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean><!-- 第三步:事务 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="save*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="delete*" propagation="REQUIRED" /><tx:method name="insert*" propagation="REQUIRED" /><tx:method name="*" propagation="REQUIRED" /></tx:attributes></tx:advice><!-- 配置拦截service --><aop:config><aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.itcast.service.*.*(..))"/></aop:config></beans>
sqlMapConfig.xml:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration></configuration>
jdbc.properties:
jdbc.url = jdbc\:mysql\:///mybatis01jdbc.driver = com.mysql.jdbc.Driverjdbc.username= rootjdbc.password= admin
log4j.properties:
### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### direct messages to file mylog.log ###log4j.appender.file=org.apache.log4j.FileAppenderlog4j.appender.file.File=c:/mylog.loglog4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### set log levels - for more verbose logging change 'info' to 'debug' ###log4j.rootLogger=info, stdout
三、Dao
ItemsMapper.java:
package cn.itcast.dao;import cn.itcast.domain.Items;import cn.itcast.domain.ItemsExample;import java.util.List;import org.apache.ibatis.annotations.Param;public interface ItemsMapper { int countByExample(ItemsExample example); int deleteByExample(ItemsExample example); int deleteByPrimaryKey(Integer id); int insert(Items record); int insertSelective(Items record); List<Items> selectByExampleWithBLOBs(ItemsExample example); List<Items> selectByExample(ItemsExample example); Items selectByPrimaryKey(Integer id); int updateByExampleSelective(@Param("record") Items record, @Param("example") ItemsExample example); int updateByExampleWithBLOBs(@Param("record") Items record, @Param("example") ItemsExample example); int updateByExample(@Param("record") Items record, @Param("example") ItemsExample example); int updateByPrimaryKeySelective(Items record); int updateByPrimaryKeyWithBLOBs(Items record); int updateByPrimaryKey(Items record);List<Items> findAll();}
ItemsMapper.xml:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><mapper namespace="cn.itcast.dao.ItemsMapper" > <resultMap id="BaseResultMap" type="cn.itcast.domain.Items" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="name" property="name" jdbcType="VARCHAR" /> <result column="price" property="price" jdbcType="REAL" /> <result column="pic" property="pic" jdbcType="VARCHAR" /> <result column="createtime" property="createtime" jdbcType="TIMESTAMP" /> </resultMap> <resultMap id="ResultMapWithBLOBs" type="cn.itcast.domain.Items" extends="BaseResultMap" > <result column="detail" property="detail" jdbcType="LONGVARCHAR" /> </resultMap> <sql id="Example_Where_Clause" > <where > <foreach collection="oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Update_By_Example_Where_Clause" > <where > <foreach collection="example.oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Base_Column_List" > id, name, price, pic, createtime </sql> <sql id="Blob_Column_List" > detail </sql> <select id="selectByExampleWithBLOBs" resultMap="ResultMapWithBLOBs" parameterType="cn.itcast.domain.ItemsExample" > select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> , <include refid="Blob_Column_List" /> from items <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> </select> <select id="selectByExample" resultMap="BaseResultMap" parameterType="cn.itcast.domain.ItemsExample" > select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from items <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> </select> <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> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from items where id = #{id,jdbcType=INTEGER} </delete> <delete id="deleteByExample" parameterType="cn.itcast.domain.ItemsExample" > delete from items <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> </delete> <insert id="insert" parameterType="cn.itcast.domain.Items" > insert into items (id, name, price, pic, createtime, detail ) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=REAL}, #{pic,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{detail,jdbcType=LONGVARCHAR} ) </insert> <insert id="insertSelective" parameterType="cn.itcast.domain.Items" > insert into items <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="name != null" > name, </if> <if test="price != null" > price, </if> <if test="pic != null" > pic, </if> <if test="createtime != null" > createtime, </if> <if test="detail != null" > detail, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=INTEGER}, </if> <if test="name != null" > #{name,jdbcType=VARCHAR}, </if> <if test="price != null" > #{price,jdbcType=REAL}, </if> <if test="pic != null" > #{pic,jdbcType=VARCHAR}, </if> <if test="createtime != null" > #{createtime,jdbcType=TIMESTAMP}, </if> <if test="detail != null" > #{detail,jdbcType=LONGVARCHAR}, </if> </trim> </insert> <select id="countByExample" parameterType="cn.itcast.domain.ItemsExample" resultType="java.lang.Integer" > select count(*) from items <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> </select> <update id="updateByExampleSelective" parameterType="map" > update items <set > <if test="record.id != null" > id = #{record.id,jdbcType=INTEGER}, </if> <if test="record.name != null" > name = #{record.name,jdbcType=VARCHAR}, </if> <if test="record.price != null" > price = #{record.price,jdbcType=REAL}, </if> <if test="record.pic != null" > pic = #{record.pic,jdbcType=VARCHAR}, </if> <if test="record.createtime != null" > createtime = #{record.createtime,jdbcType=TIMESTAMP}, </if> <if test="record.detail != null" > detail = #{record.detail,jdbcType=LONGVARCHAR}, </if> </set> <if test="_parameter != null" > <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByExampleWithBLOBs" parameterType="map" > update items set id = #{record.id,jdbcType=INTEGER}, name = #{record.name,jdbcType=VARCHAR}, price = #{record.price,jdbcType=REAL}, pic = #{record.pic,jdbcType=VARCHAR}, createtime = #{record.createtime,jdbcType=TIMESTAMP}, detail = #{record.detail,jdbcType=LONGVARCHAR} <if test="_parameter != null" > <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByExample" parameterType="map" > update items set id = #{record.id,jdbcType=INTEGER}, name = #{record.name,jdbcType=VARCHAR}, price = #{record.price,jdbcType=REAL}, pic = #{record.pic,jdbcType=VARCHAR}, createtime = #{record.createtime,jdbcType=TIMESTAMP} <if test="_parameter != null" > <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByPrimaryKeySelective" parameterType="cn.itcast.domain.Items" > update items <set > <if test="name != null" > name = #{name,jdbcType=VARCHAR}, </if> <if test="price != null" > price = #{price,jdbcType=REAL}, </if> <if test="pic != null" > pic = #{pic,jdbcType=VARCHAR}, </if> <if test="createtime != null" > createtime = #{createtime,jdbcType=TIMESTAMP}, </if> <if test="detail != null" > detail = #{detail,jdbcType=LONGVARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKeyWithBLOBs" parameterType="cn.itcast.domain.Items" > update items set name = #{name,jdbcType=VARCHAR}, price = #{price,jdbcType=REAL}, pic = #{pic,jdbcType=VARCHAR}, createtime = #{createtime,jdbcType=TIMESTAMP}, detail = #{detail,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="cn.itcast.domain.Items" > update items set name = #{name,jdbcType=VARCHAR}, price = #{price,jdbcType=REAL}, detail = #{detail,jdbcType=VARCHAR}, pic = #{pic,jdbcType=VARCHAR}, createtime = #{createtime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} </update> <select id="findAll" resultMap="BaseResultMap"> select * from items </select> </mapper>
四、Service
ItemsService:
package cn.itcast.service;import java.util.List;import cn.itcast.domain.Items;public interface ItemsService {List<Items> findAll();Items findByID(Integer id);void saveOrUpdate(Items items);void deleteByID(Integer id);}
ItemsServiceImpl:
package cn.itcast.service.impl;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Service;import cn.itcast.dao.ItemsMapper;import cn.itcast.domain.Items;import cn.itcast.service.ItemsService;@Servicepublic class ItemsServiceImpl implements ItemsService {@Resource //使用代理注入接口对象private ItemsMapper itemsMapper;public List<Items> findAll() {List<Items> list = itemsMapper.findAll();return list;}public Items findByID(Integer id) {Items items = itemsMapper.selectByPrimaryKey(id);return items;}public void saveOrUpdate(Items items) {itemsMapper.updateByPrimaryKey(items);}public void deleteByID(Integer id) {itemsMapper.deleteByPrimaryKey(id);}}
五、Controller
ItemsController:
package cn.itcast.controller;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import cn.itcast.domain.Items;import cn.itcast.service.ItemsService;@Controller@RequestMapping("/items")public class ItemsController {@Resource //注入service层对象private ItemsService itemsService;//查询所有商品@RequestMapping("list")public String list(Model model){List<Items> list = itemsService.findAll();model.addAttribute("itemsList", list); //数据回显return "itemsList";}//跳转到修改页面@RequestMapping("edit")public String edit(Integer id , Model model){//根据Id查询商品Items items = itemsService.findByID(id);//页面回显model.addAttribute("item", items);return "editItem";}@RequestMapping("saveOrUpdate")public String saveOrUpdate(Items items){itemsService.saveOrUpdate(items);return "redirect:list.do";}//根据Id进行删除@RequestMapping("deleteByID")public String deleteByID(Integer id){itemsService.deleteByID(id);return "redirect: list.do";}//批量删除@RequestMapping("deleteByIds")public String deleteByIds(Integer[] id){for(Integer ids : id){itemsService.deleteByID(ids);}return "redirect: list.do";}}
六、页面
editItem.jsp:
<%@ 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"%><c:set var="picPath" value="http://127.0.0.1:8003/ssmImage19"></c:set><!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><script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.js"></script><script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.form.js"></script><script type="text/javascript">function submitImgSize1Upload(){var option={type:'POST',url:'${pageContext.request.contextPath }/upload/uploadPic.do',dataType:'text',data:{fileName : 'imgSize1File'},success:function(data){//把json格式的字符串转换成json对象var jsonObj = $.parseJSON(data);//返回服务器图片路径,把图片路径设置给img标签$("#imgSize1ImgSrc").attr("src",jsonObj.fullPath);//数据库保存相对路径$("#imgSize1").val(jsonObj.relativePath);}};$("#itemForm").ajaxSubmit(option);}</script></head><body> <form id="itemForm" action="${pageContext.request.contextPath }/items/saveOrUpdate.do" method="post"><input type="hidden" name="id" value="${item.id }"/>修改商品信息:<table width="100%" border=1><tr><td>商品名称</td><td><input type="text" name="name" value="${item.name }"/></td></tr><tr><td>商品价格</td><td><input type="text" name="price" value="${item.price }"/></td></tr><tr><td>商品生产日期</td><td><input type="text" name="createtime" value="<fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/></td></tr><tr><td>商品图片</td><td><p><label></label><img id='imgSize1ImgSrc' src='${picPath }${item.pic }' height="100" width="100" /><input type='file' id='imgSize1File' name='imgSize1File' class="file" onchange='submitImgSize1Upload()' /><span class="pos" id="imgSize1FileSpan">请上传图片的大小不超过3MB</span> <input type='hidden' id='imgSize1' name='pic' value='' reg="^.+$" tip="亲!您忘记上传图片了。" /></p> </td></tr><tr><td>商品简介</td><td><textarea rows="3" cols="30" name="detail">${item.detail }</textarea></td></tr><tr><td colspan="2" align="center"><input type="submit" value="提交"/></td></tr></table></form></body></html>
ItemsList.jsp:
<%@ 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"%><c:set var="picPath" value="http://127.0.0.1:8003/ssmImage19"></c:set><!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> <form action="${pageContext.request.contextPath }/items/deleteByIds.do" method="post">查询条件:<table width="100%" border=1><tr><td><input type="submit" value="查询"/></td><td><input type="submit" value="批量删除"/></td></tr></table>商品列表:<table width="100%" border=1><tr><td>ID</td><td>商品名称</td><td>商品图片</td><td>商品价格</td><td>生产日期</td><td>商品描述</td><td>操作</td></tr><c:forEach items="${itemsList }" var="item"><tr><td><input type="checkbox" name="id" value="${item.id }"></td><td>${item.name }</td><td><img id='imgSize1ImgSrc' src='${picPath }${item.pic }' height="100" width="100" /></td><td>${item.price }</td><td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td><td>${item.detail }</td><td><a href="${pageContext.request.contextPath }/items/edit.do?id=${item.id}">修改</a><a href="${pageContext.request.contextPath }/items/deleteByID.do?id=${item.id}">删除</a></td></tr></c:forEach></table></form></body></html>
七、javabean
domain:
Items.java;
package cn.itcast.domain;import java.util.Date;public class Items { private Integer id; private String name; private Float price; private String pic; private Date createtime; private String detail;
0 0
- springMVC--SSM整合
- ssm-ssm整合(springmvc+mybatis)
- SSM(SpringMVC+Spring+Mybatis)整合
- SSM之WEB整合SpringMVC
- SpringMVC与ssm的整合
- springmvc+mybatis+spring 整合SSM
- 【SSM】Spring+SpringMVC+Mybatis整合
- SpringMvc使用以及ssm整合
- ssm整合经验(SpringMVC+Mybatis)
- SSM整合(Spring+SpringMVC+Mybatis)
- SSM框架整合( Spring 、 SpringMVC 和 Mybatis )
- SSM(Spring+SpringMVC+MyBatis)整合
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- SpringMVC+Mybatis框架整合源码 SSM
- SSM(springmvc+spring+mybatis)整合过程
- ssm框架学习---springmvc和mybatis整合
- spring、springmvc、mybatis整合(SSM)
- SSM(Spring,SpringMVC,MyBatis)整合开发流程
- 导入Servlet源码jar包教程
- leecode 解题总结:75. Sort Colors
- Solr拼写检查示例
- Vue.js 系列教程 2:组件,Props,Slots
- C语言编程-指针遍历二维数组
- springMVC--SSM整合
- Solr Join(加入)示例
- python opencv 学习之视频输入之一
- linux 动态库文件stripped属性理解
- 集合上的函数式编程 示例
- 谷哥的小弟学后台(13)——Cookie
- WPF窗口控件动态模糊效果
- 第四十三讲项目3.3——用柱状图输出考试的平均成绩
- LeetCode-16. 3Sum Closest