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>

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

937

被折叠的 条评论
为什么被折叠?



