对商品进行增删改查的操作

  1. 先看下我的MVC三层架构
    在这里插入图片描述
    在这里插入图片描述
  2. 首先实现登录功能,登录代码展示
    实体类 Client.java
package com.gxy.entity;

import java.sql.Date;

public class Client{
	private int cliId;
	private String cliName;
	private String cliPwd;
	private String cliRealname;
	private Date cliCreateDate;
	public Client() {
		super();
	}
	public Client(int cliId, String cliName, String cliPwd, String cliRealname, Date cliCreateDate) {
		super();
		this.cliId = cliId;
		this.cliName = cliName;
		this.cliPwd = cliPwd;
		this.cliRealname = cliRealname;
		this.cliCreateDate = cliCreateDate;
	}
	public int getCliId() {
		return cliId;
	}
	public void setCliId(int cliId) {
		this.cliId = cliId;
	}
	public String getCliName() {
		return cliName;
	}
	public void setCliName(String cliName) {
		this.cliName = cliName;
	}
	public String getCliPwd() {
		return cliPwd;
	}
	public void setCliPwd(String cliPwd) {
		this.cliPwd = cliPwd;
	}
	public String getCliRealname() {
		return cliRealname;
	}
	public void setCliRealname(String cliRealname) {
		this.cliRealname = cliRealname;
	}
	public Date getCliCreateDate() {
		return cliCreateDate;
	}
	public void setCliCreateDate(Date cliCreateDate) {
		this.cliCreateDate = cliCreateDate;
	}
	@Override
	public String toString() {
		return "Client [cliId=" + cliId + ", cliName=" + cliName + ", cliPwd=" + cliPwd + ", cliRealname=" + cliRealname
				+ ", cliCreateDate=" + cliCreateDate + "]";
	}
	
}

ClientMapper.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="com.gxy.dao.ClientDao">
	
	    <!-- 通用查询映射结果 -->
	    <resultMap id="BaseResultMap" type="com.gxy.entity.Client">
	        <id column="cli_id" property="cliId" />
	        <result column="cli_name" property="cliName" />
	        <result column="cli_pwd" property="cliPwd" />
	        <result column="cli_realname" property="cliRealname" />
	        <result column="cli_create_date" property="cliCreateDate" />
	    </resultMap>
	    
    	<!-- 查询list -->
    	<select id="selectUser" resultMap="BaseResultMap" >
    		select * from client where cli_name=#{cliName} and cli_pwd=#{cliPwd}
    	</select>
</mapper>

ClientDao.java

package com.gxy.dao;

import java.util.List;


import org.apache.ibatis.annotations.Param;

import com.gxy.entity.Client;

public interface ClientDao {
	//查询用户是否存在
	public List<Client> selectUser(@Param("cliName") String cliName,
			@Param("cliPwd") String cliPwd);
}

ClientService.java

package com.gxy.service;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.gxy.entity.Client;

public interface ClientService {
	//查询用户
	public List<Client> login(@Param("cliName") String cliName,
			@Param("cliPwd") String cliPwd) throws IOException;

}

ClientServiceImpl.java

package com.gxy.service.impl;

import java.io.IOException;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import com.gxy.dao.ClientDao;
import com.gxy.entity.Client;
import com.gxy.service.ClientService;
import com.gxy.util.MyBatisUtil;

public class ClientServiceImpl implements ClientService{

	@Override
	public List<Client> login(String cliName, String cliPwd) throws IOException {
		SqlSession session = MyBatisUtil.getSqlSession();
		ClientDao clientDao = session.getMapper(ClientDao.class);
		List<Client> list = clientDao.selectUser(cliName, cliPwd);
		//关闭流
		MyBatisUtil.close();
		return list;
	}

}

loginAction.java

package com.gxy.servlet;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.gxy.entity.Client;
import com.gxy.service.ClientService;
import com.gxy.service.impl.ClientServiceImpl;

@WebServlet("/client/loginAction")
public class loginAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取session对话
		HttpSession session = req.getSession();
		//获取用户名
		String username = req.getParameter("username");
		//获取密码
		String pwd = req.getParameter("password");
