jdbc操作数据库 and 一个商品管理页面

文章目录

  • 1. 介绍
    • 1.1 应用知识介绍
    • 1.2 项目介绍
  • 2. 文件目录
    • 2.1 目录
    • 2.2 介绍以下(从上到下)
  • 3. 相关代码
    • 3.1 DBConnection.java
    • 3.2 MysqlUtil.java
    • 3.3 AddServlet.java
    • 3.4 CommodityServlet.java
    • 3.5 DelectServlet.java
    • 3.6 SelectByIdServlet.java
    • 3.7 SelectServlet.java
    • 3.8 UpdataServlet.java
    • 3.9 style.css
    • 3.10 index.js
    • 3.11 jquery-3.7.1.min.js(略)
    • 3.12 index.html
  • 4. 效果展示
  • 5. 链接
  • 6. 思考

很丑,主要学习方法

1. 介绍

1.1 应用知识介绍

基础知识:mySQL,jbdc,JQuery,ajax

mySQL中对于表的增删改查
jQuery对于前端元素的获取
ajax传递数据和获取数据

1.2 项目介绍

是一个商品管理系统,需要自己先创建好一个表如图:
表
其中类型就不多说了。
前端交互界面设计:交互
对商品数据进行增删改查

2. 文件目录

2.1 目录

目录

2.2 介绍以下(从上到下)

DBConnection.java:用于连接数据库
MysqlUtil.java:操作数据库
AddServlet.java:增加商品
CommodityServlet.java:初始化时候进行查询
DelectServlet.java:删除数据库中的相关数据
SelectByIdServlet.java:通过id获取数据
SelectServlet.java:通过名字获取数据,用于查询
UpdataServlet.java:更新数据


style.css:样式
index.js:写js
jquery-3.7.1.min.js:引入jquery
index.html:写界面

3. 相关代码

3.1 DBConnection.java

