SSM框架整合--实现简单的增删改查(商品管理系统)

本文详细介绍了使用SSM框架(Spring、SpringMVC、MyBatis)整合开发商品管理系统的步骤,包括搭建Web工程、创建数据库和表、插入初始数据、设计前端页面以及实现后端业务逻辑。涉及的后端开发包括控制器、服务接口及实现、Mapper接口和XML配置,同时展示了配置文件如log4j、mybatis、spring-common和spring-mvc的设置。

SSM框架整合步骤

1:搭建一个web工程,将所需的jar包放进去

2,创建数据库,创建表

插入2条初始数据进去

INSERT INTO product VALUE(NULL,"手机",899,2);
INSERT INTO product VALUE(NULL,"电视",1299,5);

有了数据之后,将实体类创建出来

package com.jgl.model;

public class Product {
	
	private int id;  //商品编号
    private String pName;   //商品名称
    private double pPrice;   //商品价格
    private int pNumber;   //商品数量
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public String getpName() {
		return pName;
	}
	public void setpName(String pName) {
		this.pName = pName;
	}
	public double getpPrice() {
		return pPrice;
	}
	public void setpPrice(double pPrice) {
		this.pPrice = pPrice;
	}
	public int getpNumber() {
		return pNumber;
	}
	public void setpNumber(int pNumber) {
		this.pNumber = pNumber;
	}
	
	public Product() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Product(int id, String pName, double pPrice, int pNumber) {
		super();
		this.id = id;
		this.pName = pName;
		this.pPrice = pPrice;
		this.pNumber = pNumber;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", pName=" + pName + ", pPrice=" + pPrice + ", pNumber=" + pNumber + "]";
	}
	
}

我习惯从前端往后端的顺序开发:

3,前端部分

3.1 先画首页index.jsp,放在WebContend下面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  

<html>  
<head>  
 
<title>首页</title>  
</head>  
<body>  
    <h1>  
        <a href="${pageContext.request.contextPath}/product/getAllProduct">进入商品展示页面</a>  
    </h1>  
</body>  
</html>  

3.2 在WEB-INF下面创建一个文件夹jsp,并在里面画3个页面

allProduct.jsp代码如下所示: 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    

<html>  
  <head>  
  
    <title>商品列表</title>  
      
  </head>  
    
  <body>  
    <h6><a href="${pageContext.request.contextPath}/product/toAddProduct">添加商品</a></h6>  
    <table border="1">  
        <tbody>
        	<tr><td colspan="4" align="center"><h1>商品管理</h1></td></tr>  
            <tr>  
                <th>商品名称</th>  
                <th>商品价格</th>  
                <th>商品数量</th>
                <th>操作</th>  
            </tr>  
            <c:if test="${!empty productList }">  
                <c:forEach items="${productList}" var="product">  
                    <tr>  
                        <td>${product.pName }</td>  
                        <td>¥${product.pPrice}</td>  
                        <td>${product.pNumber}</td> 
                        <td>  
                            <a href="${pageContext.request.contextPath}/product/getProduct?id=${product.id}">编辑</a>  
                            <a href="${pageContext.request.contextPath}/product/delProduct?id=${product.id}">删除</a>  
                        
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值