//		System.out.println(username);
//		System.out.println(pwd);
		//多态调用dao方法
		ClientService clientservice = new ClientServiceImpl();
		//登录
		List<Client> list = clientservice.login(username,pwd);
		//判断是否获取到账户信息
		if (list.size() > 0) {
			//登陆成功
			System.out.println("登陆成功");
			//重定向
			//resp.sendRedirect("success.jsp");
			String realname = list.get(0).getCliRealname();
			session.setAttribute("realName", realname);
			//重定向,地址栏变化
			resp.sendRedirect(req.getContextPath()+"/product/productList.action");
		} else {
			//登陆失败
			session.setAttribute("errorMsg", "账号或密码错误");
			//重定向
			resp.sendRedirect(req.getContextPath()+"/login.jsp");
		}
	}

}

  1. 对商品进行增删改查的操作
    实体类:Product.java
package com.gxy.entity;

import java.sql.Date;

public class Product {
	private int proId;//主键
	private String proName;//商品名称
	private String proBrief;//商品简介
	private Double proPrice;//商品价格
	private int proCount;//商品数量
	private int proStatus;//商品状态
	private Date proCreateDate;//时间戳
	public Product() {
		super();
	}
	public Product(int proId, String proName, String proBrief, Double proPrice, int proCount, int proStatus,
			Date proCreateDate) {
		super();
		this.proId = proId;
		this.proName = proName;
		this.proBrief = proBrief;
		this.proPrice = proPrice;
		this.proCount = proCount;
		this.proStatus = proStatus;
		this.proCreateDate = proCreateDate;
	}
	public int getProId() {
		return proId;
	}
	public void setProId(int proId) {
		this.proId = proId;
	}
	public String getProName() {
		return proName;
	}
	public void setProName(String proName) {
		this.proName = proName;
	}
	public String getProBrief() {
		return proBrief;
	}
	public void setProBrief(String proBrief) {
		this.proBrief = proBrief;
	}
	public Double getProPrice() {
		return proPrice;
	}
	public void setProPrice(Double proPrice) {
		this.proPrice = proPrice;
	}
	public int getProCount() {
		return proCount;
	}
	public void setProCount(int proCount) {
		this.proCount = proCount;
	}
	public int getProStatus() {
		return proStatus;
	}
	public void setProStatus(int proStatus) {
		this.proStatus = proStatus;
	}
	public Date getProCreateDate() {
		return proCreateDate;
	}
	public void setProCreateDate(Date proCreateDate) {
		this.proCreateDate = proCreateDate;
	}
	@Override
	public String toString() {
		return "Product [proId=" + proId + ", proName=" + proName + ", proBrief=" + proBrief + ", proPrice=" + proPrice
				+ ", proCount=" + proCount + ", proStatus=" + proStatus + ", proCreateDate=" + proCreateDate + "]";
	}
	
	
	
}

