From b61452865bb23354a1ec33e349757f388e74f691 Mon Sep 17 00:00:00 2001
From: Gui ze yu <2970307356@qq.com>
Date: Tue, 30 May 2023 22:11:05 +0800
Subject: [PATCH 01/11] study
---
.../2023-05-29\344\275\234\344\270\232.md" | 378 ++++++++++++++++++
1 file changed, 378 insertions(+)
create mode 100644 "09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
diff --git "a/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md" "b/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
new file mode 100644
index 0000000..29f2409
--- /dev/null
+++ "b/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
@@ -0,0 +1,378 @@
+```mysql
+create database band_db charset=utf8;
+use band_db;
+create table band(
+ id int primary key auto_increment,
+name varchar(30),
+enterprisename varchar(30),
+introduction varchar(50),
+state int default 1 comment'状态:0禁用1启用'
+)comment'品牌';
+insert into band
+values
+(1,'三只松鼠','三只松鼠','三只松鼠,好吃不上火',1),
+(2,'优衣库','优衣库','优衣库,服适人生',0),
+(3,'小米','小米科技有限公司','为发烧而生',1);
+```
+
+```java
+package com.dao;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class Dao {
+ private Connection conn;
+ private String driver = "com.mysql.jdbc.Driver";
+ private String url ="jdbc:mysql://localhost:3306/band_db?useSSL=false&useUnicode=true&charsetEnding=utf8";
+ private String user="root";
+ private String password="root";
+
+ public Dao() {
+ try {
+ Class.forName(driver);
+ System.out.println("驱动加载成功");
+ } catch (ClassNotFoundException e) {
+ System.out.println("驱动加载失败!");
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Connection getConn() {
+ try {
+ conn = DriverManager.getConnection(url,user,password);
+ System.out.println("数据库连接成功");
+ } catch (SQLException e) {
+ System.out.println("数据库连接失败!");
+ throw new RuntimeException(e);
+ }
+ return conn;
+ }
+
+ public void setConn(Connection conn) {
+ this.conn = conn;
+ }
+}
+
+```
+
+```java
+package com.band;
+
+public class Band {
+ //序号
+ private int id;
+ //品牌名称
+ private String name;
+ //企业名称
+ private String enterprisename;
+ //品牌介绍
+ private String interoduction;
+ //状态
+ private String state;
+ public Band() {
+ }
+
+ public Band(int id, String name, String enterprisename, String interoduction, String state) {
+ this.id = id;
+ this.name = name;
+ this.enterprisename = enterprisename;
+ this.interoduction = interoduction;
+ this.state = state;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEnterprisename() {
+ return enterprisename;
+ }
+
+ public void setEnterprisename(String enterprisename) {
+ this.enterprisename = enterprisename;
+ }
+
+ public String getInteroduction() {
+ return interoduction;
+ }
+
+ public void setInteroduction(String interoduction) {
+ this.interoduction = interoduction;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+}
+```
+
+```java
+package com.servlet;
+
+import com.band.Band;
+import com.dao.Dao;
+
+
+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 java.io.IOException;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+@WebServlet(name = "Servlet", value = "/Servlet")
+public class Servlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html;charset=utf-8");
+ request.setCharacterEncoding("utf-8");
+ System.out.println("你调用了get方法");
+ String mess = request.getParameter("submit");
+ if (mess.endsWith("查询")) {
+ Find(request, response);
+ }
+ if (mess.endsWith("添加")) {
+ Add(request, response);
+ }
+ if(mess.endsWith("修改")){
+ Update(request,response);
+ }
+ }
+
+ //查询
+ public void Find(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String id = request.getParameter("id");
+ String name = request.getParameter("name");
+ String enterprisename = request.getParameter("enterprisename");
+ String introduction = request.getParameter("introduction");
+ String state = request.getParameter("state");
+ Band band = new Band();
+ Dao dao = new Dao();
+ String sql = "select * from band where id=? and name=? and enterprisename=? and introduction=? and state=?";
+ try {
+ PreparedStatement pre = dao.getConn().prepareStatement(sql);
+ pre.setString(1, id);
+ pre.setString(2, name);
+ pre.setString(3, enterprisename);
+ pre.setString(4,introduction);
+ pre.setString(5,state);
+ ResultSet res = pre.executeQuery();
+ while (res.next()) {
+ id = res.getString("id");
+ name = res.getString("name");
+ enterprisename = res.getString("enterprisename");
+ introduction = res.getString("introduction");
+ state = res.getString("state");
+ band.setId(Integer.parseInt(id));
+ band.setName(name);
+ band.setEnterprisename(enterprisename);
+ band.setInteroduction(introduction);
+ band.setState("state");
+ response.getWriter().write(String.valueOf(band));
+ }
+ res.close();
+ } catch (SQLException e) {
+ }
+ }
+
+ //添加
+ public void Add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String id = request.getParameter("id");
+ String name = request.getParameter("name");
+ String enterprisename = request.getParameter("enterprisename");
+ String introduction = request.getParameter("introduction");
+ String state = request.getParameter("state");
+ Band band = new Band();
+ Dao dao = new Dao();
+ String sql = "insert into band values(?,?,?,?,?)";
+ try {
+ PreparedStatement pre = dao.getConn().prepareStatement(sql);
+ pre.setString(1, id);
+ pre.setString(2, name);
+ pre.setString(3, enterprisename);
+ pre.setString(4,introduction);
+ pre.setString(5,state);
+ int i = pre.executeUpdate();
+ if (i > 0) {
+ band.setId(Integer.parseInt(id));
+ band.setName(name);
+ band.setEnterprisename(enterprisename);
+ band.setInteroduction(introduction);
+ band.setState(state);
+ System.out.println(band);
+ response.getWriter().write("添加成功");
+ } else response.getWriter().write("添加失败");
+ pre.close();
+ } catch (SQLException e) {
+ }
+ }
+ //修改
+public void Update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String id = request.getParameter("id");
+ String name = request.getParameter("name");
+ String enterprisename = request.getParameter("enterprisename");
+ String introduction = request.getParameter("introduction");
+ String state = request.getParameter("state");
+ Band band = new Band();
+ Dao dao = new Dao();
+ String sql = "update band set name=?,enterprisename=?,introduction=?,state=? where id=?";
+ try {
+ PreparedStatement pre = dao.getConn().prepareStatement(sql);
+ pre.setString(1, name);
+ pre.setString(2,enterprisename);
+ pre.setString(3,introduction);
+ pre.setString(4,state);
+ pre.setString(5,id);
+ int i = pre.executeUpdate();
+ if (i > 0) {
+ band.setId(Integer.parseInt(id));
+ band.setName(name);
+ band.setEnterprisename(enterprisename);
+ band.setInteroduction(introduction);
+ band.setState(state);
+ response.getWriter().write("修改成功");
+ } else response.getWriter().write("修改失败");
+ pre.close();
+ } catch (SQLException e) {
+ }
+}
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doGet(request, response);
+ }
+}
+
+```
+
+```java
+<%@ page import="com.dao.Dao" %>
+<%@ page import="java.sql.PreparedStatement" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="java.sql.SQLException" %>
+<%@ page import="com.band.Band" %>
+<%@ page import="javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec" %><%--
+ Created by IntelliJ IDEA.
+ User: MAC
+ Date: 2023/5/27
+ Time: 18:18
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 主页
+
+
+
+
+ 序号 | 品牌名称 | | 企业名称 | 品牌名称 | 状态 | 操作 |
+ <%
+ Band band = new Band();
+ Dao dao = new Dao();
+ String sql = "select * from band;";
+ try {
+ PreparedStatement pre = dao.getConn().prepareStatement(sql);
+ ResultSet res = pre.executeQuery();
+ while (true) {
+ try {
+ if (!res.next()) break;
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ String id = res.getString("id");
+ String name = res.getString("name");
+ String enterprisename = res.getString("enterprisename");
+ String introduction = res.getString("introduction");
+ String state = res.getString("state");
+ band.setId(Integer.parseInt(id));
+ band.setName(name);
+ band.setEnterprisename(enterprisename);
+ band.setInteroduction(introduction);
+ band.setState("state");
+ %>
+
+ <%=band.getId()%> | <%=band.getName()%> | <%=band.getEnterprisename()%> |
+ <%=band.getInteroduction()%> | <%=band.getState()%> |
+ 修改 删除 |
+
+ <%res.close();} catch (SQLException e) {}%>
+
+
+
+
+```
+
+```java
+<%@ page import="com.student.Student" %>
+<%@ page import="com.dao.Dao" %>
+<%@ page import="java.sql.PreparedStatement" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="java.sql.SQLException" %>
+<%@ page import="com.band.Band" %><%--
+ Created by IntelliJ IDEA.
+ User: MAC
+ Date: 2023/5/27
+ Time: 22:48
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 删除学生
+
+
+<%String id = request.getParameter("id");
+ Band band = new Band();
+ Dao dao = new Dao();
+ String sql = "delete from band where id=?";
+ try {
+ PreparedStatement pre = dao.getConn().prepareStatement(sql);
+ pre.setString(1, id);
+ int i = pre.executeUpdate();
+ if (i > 0) {
+ response.getWriter().write("");
+ response.sendRedirect("index.jsp");
+ request.setAttribute("band",band);
+ } else response.getWriter().write("删除失败");
+ pre.close();
+ } catch (SQLException e) {
+ }%>
+<% band = (Band) request.getAttribute("band");%>
+
+
+
+
+```
+
--
Gitee
From f9b125ac7c854e6db7dd1d4ec5ca3a52d257b275 Mon Sep 17 00:00:00 2001
From: Gui ze yu <2970307356@qq.com>
Date: Tue, 30 May 2023 22:24:00 +0800
Subject: [PATCH 02/11] studu
---
.../2023-05-29\344\275\234\344\270\232.md" | 31 +++++++++----------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git "a/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md" "b/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
index 29f2409..e733215 100644
--- "a/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
+++ "b/09 \346\241\202\346\263\275\347\205\234/2023-05-29\344\275\234\344\270\232.md"
@@ -284,34 +284,27 @@ public void Update(HttpServletRequest request, HttpServletResponse response) thr
主页
- 序号 | 品牌名称 | | 企业名称 | 品牌名称 | 状态 | 操作 |
+ 序号 | 品牌名称 | 企业名称 | 品牌名称 | 状态 | 操作 |
<%
Band band = new Band();
Dao dao = new Dao();
String sql = "select * from band;";
- try {
PreparedStatement pre = dao.getConn().prepareStatement(sql);
ResultSet res = pre.executeQuery();
- while (true) {
- try {
- if (!res.next()) break;
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
- String id = res.getString("id");
- String name = res.getString("name");
- String enterprisename = res.getString("enterprisename");
+ while (res.next()) {
+ String id = res.getString("id");
+ String name = res.getString("name");
+ String enterprisename = res.getString("enterprisename");
String introduction = res.getString("introduction");
- String state = res.getString("state");
+ int state = res.getInt("state");
band.setId(Integer.parseInt(id));
band.setName(name);
band.setEnterprisename(enterprisename);
@@ -323,7 +316,13 @@ public void Update(HttpServletRequest request, HttpServletResponse response) thr
<%=band.getInteroduction()%> | <%=band.getState()%> |
修改 删除 |
- <%res.close();} catch (SQLException e) {}%>
+ <%}
+ try {
+ res.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ %>