May 7, 2022 blog content SSM framework project management ---------- supermarket management system (Lesson 11: modify the data in the data table in the order management table)

Bejpse 2022-05-14 14:35:16 阅读数:916

blogcontentssmframeworkproject

Catalog

2022 year 5 month 7 Blog content SSM Framework project management ------------- Supermarket management system ( Lesson 11 modify the data of the data table in the order management table )

Ask a question : How to modify the data from the browser while ensuring that the data in the database can also be modified ? Here it is MVC The idea of three-tier architecture . I won't introduce the access flow chart anymore . After writing so many processes, I should keep them in my mind !

Let's clarify the idea of solving the problem :

First step : When the user clicks the button to modify data, it is certain that there must be a page to jump to , And this page must jump to the controller , Controller definition method , Used to receive subscripts , Obtain the order information to be modified according to the subscript .

The second step : After finding the modified data, you will jump to an independent modified data page . There must be a jump to the controller in this page , And jump to the controller with the modified data . The controller must receive the browser and forward it to the server .?

The third step : The controller definition method is used to receive the modified data sent by the browser to the controller , And then use it list Call in Map Set the data , Send layer by layer and finally modify the data in the database , And refresh the modified database and return the result to the controller , Then jump to the system page to refresh .

Step four : Three layers of analysis Control layer ? Business logic layer ? ? Data access layer

Step 5 code operation step by step .

Step six : Define a modification page .

First step : When the user clicks the button to modify data, it is certain that there must be a page to jump to , And this page must jump to the controller , Controller definition method , Used to receive subscripts , Obtain the order information to be modified according to the subscript .

When I modify the above data, I want to receive these data into the controller . Here is the way of annotation .

First step :

The second step :

The third step :

Step four :

Step five : Define the interface file in the logical layer :

Lesson 6 :Dao Layer Sql Statement word query .

Running results :

The next blog is to add functions , Adding functions is a little complicated , The access process is similar to modification .


2022 year 5 month 7 Blog content SSM Framework project management ------------- Supermarket management system ( Lesson 11 modify the data of the data table in the order management table )

Ask a question : How to modify the data from the browser while ensuring that the data in the database can also be modified ? Here it is MVC The idea of three-tier architecture . I won't introduce the access flow chart anymore . After writing so many processes, I should keep them in my mind !

Let's clarify the idea of solving the problem :

First step : When the user clicks the button to modify data, it is certain that there must be a page to jump to , And this page must jump to the controller , Controller definition method , Used to receive subscripts , Obtain the order information to be modified according to the subscript .

The second step : After finding the modified data, you will jump to an independent modified data page . There must be a jump to the controller in this page , And jump to the controller with the modified data . The controller must receive the browser and forward it to the server .

The third step : The controller definition method is used to receive the modified data sent by the browser to the controller , And then use it list Call in Map Set the data , Send layer by layer and finally modify the data in the database , And refresh the modified database and return the result to the controller , Then jump to the system page to refresh .

Step four : Three layers of analysis Control layer Business logic layer Data access layer

Step 5 code operation step by step .

Step six : Define a modification page .