ProductMapper.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="com.gxy.dao.ProductDao">

	    <!-- 通用查询映射结果 -->
	    <resultMap id="BaseResultMap" type="com.gxy.entity.Product">
	        <id column="pro_Id" property="proId" />
	        <result column="pro_Name" property="proName" />
	        <result column="pro_Brief" property="proBrief" />
	        <result column="pro_Price" property="proPrice" />
	        <result column="pro_Count" property="proCount" />
	        <result column="pro_Status" property="proStatus" />
	        <result column="pro_Create_Date" property="proCreateDate" />
	    </resultMap>

    	<!-- 查询list -->
    	<select id="selectProductList" resultMap="BaseResultMap">
    		select * from product
    	</select>
    	
    	<!-- 插入 -->
    	<insert id="insertProduct">
    		insert into product values(seq_pro.nextval,#{proName},#{proBrief},${proPrice},${proCount},1,sysdate)
    	</insert>
    	<!-- 通过id查询商品 -->
    	<select id="selectProductById" resultMap="BaseResultMap">
    		select * from product where pro_Id=${proId}
    	</select>
    	<!-- 修改 -->
    	<update id="updateProduct">
    		update product set pro_Name=#{proName},pro_Brief=#{proBrief},pro_Price=${proPrice} where pro_Id=${proId} 
    	</update>
    	<!-- 删除 -->
    	<delete id="deleteProduct">
    		delete from product where pro_Id=${proId} 
    	</delete>
    	<!-- 修改货物状态 -->
    	<update id="updateStatus">
    		update product set pro_status=mod(pro_status+1,2) where pro_Id=${proId}
    	</update>
    	<!-- 批量删除 -->
    	<delete id="deleteBatch">
    		delete from product where pro_id in
    		<foreach collection="ids" open="(" item ="id" close=")" separator=",">
    			#{id}
    		</foreach>
    	</delete>
</mapper>

ProductDao

package com.gxy.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.gxy.entity.Product;

public interface ProductDao {
	//查询
	public List<Product> selectProductList();
	//插入
	public void insertProduct(@Param("proName")String proName,
			@Param("proBrief")String proBrief,
			@Param("proPrice")Double proPrice,
			@Param("proCount")int proCount);
	//通过id查询商品
	public Product selectProductById(@Param("proId")int proId);
	//修改
	public void updateProduct(@Param("proName")String proName,
			@Param("proBrief")String proBrief,
			@Param("proPrice")Double proPrice,
			@Param("proId")int proId);
	//删除
	public void deleteProduct(@Param("proId")int proId);
	//修改货物状态
	public void updateStatus(@Param("proId")int proId);
	//批量删除
	public void deleteBatch(@Param("ids")String[] ids);
}

ProductService

package com.gxy.service;

import java.io.IOException;
import java.util.List;
import com.gxy.entity.Product;

public interface ProductService {
	//查询
	public List<Product> selectProductList() throws IOException;
	//插入
	public void insertProduct(String proName,String proBrief,Double proPrice,int proCount)throws IOException;
	//通过id查询商品
	public Product selectProductById(int proId) throws IOException;
	//修改
	public void updateProduct(String proName,String proBrief,Double proPrice,int proId) throws IOException;
	//删除
	public void deleteProduct(int proId) throws IOException;
	//修改货物状态
	public void updateStatus(int proId) throws IOException;
	//批量删除
	public void deleteBatch(String[] ids);
}

ProductServiceImpl

package com.gxy.service.impl;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.gxy.dao.ProductDao;
import com.gxy.entity.Product;
import com.gxy.service.ProductService;
import com.gxy.util.MyBatisUtil;

public class ProductServiceimpl implements ProductService {

	//查询
	public List<Product> selectProductList() throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		List<Product> list = productDao.selectProductList();
		return list;
	}

	//插入
	public void insertProduct(String proName, String proBrief, Double proPrice, int proCount) throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		productDao.insertProduct(proName, proBrief, proPrice, proCount);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
		
	}
	//通过id查询商品
	public Product selectProductById(int proId) throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		Product productById = productDao.selectProductById(proId);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
		return productById;
	}

	//修改
	public void updateProduct(String proName, String proBrief, Double proPrice, int proId) throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		productDao.updateProduct(proName, proBrief, proPrice, proId);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
	}
	//删除
	public void deleteProduct(int proId) throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		productDao.deleteProduct(proId);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
	}
	//修改货物状态
	public void updateStatus(int proId) throws IOException {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		productDao.updateStatus(proId);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
	}
	//批量删除
	public void deleteBatch(String[] ids) {
		//获取连接
		SqlSession session = MyBatisUtil.getSqlSession();
		//通过代理生成对象
		ProductDao productDao = session.getMapper(ProductDao.class);
		//对象调方法
		productDao.deleteBatch(ids);
		//提交事务
		session.commit();
		//关闭流
		MyBatisUtil.close();
	}
}

  1. 展示商品列表的servlet
package com.gxy.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gxy.entity.Product;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

/**
 * Servlet implementation class productListAction
 */