package com.qcby.db;import java.sql.Connection;
import java.sql.DriverManager;public class DBConnection {public static void main(String[] args) {}String driver = "com.mysql.jdbc.Driver";String url = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false";String user = "root";String password = "root";public Connection conn;public DBConnection() {try {Class.forName(driver);conn = (Connection) DriverManager.getConnection(url, user, password);//// if(!conn.isClosed())// System.out.println("Succeeded connecting to the Database!");} catch (Exception e) {e.printStackTrace();}}public void close() {try {this.conn.close();} catch (Exception e) {e.printStackTrace();}}}

3.2 MysqlUtil.java

package com.qcby.db;import java.rmi.StubNotFoundException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MysqlUtil {public static void main(String[] args) {//		String sqlcount = "select count(*) from admin";
//		String sql = "select * from admin";
//		String[] colums = {"id","account","password"};
//		String json = getJsonBySql(sqlcount, sql, colums);
//		System.out.println(json);/*String sql = "insert into t_student(name,age,sex) values(\"张三\",21,\"男\")";System.out.println(add(sql));*//*String sqldel = "delete from gq_user where id=11";System.out.println(del(sqldel));*//** String sqlupdate ="update user set age = 60 where name=\"you\"";* System.out.println(update(sqlupdate));*//*String sql = "select count(*) from gq_user";System.out.println(getCount(sql));*//*String[] col = {"id","name","age"};String sql = "select * from t_student";String sqlCount = "select count(*) from t_student";String strJson = getJsonBySql(sqlCount,sql,col);System.out.println(strJson);*//*String sqlcount = "select count(*) from gq_user";String sql="select * from gq_user";String[] col = {"username","age","id","sex","salary"};System.out.println(getJsonBySql(sqlcount, sql, col));*//** String sql = "select * from user"; String[] column =* {"id","name","age","entrydate"}; ArrayList<String[]> strings =* MysqlUtil.showUtil(sql, column); for (String[] string : strings) {* System.out.println(Arrays.toString(string)); }*/}/*添加*/public static int add(String sql) {// System.out.println("sql语句是:" + sql);int i=0;//数据库连接DBConnection db = new DBConnection();try {        PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(sql);i=preStmt.executeUpdate();preStmt.close();db.close();//关闭连接 System.out.println("数据插入成功,sql语句是:" + sql);} catch (Exception e) {e.printStackTrace();}System.out.println(i);return i;//返回影响的行数,1为执行成功;}/*修改数据*/public static int update(String sql) {int i =0;DBConnection db = new DBConnection();try {PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(sql);i = preStmt.executeUpdate();preStmt.close();db.close();System.out.println("数据更新成功,sql语句是:" + sql);} catch (SQLException e) {e.printStackTrace();}return i;}/*删除*/public static int del(String delstr) {int i=0;DBConnection db = new DBConnection();try {    PreparedStatement preStmt = (PreparedStatement) db.conn.prepareStatement(delstr);i=preStmt.executeUpdate();//executeUpdate()返回受影响的行数preStmt.close();db.close();System.out.println("数据删除成功,sql语句是:" + delstr);} catch (SQLException e){e.printStackTrace();}return i;}/*查询数量*/public static int getCount(String sql) {int sum = 0;DBConnection db = new DBConnection();try {Statement stmt = (Statement) db.conn.createStatement();ResultSet rs = (ResultSet) stmt.executeQuery(sql);while (rs.next()) {sum += rs.getInt(1);}rs.close();db.close();} catch (Exception e) {// TODO: handle exception}return sum;}/***功能描述 查询json数据带数据总量* @author 郭帅* @date 2021-03-22 10:30* @param sqlcount 查询数量的sql* @param sql 查询具体数据的sql* @param colums 查询的字段* @return java.lang.String*/public static String getJsonBySqlDataGrid( String sqlcount,String sql,String[] colums){int count = getCount(sqlcount);System.err.println("标红信息展示sql:" + sql);ArrayList<String[]>  result = new ArrayList<String[]>();DBConnection db = new DBConnection();try {Statement stmt = (Statement) db.conn.createStatement();ResultSet rs = (ResultSet) stmt.executeQuery(sql);while(rs.next()){String[] dataRow = new String[colums.length];for( int i = 0; i < dataRow.length; i++ ) {dataRow[i] = rs.getString( colums[i] );}result.add(dataRow);}rs.close();db.close();//} catch (SQLException e) {e.printStackTrace();}return listToJsonDataGrid(result,colums,count);}/***功能描述 查询json数据* @author 郭帅* @date 2021-03-22 10:30* @param sql 查询具体数据的sql* @param colums 查询的字段* @return java.lang.String*/public static String getJsonBySql( String sql,String[] colums){System.err.println("标红信息展示sql:" + sql);ArrayList<String[]>  result = new ArrayList<String[]>();DBConnection db = new DBConnection();try {Statement stmt = (Statement) db.conn.createStatement();ResultSet rs = (ResultSet) stmt.executeQuery(sql);while(rs.next()){String[] dataRow = new String[colums.length];for( int i = 0; i < dataRow.length; i++ ) {dataRow[i] = rs.getString( colums[i] );}result.add(dataRow);}rs.close();db.close();//} catch (SQLException e) {e.printStackTrace();}return listToJson(result,colums);}/***功能描述 查询数据* @author 郭帅* @date 2021-03-22 10:38* @param sql 查询具体数据的sql* @param colums  查询的字段* @return java.util.ArrayList<java.lang.String[]>*/public static ArrayList<String[]> showUtil( String sql, String[] colums){ArrayList<String[]>  result = new  ArrayList<String[]>();DBConnection db = new DBConnection();try {Statement stmt = (Statement) db.conn.createStatement();ResultSet rs = (ResultSet) stmt.executeQuery(sql);while(rs.next()){String[] dataRow = new String[colums.length];for( int i = 0; i < dataRow.length; i++ ) {dataRow[i] = rs.getString( colums[i] );}result.add(dataRow);}rs.close();db.close();//} catch (SQLException e) {e.printStackTrace();}return result;}/*** 转化为json数据字符串* @param* @return*/public static String listToJsonDataGrid( ArrayList<String[]> list,String[] colums,int count) {String jsonStr = "{\"code\":0,\"msg\":\"成功了\",\"count\":"+count+",\"data\":[";for(int i = 0; i < list.size(); i++) {String arr = "{";for( int j = 0; j < list.get(0).length; j++) {if( list.get(i)[j] == null || "NULL".equals(list.get(i)[j])) {arr += "\"" + colums[j] + "\":\"\"";}else {arr += "\"" + colums[j] + "\""+":" ;arr +=  "\"" + list.get(i)[j].replace("\"","\\\"") + "\"";}if( j < list.get(0).length - 1 ) {arr += ",";}}arr += "}";if( i < list.size() - 1 ) {arr += ",";}jsonStr += arr;}jsonStr += "]}";return jsonStr;}/*** 转化为json数据字符串* @param* @return*/public static String listToJson( ArrayList<String[]> list,String[] colums) {String jsonStr = "{\"code\":0,\"msg\":\"成功了\",\"data\":[";for(int i = 0; i < list.size(); i++) {String arr = "{";for( int j = 0; j < list.get(0).length; j++) {if( list.get(i)[j] == null || "NULL".equals(list.get(i)[j])) {arr += "\"" + colums[j] + "\":\"\"";}else {arr += "\"" + colums[j] + "\""+":" ;arr +=  "\"" + list.get(i)[j].replace("\"","\\\"") + "\"";}if( j < list.get(0).length - 1 ) {arr += ",";}}arr += "}";if( i < list.size() - 1 ) {arr += ",";}jsonStr += arr;}jsonStr += "]}";return jsonStr;}}

3.3 AddServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class AddServlet*/
@WebServlet("/add")
public class AddServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public AddServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");String name = request.getParameter("name");String number = request.getParameter("num");String price = request.getParameter("price");String sql = "insert into commodity(name, num, price) VALUES ('"+ name + "', " + number + ", "+ price + ");";int num = MysqlUtil.add(sql);response.getWriter().write(num + "");}
}

3.4 CommodityServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class CommodityServlet*/
@WebServlet("/commodity")
public class CommodityServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public CommodityServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");//设置返回数据的格式response.setContentType("text/json;charset:utf-8");String sql = "select * from commodity";String[] column ={"id","name","num","price"};String res = MysqlUtil.getJsonBySql(sql, column);System.out.println(res);// 响应数据response.getWriter().write(res);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

3.5 DelectServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class DelectServlet*/
@WebServlet("/del")
public class DelectServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public DelectServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub// 接受参数String id = request.getParameter("id");String sql = "delete from commodity where id = " + id;int num = MysqlUtil.del(sql);response.getWriter().write(num);}}

3.6 SelectByIdServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class SelectByIdServlet*/
@WebServlet("/selectById")
public class SelectByIdServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public SelectByIdServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubString id = request.getParameter("id");String sql = "select * from commodity where id ='" + id +"';";response.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");//设置返回数据的格式response.setContentType("text/json;charset:utf-8");String[] column ={"id","name","num","price"};String res = MysqlUtil.getJsonBySql(sql, column);System.out.println(res);// 响应数据response.getWriter().write(res);}}

3.7 SelectServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class SelectServlet*/
@WebServlet("/select")
public class SelectServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public SelectServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubString name = request.getParameter("name");String sql = "select * from commodity where name ='" + name +"';";response.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");//设置返回数据的格式response.setContentType("text/json;charset:utf-8");String[] column ={"id","name","num","price"};String res = MysqlUtil.getJsonBySql(sql, column);System.out.println(res);// 响应数据response.getWriter().write(res);}}

3.8 UpdataServlet.java

package com.qcby.servlet;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.qcby.db.MysqlUtil;/*** Servlet implementation class UpdataServlet*/
@WebServlet("/updata")
public class UpdataServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public UpdataServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");String id = request.getParameter("id");String name = request.getParameter("name");String number = request.getParameter("num");String price = request.getParameter("price");String sql = "update commodity set  name = '" + name + "', num = "+ number +", price="+ price +" where id = " + id +";";int num = MysqlUtil.update(sql);response.getWriter().write(num + "");}}

3.9 style.css

*{margin: 0;padding: 0;
}
@font-face {font-family: YUZ;src: url(./YXZ.ttf);
}
body{position: relative;padding-top: 100px;
}
#todo {width: 500px;min-width: 500px;padding: 5px;background:linear-gradient(red,blue);background:-moz-linear-gradient(left,#ace,#f96);background:-webkit-gradient(linear,0 50%,100% 50%,from(#ace),to(#f96));background:-webkit-linear-gradient(left,#ace,#f96);background:-o-linear-gradient(left,#ace,#f96);margin: auto;border-radius: 10px;border: solid 1px wheat;
}
#todo .cmmodityName{width: 50%;height:25px;line-height:30px;border-radius: 10px 10px 10px 10px;border: solid 1px rgb(255, 255, 255);margin-bottom: 10px;padding-left: 10px;font-size: 20px;
}#todo .add, #todo .select{width: 15%;height:30px;line-height:30px;border-radius: 10px 10px 10px 10px;background-color: rgb(39, 160, 225);border: solid 1px rgb(255, 255, 255);margin-bottom: 10px;
}
#todo #add{width: 40%;border-radius: 0px 10px 10px 0px;background-color: rgb(39, 160, 225);border: 0;cursor: pointer;color: rgb(255, 255, 255);
}
#todoList{width: 100%;border-radius: 10px;overflow: hidden;color: white;
}
#todoList thead {background-color: rgb(39, 160, 225);
}
#todoList thead td:first-child {width: 20%;border-radius: 10px 0px 0px 0px;
}
#todoList thead td:last-child {border-radius: 0px 10px 0px 0px;
}
#todoList tr{width: 100%;height: 40px;text-align: center;color: rgb(51, 51, 51);
}
#todoList td{border: solid 1px white ; 
}
#todoList tr td input{width: 45px;height: 25px;line-height: 25px;font-family: Arial, Helvetica, sans-serif;background-color: #ace;border: solid 1px white;color: rgb(67, 67, 67);
}
#todoList tr td input:first-child{border-radius: 5px 0 0 5px;
}
#todoList tr td input:last-child{border-radius: 0 5px 5px 0;border-left: 0;
}
#add_div, #add_div2{position: absolute;top: 0;left: 0;background-color: rgba(255, 255, 255, 0.95);width: 100%;height: 100vh;
}
#add_div .add_div{margin: auto;padding: 5px;border: solid 2px #ac0f0f;border-radius: 3px;position: absolute;width: 20%;height: 20%;top: 40%;left: 40%;
}
#add_div .add_div input{height: 20px;width: 150px;padding-left: 5px;
}
#add_div2 .add_div{margin: auto;padding: 5px;border: solid 2px #ac0f0f;border-radius: 3px;position: absolute;width: 20%;height: 20%;top: 40%;left: 40%;
}
#add_div2 .add_div tr th{width: 100px;height: 30px;
}
#add_div2 .add_div span{height: 20px;width: 100px;padding-left: 5px;
}
#add_div2 .add_div input{height: 20px;width: 200px;
}