<%@page import="com.github.pagehelper.PageInfo" %>
<%@page import="java.util.Map" %>
<%@page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Supermarket order management system -- Order list </title>
<style type="text/css">
tr {
height: 40px;
}
* {
font-family: Arial;
font-size: 20px;
font-weight: bold;
background-color: #FFF2EF;
}
td {
width: 10%;
}
input {
background: linear-gradient(100deg, black, black);
color: red;
border-radius: 12px;
}
table{
border-radius: 12px;
border-top: 3px dotted black;
border-bottom: 3px dotted black;
}
tr{
border-radius: 12px;
border-left: 2px dotted black;
}
td{
border-radius: 12px;
border-left: 2px solid #CCE8CF;
}
</style>
</head>
<body>
<% //PageInfo pi=(PageInfo)request.getAttribute("bills"); %>
<div style="width: 1800px;height: 1000px;margin: auto;">
<div style="width: 100%;height: 160px;">
<div style="width: 100%;height: 20px;">
<div align="left" style="width: 20%;height: 100%;float: left;">
&nbsp;<a href="home.do" style="text-decoration: none;"> Back to the home page </a>
</div>
<div align="right" style="width: 80%;height: 100%;float: right;">
<a> welcome ,<span style="color: red;">${user.userName}</span></a>
&nbsp;&nbsp;<a href="index.do" style="text-decoration: none;"> Cancellation </a>&nbsp;
</div>
</div>
<div align="center" style="width: 100%;height: 140px;line-height: 140px;"><h1> Supermarket order management system </h1></div>
</div>
<% //List<Map<String,Object>> list=pi.getList(); %>
<% List<Map<String, Object>> list = (List<Map<String, Object>>) request.getAttribute("bills");%>
<div align="center" style="width: 100%;height: 840px;overflow: scroll;">
<!-- Whether the current ordinary employees have talked about the order information , without , Show no information , If there is , Show all orders for this employee -->
<% if (list == null || list.size() == 0) { %>
<div style="width: 98%;text-align: center;height: 800px;">
Currently, there is no order information
</div>
<%} else { %>
<table border="2" style="width: 98%;text-align: center;border-collapse: collapse;">
<tr>
<td> Primary key Id</td>
<td> Bill code </td>
<td> Name of commodity </td>
<td> Commodity Description </td>
<td> The number </td>
<td> Commodity unit </td>
<td> Total merchandise </td>
<td> Whether to pay </td>
<td> Employee name </td>
<td> Name of supplier </td>
<td> Creation time </td>
<td> Modification time </td>
<td> Operation modification </td>
<td> Operation delete </td>
</tr>
<% for (int i = 0; i < list.size(); i++) { %>
<tr>
<td><%=list.get(i).get("id") %>
</td>
<td><%=list.get(i).get("billCode") %>
</td>
<td><%=list.get(i).get("productName") %>
</td>
<td><%=list.get(i).get("productDesc") %>
</td>
<td><%=list.get(i).get("productCount") %>
</td>
<td><%=list.get(i).get("productUnit") %>
</td>
<td><%=list.get(i).get("totalPrice")%> element </td>
<% int type = (int) list.get(i).get("isPayment"); %>
<% if (type == 1) { %>
<td style="color:red;"> Did not pay </td>
<%} else if (type == 2) { %>
<td style="color:green;"> Paid </td>
<%} %>
<td><%=list.get(i).get("userName") %>
</td>
<td><%=list.get(i).get("proName")%>
</td>
<td><%=list.get(i).get("creationDate")%>
</td>
<%
String time = "";
if (list.get(i).get("modifyDate") == null) {
time = " Not modified yet ";
} else if ("null".equals(list.get(i).get("modifyDate"))) {
time = " Not modified yet ";
} else {
time = list.get(i).get("modifyDate").toString();
}
%>
<td><%=time %>
</td>
<td>
<a href="GetBillByIndex.do?index=<%=i%>"><input type="button" value=" modify "
style="border: 2px;border-radius: 12px;color: black;color: white;background-color: red"></a>
</td>
<td>
<a href="DeleteBill.do?id=<%=list.get(i).get("id") %>"><input type="button" value=" Delete "
style="border: 2px;border-radius: 12px;color: white;background-color: green"></a>
</td>
</tr>
<%} %>
</table>
<!-- Pagination page navigation bar -->
<%--<br>
<div align="center">
<!-- Judge whether the current page has a previous page , If it does not exist, the button on the previous page will not be displayed -->
<%if(pi.getPrePage()>0){ %>
<a href="GetBills.do?ym=<%=pi.getPrePage()%>"><input type="button" value=" The previous page "/></a>&nbsp;
<%} %>
<% for(int i:pi.getNavigatepageNums()){ %>
<a href="GetBills.do?ym=<%=i%>"><%=i %></a>&nbsp;
<%} %>
<!-- Judge whether the current page has a next page , If it does not exist, the button on the next page will not be displayed -->
<% if(pi.getPageNum()<pi.getLastPage()){ %>
<a href="GetBills.do?ym=<%=pi.getNextPage()%>"><input type="button" value=" The next page "/></a>&nbsp;
<%} %>
</div>--%>
<%} %>
</div>
<a href="#"> Return to the top </a>
</div>
</body>
</html>

