当前位置:网站首页>ssm框架的简单案例
ssm框架的简单案例
2022-07-06 23:34:00 【_小许_】
学完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;
}
}
仅部分代码共参考
边栏推荐
- Sorry, I've learned a lesson
- 全链路压测:影子库与影子表之争
- c语言神经网络基本代码大全及其含义
- Make web content editable
- TabLayout修改自定义的Tab标题不生效问题
- 局部变量的数组初始化问题
- Photo selector collectionview
- Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
- 利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点
- 项目经理如何凭借NPDP证书逆袭?看这里
猜你喜欢

K6EL-100漏电继电器

Leetcode (46) - Full Permutation

qt 简单布局 盒子模型 加弹簧

Y58. Chapter III kubernetes from entry to proficiency - continuous integration and deployment (Sany)

Is it necessary to renew the PMP certificate?

Initial experience of annotation

一条 update 语句的生命经历

pmp真的有用吗?

Full link voltage test: the dispute between shadow database and shadow table

10 distributed databases that take you to the galaxy
随机推荐
np. random. Shuffle and np Use swapaxis or transfer with caution
qt 简单布局 盒子模型 加弹簧
Vector and class copy constructors
Phenomenon analysis when Autowired annotation is used for list
Sorry, I've learned a lesson
最长不下降子序列(LIS)(动态规划)
在米家、欧瑞博、苹果HomeKit趋势下,智汀如何从中脱颖而出?
Timer create timer
【PHP SPL笔记】
JVM(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
Aidl and service
漏电继电器JD1-100
Disk monitoring related commands
Most commonly used high number formula
SQL injection - secondary injection and multi statement injection
U++4 interface learning notes
【oracle】简单的日期时间的格式化与排序问题
MySQL数据库学习(7) -- pymysql简单介绍
【opencv】图像形态学操作-opencv标记不同连通域的位置
Is it necessary to renew the PMP certificate?