3.10 index.js

// 初始化
$.ajax({url:"commodity",type: "get",success:function(value){console.log(value);var arr = value.data;for(let i = 0 ; i < arr.length; i ++){$("#one").append("<tr>" + "<td>" + arr[i].name +"</td>"+"<td>" + arr[i].num +"</td>"+"<td>" + arr[i].price +"</td>"+"<td>" + "<input type=\"button\" value=\"修改\" class=\"reUpdata\" index = \"" + arr[i].id + "\">" + "<input type=\"button\" class = \"del\" value=\"删除\" index = \""+ arr[i].id +"\">" + "</td>")}},error:function(){alert("失败了!!");}
})
// 删除
$("tbody").on("click",".del", function(){var id = $(this).attr("index");$.ajax({url:"del",type:"post",data:{id},success:function(value){location.reload();},error: function(){alert("失败了!!");}})
})
var flag = 1;
// 点击添加
$(".add").on("click",function(){$("#add_div").css("display","block");$(".name").val("");$(".num").val("");$(".price").val("");$(".upData").val("添加商品");flag = 1;
})
// 点击取消
$(".back").on("click", function(){$("#add_div").css("display","none");
})
// 取消查找
$(".back2").on("click", function(){$("#add_div2").css("display","none");
})
// 点击查找
$(".select").on("click",function(){var name = $(".cmmodityName").val();if(name==""){alert("输入正确的格式!!!");return;}$.ajax({url:"select",type:"post",data:{name},success:function(value){if(value.data.length == 0){alert("不存在该物品");return;}var arr = value.data[0];$(".Cname").text(arr.name);$(".Cnum").text(arr.num);$(".Cprice").text(arr.price);$("#add_div2").css("display","block");},error:function(){alert("不存在该物品");}});})
// 点击第二个添加,更新数据
$(".upData").on("click", function(){// 是1,就是添加if(flag ==1){var name = $(".name").val();var num = $(".num").val();var price = $(".price").val();$.ajax({url:"add",type:"post",data:{name,num,price},success:function(value){console.log(value);if(value=="0"){alert("请输入正确格式!!!");}else{location.reload();alert("添加成功!!!");}},error:function(){alert("失败了")}})}else{var id = $(".Cid").val();var name = $(".name").val();var num = $(".num").val();var price = $(".price").val();$.ajax({url:"updata",type:"post",data:{id, name, num, price},success:function(value){console.log(value);if(value=="0"){alert("请输入正确格式!!!");}else{location.reload();alert("修改成功!!!")}},error:function(){alert("失败了");}})}
})
// 点击修改
$("tbody").on("click",".reUpdata", function(){$("#add_div").css("display","block");id = $(this).attr("index");$.ajax({url:"selectById",type:"post",data:{id},success:function(value){flag = 0;var arr = value.data[0];$(".Cid").val(arr.id);$(".name").val(arr.name);$(".num").val(arr.num);$(".price").val(arr.price);$(".upData").val("修改");},error: function(){alert("失败了!!");}})
})