@WebServlet("/product/productList.action")
public class productListAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取session对话
		HttpSession session = req.getSession();
		//多态调用dao方法
		ProductService serviceimpl = new ProductServiceimpl();
		//获取商品
		List<Product> list = serviceimpl.selectProductList();
		session.setAttribute("list", list);
		//转发
		req.getRequestDispatcher("/admin/product/ProductList.jsp").forward(req, resp);
	}

}
  1. 添加商品的servlet
package com.gxy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

@WebServlet("/product/productAddAction")
public class productAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//处理请求乱码
		req.setCharacterEncoding("utf-8");
		//处理响应乱码
		resp.setContentType("text/html;charset=utf-8");
		//获取信息
		String proName = req.getParameter("proName");
		Double proPrice = Double.parseDouble(req.getParameter("proPrice"));
		int proCount = Integer.valueOf(req.getParameter("proCount"));
		String proBrief = req.getParameter("proBrief");
		//多态调用dao方法
		ProductService proservice = new ProductServiceimpl();
		//执行插入信息
		proservice.insertProduct(proName, proBrief, proPrice, proCount);
		//重定向,不携带数据,地址栏改变,再次显示商品列表
		resp.sendRedirect(req.getContextPath()+"/product/productList.action");
	}
}
  1. 删除商品的servlet
package com.gxy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

@WebServlet("/product/productDeleteAction")
public class productDeleteAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取信息
		int proId = Integer.parseInt(req.getParameter("proId"));
		ProductService proservice = new ProductServiceimpl();
		//执行删除
		proservice.deleteProduct(proId);
		//重定向,不携带数据,地址栏改变,再次显示商品列表
		resp.sendRedirect(req.getContextPath()+"/product/productList.action");
	}

}
  1. 修改商品的servlet
    修改需要先获取id再执行修改操作
package com.gxy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gxy.entity.Product;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

@WebServlet("/product/productSelectByIdAction")
public class productSelectByIdAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int proId = Integer.valueOf(req.getParameter("proId"));
		ProductService proservice = new ProductServiceimpl();
		//通过id查询商品信息
		Product productById = proservice.selectProductById(proId);
		//保存在作用域中
		req.setAttribute("product", productById);
		//转发,携带数据,地址栏不变
		req.getRequestDispatcher("/admin/product/updateProduct.jsp").forward(req, resp);
		
	}

}

package com.gxy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

@WebServlet("/product/productUpdateAction")
public class productUpdateAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//处理请求乱码
		req.setCharacterEncoding("utf-8");
		//处理响应乱码
		resp.setContentType("text/html;charset=utf-8");	
		//获取前台商品信息
		int proId = Integer.valueOf(req.getParameter("proId"));
		String proName = req.getParameter("proName");
		Double proPrice = Double.parseDouble(req.getParameter("proPrice"));
		String proBrief = req.getParameter("proBrief");
		//执行修改
		ProductService proservice = new ProductServiceimpl();
		proservice.updateProduct(proName, proBrief, proPrice, proId);
		//重定向,不携带数据,地址栏改变,再次显示商品列表
		resp.sendRedirect(req.getContextPath()+"/product/productList.action");
	}

}

  1. 修改货物状态的servlet
package com.gxy.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;

@WebServlet("/product/productChangeStatusAction")
public class productChangeStatusAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取商品id
		int proId = Integer.valueOf(req.getParameter("proId"));
		//调用方法
		ProductService proservice = new ProductServiceimpl();
		//修改货物状态
		proservice.updateStatus(proId);
		//重定向,不携带数据,地址栏改变,再次显示商品列表
		resp.sendRedirect(req.getContextPath()+"/product/productList.action");
	}

}

  1. 批量删除的servlet
package com.gxy.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gxy.service.ProductService;
import com.gxy.service.impl.ProductServiceimpl;




/**
 * Servlet implementation class productSelectAction
 */