First step : When the user clicks the button to modify data, it is certain that there must be a page to jump to , And this page must jump to the controller , Controller definition method , Used to receive subscripts , Obtain the order information to be modified according to the subscript .

<td>
<a href="GetBillByIndex.do?index=<%=i%>"><input type="button" value=" modify "
style="border: 2px;border-radius: 12px;color: black;color: white;background-color: red"></a>
</td>
@RequestMapping("/GetBillsByUserId.do")
public ModelAndView GetBillsByUserId(HttpSession session) {
// Need from session Users saved after successful login in id As a condition for querying the database
Map<String, Object> map = (Map<String, Object>) session.getAttribute("userInfo");
long userId = (long) map.get("id");
List<Map<String, Object>> billsByUserId = bService.getBillsByUserId(userId);
ModelAndView mav = new ModelAndView();
mav.addObject("bills", billsByUserId);
mav.setViewName("billList");
return mav;

When I modify the above data, I want to receive these data into the controller . Here is the way of annotation .

First step :

@RequestMapping(value = "/updateBill.do",params =
??????? {"id","productName","productDesc","productCount","productUnit","totalPrice","isPayment","proName"})

The second step :

 // Automatically write business logic layer objects in
@Autowired
IBillService bService;
// Inject IProviderService pService
@Autowired
IProviderService pService;
List<Map<String, Object>> billls = null;
public String updateBill(long id,String productName,String productDesc,double productCount,String productUnit,
double totalPrice,int isPayment,String proName ,HttpSession session){

The third step :

 Map<String,Object> map=new HashMap<>();
map.put("id",id);
map.put("productName",productName);// Name of commodity
map.put("productDesc",productDesc);// Commodity Description
map.put("productCount",productCount);// The number
map.put("productUnit",productUnit);// Commodity unit
map.put("totalPrice",totalPrice);// Total sum
map.put("isPayment",isPayment);
map.put("proName",proName);// Name of supplier

Step four :

 // Manager's id
map.put("modifyBy",((Map<String,Object>)session.getAttribute("userInfo")).get("id"));
// Modify the real-time time time of the order
map.put("modifyDate",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
System.out.println(" The data obtained is "+map);

Step five : Define the interface file in the logical layer :

 // modify
int updateBill(Map<String,Object> map);
@Autowired
IBillDao dao;
@Override
public int updateBill(Map<String, Object> map) {
}

Lesson 6 :Dao Layer Sql Statement word query .

 // Modify the content
@Update("update smbms_bill set smbms_bill.productName=#{productName}, " +
"smbms_bill.productDesc=#{productDesc},smbms_bill.productCount=#{productCount}," +
"smbms_bill.productUnit=#{productUnit},smbms_bill.isPayment=#{isPayment}, " +
"smbms_bill.totalPrice=#{totalPrice},smbms_bill.modifyBy=#{modifyBy}, " +
"smbms_bill.modifyDate=#{modifyDate}, " +
"smbms_bill.providerId=(SELECT id from smbms_provider where proName=#{proName})" +
"WHERE smbms_bill.id=#{id}")
int updateBill(Map<String, Object> map);
@Override
public int updateBill(Map<String, Object> map) {
return dao.updateBill(map);
}
int i = bService.updateBill(map);
String url="";
if (i>0)
// Order modification succeeded , Refresh the order list page
System.out.println(" Modified an order management information ");
url="redirect:GetBills.do";
return url;

Running results :

The next blog is to add functions , Adding functions is a little complicated , The access process is similar to modification .

版权声明:本文为[Bejpse]所创,转载请带上原文链接,感谢。 https://qdmana.com/2022/134/202205141340163720.html