3.11 jquery-3.7.1.min.js(略)

3.12 index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title></title><link rel="stylesheet" href="css/style.css"><script src="js/jquery-3.7.1.min.js"></script><script src="js/index.js" defer></script>
</head>
<body><!-- <div>demo</div><a href="test">你好</a> --><div id="todo">商品名称:<input type="text" class="cmmodityName"><input type="button"  class="select" value="查找"><input type="button"  class="add" value="添加"><table id="todoList" cellpadding="0" cellspacing="0" ><thead><td>商品名字</td><td>数量</td><td>价格</td><td>操作</td></thead><tbody id ="one"></tbody></table></div><div id="add_div" style="display:none"><table class="add_div"><tr><th>商品名称:</th><th><input type="text" class="name"></th></tr><tr><th>商品数量:</th><th><input type="text" class="num"></th></tr><tr><th>商品价格:</th><th><input type="text" class="price"></th></tr><tr><th> <input type="button" value="添加" class="upData"></th><th><input type="button" value="取消" class="back"></th></tr></table></div><div id="add_div2" style="display:none"><span class="Cid" style="display:none">1</span><table class="add_div"><tr><th>商品名称:</th><th><span class="Cname">XXX</span></th></tr><tr><th>商品数量:</th><th><span class="Cnum">XXX</span></th></tr><tr><th>商品价格:</th><th><span class="Cprice">XXX</span></th></tr><tr><th colspan="2"><input type="button" value="取消" class="back2"></th></tr></table></div></body>
</html>

4. 效果展示

查找不存在的物品:
查找1
查找成功:
查找2
点击添加:
在这里插入图片描述

添加成功:
在这里插入图片描述
在这里插入图片描述

添加失败:
在这里插入图片描述

点击删除就直接没了

点击修改:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5. 链接

javaWeb项目创建

史上最全MySQL基本操作(这一篇就够用了!!!)

6. 思考

目前还是不完美的,当添加商品时,商品已经存在表里,仍然能添加上,就交给你去修改了。(因为我比较懒。。。。)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/827413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

揭秘Faiss:大规模相似性搜索与聚类的技术神器深度解析!

Faiss&#xff08;由Facebook AI Research开发&#xff09;是一个用于高效相似性搜索和密集向量聚类的库。它用C编写&#xff0c;并提供Python绑定&#xff0c;旨在帮助研究人员和工程师在大规模数据集上进行快速的相似性搜索和聚类操作。 一、介绍&#xff1a; Faiss的核心功…

双链向表专题

1.链表的分类 链表的种类非常多组合起来就有 2 2 8种 链表说明&#xff1a; 虽然有这么多的链表的结构&#xff0c;但是我们实际中最常⽤还是两种结构&#xff1a; 单链表 和 双向带头循环链表 1. 无头单向⾮循环链表&#xff1a;结构简单&#xff0c;⼀般不会单独⽤来存数…

Ultralytics YOLOv8 英伟达™ Jetson®处理器部署

系列文章目录 前言 本综合指南提供了在英伟达 Jetson设备上部署Ultralytics YOLOv8 的详细攻略。此外&#xff0c;它还展示了性能基准&#xff0c;以证明YOLOv8 在这些小巧而功能强大的设备上的性能。 备注 本指南使用Seeed Studio reComputer J4012进行测试&#xff0c;它基于…

在邮件控件Aspose.Email中,处理Outlook TNEF 格式电子邮件

Microsoft Outlook 中常见的传输中性封装格式 (TNEF)电子邮件在处理和提取其内容时可能会带来挑战。在这篇博文中&#xff0c;我们将探讨如何使用强大的 .NET C# 库来处理此类消息&#xff0c;该库简化了各种电子邮件格式&#xff08;包括 TNEF&#xff09;的处理。 Aspose.Em…

尚硅谷-JavaSE阶段考试与面试题库

一、基础题 1&#xff09;用最有效的的方法算出2称以8等于几 答案&#xff1a;2<<3 2&#xff09;两个对象a和b&#xff0c;请问ab和a.equals(b)有什么区别&#xff1f; ab&#xff1a;比较对象地址 a.equals(b)&#xff1a;如果a对象没有重写过equals方法&#xff0c…

【技术干货】润石红外额温枪方案芯片功能介绍

手持红外额温枪框图中&#xff0c;以电池采用9V为例&#xff0c;先通过一个高压LDO RS3002 把电池电压转为3V&#xff0c;供整个系统使用&#xff0c;包括为 MCU&#xff0c;背光灯&#xff0c;运放 等器件供电&#xff0c;然后再用一个低功耗LDO RS3236 从3V 降为1.5V&#…

rc_visard 3D Stereo Senso

1 简介 rc_visard 3D立体视觉传感器 支持的接口标准 GenICam Generic Interface for CamerasGigE Gigabit Ethernet 词汇表 SGM semi-global matching 半全局匹配 SLAM Simultaneous Localization and Mapping 即时定位与地图构建 2 安全 3 硬件规格 坐标系 rc_visar…

TypeScript 中 interface 和 type 的使用#记录

一、interface&#xff1a;接口 interface A{label: string; }const aa ((aObj: A) > {console.log(aObj.label);//123return aObj.label; })aa({label: 123}) 1、可选属性 interface A{label: string;age?: number; } 2、只读属性 interface A{label: string;age?:…

231 基于matlab的北斗信号数据解析

基于matlab的北斗信号数据解析&#xff0c;多通道和单通道接收到的北斗信号数据&#xff0c;利用接收到的北斗数据&#xff08;.dat .txt文件&#xff09;&#xff0c;进行解析&#xff0c;得到初始伪距&#xff0c;平滑伪距&#xff0c;载波相位&#xff0c;并计算其标准差&am…

翱途开发平台新手上路-体验APP移动手机办公