@WebServlet("/product/productBatchDeleteAction")
public class productBatchDeleteAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String[] values = req.getParameterValues("id");
		for (int i = 0; i < values.length; i++) {
			//多态调用dao方法
			ProductService proservice = new ProductServiceimpl();
			//Integer id = Integer.valueOf(values[i]);
			//执行插入信息
			proservice.deleteBatch(values);
		}
		//转发,携带数据,地址栏不变,再次显示商品列表
		req.getRequestDispatcher("/product/productList.action").forward(req, resp);
	}  
}
  1. mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
	PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

	<!-- 配置数据库连接信息 -->
	<environments default="development">
		<environment id="development">
				<transactionManager type="JDBC"/>
				<dataSource type="POOLED">
					<property name="driver" value="oracle.jdbc.OracleDriver"/>
					<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
					<property name="username" value="hr"/>
					<property name="password" value="123456"/>
			</dataSource>
		</environment>
	</environments>
	
	<!-- 配置mapper文件的路径 -->
	<mappers>
		<mapper resource="com/gxy/dao/ClientMapper.xml"/>
		<mapper resource="com/gxy/dao/ProductMapper.xml"/>
	</mappers>
	
</configuration>
  1. login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
	<head>
		<title>河南工学院</title>
		<meta content="text/html; charset=UTF-8"  http-equiv="Content-Type"/>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/login.css" />
	</head>
	<body>	
	<div id="wrap">
	
	  <div id="header">
	    <div class="topbox">
	      <div class="logo"><img src="${pageContext.request.contextPath }/images/logo.png" width='200px' /></div>
	    </div>
	  </div>
	  
	  <div id="mainer">
	  
	    <div class="login_main">
	    
	      <div class="login_img"></div>
	      <div class="login_box" style='height:450px'>
	        <div class="login_tit">用户登录</div>
	          <form method="post" action="${pageContext.request.contextPath }/client/loginAction" id="form1">
	            <div class="item">       
	                <input name="username" type="text" id="txtUserName" class="input input1" placeholder="账号"  />
	                <i class="input-username"></i>
	            </div>
	            <div class="item item2">
	                <input name="password" type="password" id="txtPassword" class="input input2" placeholder="密码" />
	                <i class="input-password"></i>
	            </div>
	            <!-- <div class="item item2">
	                <input type="checkbox" name="rememberme" value='ok' id="" />
	               		 记住我[一周]
	            </div> -->
	             <p style='color:red'>
					${errorMsg } 
	          	</p>
	            <div class="item">
	               
	            <input type="submit" name="btnLogin" value="登录" id="btnLogin" class="btn" />
				
				<a href='./Regist.html'>
				<input style='margin-top:10px' type="button" name="btnLogin" value="注册" id="btnRegist" class="btn" />
				</a>
	            </div>
	            
	          </form>
	          
	         
	      </div>
	      
	    </div>
	  
	  </div>
	  
	  <div id="footer">
	    <div class="footbox"><a href="">北京打造前程集团</a></div>
	  </div>
	</div>
	</body>
</html>
  1. ProductList.jsp
