更新时间:2022-12-13 11:30:37 来源:动力节点 浏览1025次
小编来给大家举个比较简单的SSM框架项目实例。
项目结构图:
看项目结构:
关键代码:
前端是jsp技术,当然也可以用vue分离的自己选择就好。
订单页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%@include file="./common/head.jsp"%>
<div class="right">
<div class="location">
<strong>你现在所在的位置是:</strong>
<span>订单管理页面</span>
</div>
<div class="search">
<form method="get" action="${pageContext.request.contextPath }/jsp/bill.do">
<input name="method" value="query" class="input-text" type="hidden">
<span>商品名称:</span>
<input name="queryProductName" type="text" value="${queryProductName }">
<span>供应商:</span>
<select name="queryProviderId">
<c:if test="${providerList != null }">
<option value="0">--请选择--</option>
<c:forEach var="provider" items="${providerList}">
<option value="${provider}">${provider}</option>
</c:forEach>
</c:if>
</select>
<span>是否付款:</span>
<select name="queryIsPayment">
<option value="0">--请选择--</option>
<option value="1" ${queryIsPayment == 1 ? "selected=\"selected\"":"" }>未付款</option>
<option value="2" ${queryIsPayment == 2 ? "selected=\"selected\"":"" }>已付款</option>
</select>
<input value="查 询" type="submit" id="searchbutton">
<a href="${pageContext.request.contextPath }/billadd">添加订单</a>
</form>
</div>
<!--账单表格 样式和供应商公用-->
<table class="providerTable" cellpadding="0" cellspacing="0">
<tr class="firstTr">
<th width="10%">订单编码</th>
<th width="20%">商品名称</th>
<th width="10%">供应商</th>
<th width="10%">订单金额</th>
<th width="10%">是否付款</th>
<th width="10%">创建时间</th>
<th width="30%">操作</th>
</tr>
<c:forEach var="bill" items="${billList }" varStatus="status">
<tr>
<td>
<span>${bill.billCode }</span>
</td>
<td>
<span>${bill.productName }</span>
</td>
<td>
<span>${bill.providerId}</span>
</td>
<td>
<span>${bill.totalPrice}</span>
</td>
<td>
<span>
<c:if test="${bill.isPayment == 1}">未付款</c:if>
<c:if test="${bill.isPayment == 2}">已付款</c:if>
</span>
</td>
<td>
<span>
${bill.creationDate}
</span>
</td>
<td>
<span><a class="viewBill" href="${pageContext.request.contextPath }/billview?code=${bill.billCode}" billid=${bill.id } billcc=${bill.billCode }><img src="${pageContext.request.contextPath }/images/read.png" alt="查看" title="查看"/></a></span>
<span><a class="modifyBill" href="${pageContext.request.contextPath }/billmodify?code=${bill.billCode}" billid=${bill.id } billcc=${bill.billCode }><img src="${pageContext.request.contextPath }/images/xiugai.png" alt="修改" title="修改"/></a></span>
<span><a class="deleteBill" href="javascript:deleteBill();" billid=${bill.id } billcc=${bill.billCode }><img src="${pageContext.request.contextPath }/images/schu.png" alt="删除" title="删除"/></a></span>
</td>
</tr>
</c:forEach>
</table>
</div>
</section>
<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeBi">
<div class="removerChid">
<h2>提示</h2>
<div class="removeMain">
<p>你确定要删除该订单吗?</p>
<a href="#" id="yes">确定</a>
<a href="#" id="no">取消</a>
</div>
</div>
</div>
<%@include file="./common/foot.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/billlist.js"></script>
界面就没有上面好看的了,框架自行下载。
供应商页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="./common/head.jsp"%>
<div class="right">
<div class="location">
<strong>你现在所在的位置是:</strong>
<span>供应商管理页面</span>
</div>
<div class="search">
<form method="get" action="${pageContext.request.contextPath }/provider.select">
<input name="method" value="query" type="hidden">
<span>供应商编码:</span>
<input name="queryProCode" type="text" value="${queryProCode }">
<span>供应商名称:</span>
<input name="queryProName" type="text" value="${queryProName }">
<input value="查 询" type="submit" id="searchbutton">
<a href="${pageContext.request.contextPath }/jsp/provideradd.jsp">添加供应商</a>
</form>
</div>
<!--供应商操作表格-->
<table class="providerTable" cellpadding="0" cellspacing="0">
<tr class="firstTr">
<th width="10%">供应商编码</th>
<th width="20%">供应商名称</th>
<th width="10%">联系人</th>
<th width="10%">联系电话</th>
<th width="10%">传真</th>
<th width="10%">创建时间</th>
<th width="30%">操作</th>
</tr>
<c:forEach var="provider" items="${providerList }" varStatus="status">
<tr>
<td>
<span>${provider.proCode }</span>
</td>
<td>
<span>${provider.proName }</span>
</td>
<td>
<span>${provider.proContact}</span>
</td>
<td>
<span>${provider.proPhone}</span>
</td>
<td>
<span>${provider.proFax}</span>
</td>
<td>
<span>
${provider.creationDate}
</span>
</td>
<td>
<span><a class="viewProvider" href="${pageContext.request.contextPath }/providerview?code=${provider.proCode}" proid=${provider.id } proname=${provider.proName }><img src="${pageContext.request.contextPath }/images/read.png" alt="查看" title="查看"/></a></span>
<span><a class="modifyProvider" href="${pageContext.request.contextPath }/provideralter?code=${provider.proCode}" proid=${provider.id } proname=${provider.proName }><img src="${pageContext.request.contextPath }/images/xiugai.png" alt="修改" title="修改"/></a></span>
<span><a class="deleteProvider" href="javascript:;" proid=${provider.id } proname=${provider.proName }><img src="${pageContext.request.contextPath }/images/schu.png" alt="删除" title="删除"/></a></span>
</td>
</tr>
</c:forEach>
</table>
</div>
</section>
<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeProv">
<div class="removerChid">
<h2>提示</h2>
<div class="removeMain" >
<p>你确定要删除该供应商吗?</p>
<a href="#" id="yes">确定</a>
<a href="#" id="no">取消</a>
</div>
</div>
</div>
<%@include file="./common/foot.jsp" %>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/providerlist.js"></script>
主要是前后端的交互部分,控制器都是由spring容器控制,注意要释放静态资源。
订单后台:
package cms.ssm.controller;
import cms.ssm.dao.BillMapper;
import cms.ssm.dao.ProviderMapper;
import cms.ssm.model.Bill;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Controller
public class BillController {
@Resource
private BillMapper billMapper;
@Resource
private ProviderMapper providerMapper;
@GetMapping("/bill")
public String showBill(Model model){
List<Bill> bills = billMapper.selectAll();
List<String> list = providerMapper.selectProviderNames();
model.addAttribute("billList",bills);
model.addAttribute("providerList",list);
return "/jsp/billlist.jsp";
}
@GetMapping("/billview")
public String showOne(@RequestParam("code") String code,Model model){
Bill bill = billMapper.selectByCode(code);
model.addAttribute("bill",bill);
return "/jsp/billview.jsp";
}
@GetMapping("/billmodify")
public String alterBill(@RequestParam("code") String code,Model model){
Bill bill = billMapper.selectByCode(code);
List<String> list = providerMapper.selectProviderNames();
model.addAttribute("bill",bill);
model.addAttribute("provider",list);
return "/jsp/billmodify.jsp";
}
@GetMapping(value = "/jsp/bill.do")
public String select_more(@RequestParam("method") String method,@RequestParam("queryProductName") String queryProductName,@RequestParam("queryIsPayment") int queryIsPayment,Model model){
List<Bill> billList = billMapper.selectMore("%"+queryProductName+"%", queryIsPayment);
model.addAttribute("billList",billList);
return "/jsp/billlist.jsp";
}
@GetMapping(value = "/billadd")
public String billAdd(Model model){
List<String> list = providerMapper.selectProviderNames();
model.addAttribute("list",list);
return "/jsp/billadd.jsp";
}
@RequestMapping(value = "/billadd.do", method = RequestMethod.GET)
public void billAddColumn(@RequestParam("billCode") String billCode, @RequestParam("productName") String productName, @RequestParam("productCount") Double productCount,@RequestParam("productUnit") String productUnit,@RequestParam("providerId") int providerId){
Bill bill =new Bill();
bill.setBillCode(billCode);
bill.setProductName(productName);
bill.setProductCount(productCount);
bill.setProductUnit(productUnit);
bill.setProviderId(providerId);
billMapper.insertOneBill(bill);
}
}
供应商后台:
package cms.ssm.controller;
import cms.ssm.dao.ProviderMapper;
import cms.ssm.dao.UserMapper;
import cms.ssm.model.Provider;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
@Controller
public class ProviderController {
@Resource
private ProviderMapper providerMapper;
// @Resource
// private UserMapper userMapper;
@GetMapping(value = "/provider")
public String showProviders(Model model){
List<Provider> list= providerMapper.selectAll();
//List<String> roles= userMapper.select_all_role();
model.addAttribute("providerList",list);
return "jsp/providerlist.jsp";
}
@GetMapping(value = "/providerview")
public String providerView(@RequestParam("code") String code,Model model){
Provider provider= providerMapper.selectById(code);
model.addAttribute("provider",provider);
return "/jsp/providerview.jsp";
}
@GetMapping(value = "/provideralter")
public String providerAlter(@RequestParam("code") String code,Model model){
Provider provider= providerMapper.selectById(code);
model.addAttribute("provider",provider);
return "/jsp/providermodify.jsp";
}
@GetMapping(value = "/provider.select")
public String providerSelect(Model model,@RequestParam("queryProCode") String queryProCode,@RequestParam("queryProName") String queryProName){
List<Provider> list = providerMapper.selectMore("%"+queryProCode+"%", "%"+queryProName+"%");
model.addAttribute("providerList",list);
return "/jsp/providerlist.jsp";
}
@GetMapping(value = "/provideradd.do")
public String providerAdd(@RequestParam("proCode") String proCode,@RequestParam("proName") String proName,@RequestParam("proContact") String proContact,@RequestParam("proPhone") String proPhone,@RequestParam("proAddress") String proAddress,@RequestParam("proFax") String proFax,@RequestParam("proDesc") String proDesc){
Provider provider = new Provider();
provider.setProCode(proCode);
provider.setProName(proName);
provider.setProContact(proContact);
provider.setProPhone(proPhone);
provider.setProAddress(proAddress);
provider.setProFax(proFax);
provider.setProDesc(proDesc);
providerMapper.insertOne(provider);
return "/jsp/provideradd.jsp";
}
@GetMapping(value = "/provider.oparater")
@ResponseBody
public String providerOparater(@RequestParam("proid") int id){
providerMapper.delById(id);
String delResult = "true";
return delResult;
}
}
0基础 0学费 15天面授
Java就业班有基础 直达就业
业余时间 高薪转行
Java在职加薪班工作1~3年,加薪神器
工作3~5年,晋升架构
提交申请后,顾问老师会电话与您沟通安排学习