O2OA(翱途)开发平台拥有配套的移动办公APP&#xff0c;支持IOS和安卓端&#xff0c;用户可在连接O2云之后&#xff0c;使用APP使用移动办公。移动办公APP开放源代码&#xff0c;不会产生任何费用。本篇主要简单讲述初如何完成服务器连接O2云&#xff0c;实现移动办公。 一、先决…

Barnes-Hut t-SNE:大规模数据的高效降维算法

在数据科学和分析中&#xff0c;理解高维数据集中的底层模式是至关重要的。t-SNE已成为高维数据可视化的有力工具。它通过将数据投射到一个较低维度的空间&#xff0c;提供了对数据结构的详细洞察。但是随着数据集的增长&#xff0c;标准的t-SNE算法在计算有些困难&#xff0c;…

什么是IoT?

什么是IoT&#xff1f; IoT&#xff0c;即物联网&#xff08;Internet of Things&#xff09;&#xff0c;是通过信息传感设备和互联网将各种物品连接起来&#xff0c;实现智能化的识别、定位、跟踪、监控和管理的网络系统。 以下是关于IOT的一些详细解释&#xff1a; 基本概…

JVM之本地方法栈和程序计数器和堆

本地方法栈 本地方法栈是为虚拟机执行本地方法时提供服务的 JNI&#xff1a;Java Native Interface&#xff0c;通过使用 Java 本地接口程序&#xff0c;可以确保代码在不同的平台上方便移植 不需要进行 GC&#xff0c;与虚拟机栈类似&#xff0c;也是线程私有的&#xff0c;…

OCP Java17 SE Developers 复习题13

答案 D, F. There is no such class within the Java API called ParallelStream, so options A and E are incorrect. The method defined in the Stream class to create a parallel stream from an existing stream is parallel(); therefore, option F is correct, and o…

高斯溅射融合之路(一)- webgl渲染3d gaussian splatting

大家好&#xff0c;我是山海鲸的技术负责人。之前已经写了一个GIS融合系列。其实CesiumJS的整合有相当的难度&#xff0c;同时也有很多方面的工作&#xff0c;很难在几篇文章内写完&#xff0c;整个山海鲸团队也是投入了接近两年的时间&#xff0c;才把周边整套工具链进行了完善…

Linux中inode号与日志分析

一.inode号 1.inode表结构 元信息&#xff1a;每个文件的属性信息&#xff0c;比如&#xff1a;文件的大小&#xff0c;时间&#xff0c;类型&#xff0c;权限等&#xff0c;称为文件的元数据(meta data 元信息 ) 元数据是存放在inode&#xff08;index node&#xff09;表中…

Spring Kafka—— KafkaListenerEndpointRegistry 隐式注册分析

由于我想在项目中实现基于 Spring kafka 动态连接 Kafka 服务&#xff0c;指定监听 Topic 并控制消费程序的启动和停止这样一个功能&#xff0c;所以就大概的了解了一下 Spring Kafka 的几个重要的类的概念&#xff0c;内容如下&#xff1a; ConsumerFactory 作用&#xff1a;…

Opencv_2_ 图像色彩空间转换

ColorInvert.h 内容如下&#xff1a; #pragma once #include <opencv.hpp> using namespace std; #include <opencv.hpp> using namespace cv; using namespace std; class ColorInvert{ public : void colorSpaceInvert(Mat&image); }; ColorInvert.cpp…

高效过滤器检漏方法选择指南及关键注意事项一览

在生物制药企业中&#xff0c;高效过滤器&#xff08;HEPA&#xff09;的检漏工作是确保洁净室能够达到并保持设计的洁净级别的关键步骤。这关系到产品的质量和安全&#xff0c;因此必须遵循相关法规标准和操作流程。 关于北京中邦兴业 北京中邦兴业科技有限公司是一家国家高新…

element中file-upload组件的提示‘按delete键可删除’,怎么去掉?

问题描述 element中file-upload组件会出现这种提示‘按delete键可删除’ 解决方案&#xff1a; 这是因为使用file-upload组件时自带的提示会盖住上传的文件名&#xff0c;修改一下自带的样式即可 ::v-deep .el-upload-list__item.is-success.focusing .el-icon-close-tip {d…