<%@page import="com.gxy.entity.Product"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>商品列表</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!--引用CSS样式  -->
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/style.css" />
	</head>
	<body>
		<div id="wrap">
			<div id="top_content"> 
				<div id="header">
					<div id="rightheader">
						<p>
							<fmt:formatDate value="${sessionScope.date }" pattern="yyyy-MM-dd HH:mm:ss" />
							<br />
						</p>
					</div>
					<div id="topheader">
						<h1 id="title">
							<a href="#">商品管理</a>
						</h1>
					</div>
					<div id="navigation">
					</div>
				</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						${realName },欢迎您!
					</h1>
					<form action="${pageContext.request.contextPath }/product/productBatchDeleteAction" method="post">
					<table class="table">
						<tr class="table_header">
							<td>
								<input type="submit" value="删除选中" />
							</td>
							<td>
								商品名
							</td>
							<td>
								单价
							</td>
							<td>库存</td>
							<td>状态</td>
							<td>添加时间</td>
							<td>
								商品描述
							</td>
							<td>
								操作
							</td>
						</tr>
						<!--商品查询 接受action数据 循环输出 -->
							<%-- <%
							List<Product> list = (List<Product>)request.getAttribute("list");
							for(Product p : list){
							 %> --%>
							 <c:forEach var='s' items="${list }">
							
							 
						<tr class="row1">
							<td>
								<input type="checkbox" name="id" value="${s.proId}" />
							</td>	
							<td>
								${s.proName}
							</td>
							<td>
								${s.proPrice}
							</td>
							<td>${s.proCount}</td>
							<td>
							<c:set var='v' value="<font color='red'>下架</font>" scope='page' />
							${s.proStatus eq 1?"上架": v}
							</td>
							<td>${s.proCreateDate}</td>
							<td>
								${s.proBrief}
							</td>
							
							<td>
								<a href="${pageContext.request.contextPath }/product/productDeleteAction?proId=${s.proId}">删除</a>&nbsp;
								<a href="${pageContext.request.contextPath }/product/productSelectByIdAction?proId=${s.proId}">修改</a>&nbsp;
								<a href="${pageContext.request.contextPath }/product/productChangeStatusAction?proId=${s.proId}">${s.proStatus eq 1?"下架":"上架"}</a>
							</td>
						</tr>
						</c:forEach>
				
					</table>
					</form>
					<p>
						<a href="${pageContext.request.contextPath }/admin/product/addProduct.jsp" class="button">添加商品</a>
					</p>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
				www.zparkhr.com.cn
				</div>
			</div>
		</div>
	</body>
</html>

13.addProduct.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<title>添加商品</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
	</head>

	<body>
		<div id="wrap">
			<div id="top_content">
				<div id="header">
					<div id="rightheader">
						<p>
							2014/6/25
							<br />
						</p>
					</div>
					<div id="topheader">
						<h1 id="title">
								<a href="#">商品管理</a>
							</h1>
					</div>
					<div id="navigation">
					</div>
				</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						添加商品:
					</h1>
					<form action="${pageContext.request.contextPath }/product/productAddAction" method="post">
						<table cellpadding="0" cellspacing="0" border="0" class="form_table">
							<tr>
								<td valign="middle" align="right">
									商品名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" name="proName" />
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									价格:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" name="proPrice" />()
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									库存:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" name="proCount" />()
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									商品描述:
								</td>
								<td valign="middle" align="left">
									<textarea rows="4" cols="30" class="inputgri" name="proBrief" tabindex="0"></textarea>
								</td>
							</tr>
						</table>
						<p>
							<input type="submit" class="button" value="确认" />
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
					www.zparkhr.com.cn
				</div>
			</div>
		</div>
	</body>

</html>
  1. updateProduct.jsp
<%-- <%@page import="com.gxy.service.ProductServiceImpl"%> --%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*,com.gxy.entity.Product" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>更新商品</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath }/css/style.css" />
	</head>

	<body>
		<div id="wrap">
			<div id="top_content">
					<div id="header">
						<div id="rightheader">
							<p>
								2014/6/25
								<br />
							</p>
						</div>
						<div id="topheader">
							<h1 id="title">
								<a href="#">商品管理</a>
							</h1>
						</div>
						<div id="navigation">
						</div>
					</div>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						更新商品:
					</h1>
					<!-- 调用service层的方法,根据ID查询图书对象
					id通过get方式得到 -->
				
					
					
					<form action="${pageContext.request.contextPath }/product/productUpdateAction" method="post">
						<table cellpadding="0" cellspacing="0" border="0"
							class="form_table">
							<tr>
								<td valign="middle" align="right" style="display:none">
									id:
								</td>
								<td valign="middle" align="left"> 
									<input type="text" class="inputgri" name="proId" value="${requestScope.product.proId }" 
									readonly="readonly" style="display:none"/>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									商品名:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" name="proName" value="${requestScope.product.proName }"/>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									价格:
								</td>
								<td valign="middle" align="left">
									<input type="text" class="inputgri" name="proPrice" value="${requestScope.product.proPrice }"/>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">
									商品描述:
								</td>
								<td valign="middle" align="left">
									<textarea rows="4" cols="30" class="inputgri" name="proBrief" tabindex="0">${requestScope.product.proBrief }</textarea>
								</td>
							</tr>
						</table>
						<p>
							<input type="submit" class="button" value="确认" />
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">
					www.zparkhr.com.cn
				</div>
			</div>
		</div>
	</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值