parent
f4c7f62707
commit
a659d861a6
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myValues">
|
||||
<value>
|
||||
<list size="7">
|
||||
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
||||
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
||||
<item index="2" class="java.lang.String" itemvalue="comment" />
|
||||
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
||||
<item index="4" class="java.lang.String" itemvalue="embed" />
|
||||
<item index="5" class="java.lang.String" itemvalue="script" />
|
||||
<item index="6" class="java.lang.String" itemvalue="String" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myCustomValuesEnabled" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="WebContextManager">
|
||||
<option name="state">
|
||||
<map>
|
||||
<entry key="file://$PROJECT_DIR$/src/main/webapp/Num2_remember_login/logout.jsp" value="file://$PROJECT_DIR$/src/main/webapp/Num2_remember_login" />
|
||||
<entry key="file://$PROJECT_DIR$/src/main/webapp/Num_library/index.html" value="file://$PROJECT_DIR$/src/main/webapp/Num_library" />
|
||||
<entry key="file://$PROJECT_DIR$/src/main/webapp/WEB-INF/studentList.jsp" value="file://$PROJECT_DIR$/src/main/webapp/WEB-INF" />
|
||||
<entry key="file://$PROJECT_DIR$/src/main/webapp/Web/register.html" value="file://$PROJECT_DIR$/src/main/webapp/Web" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>ZYG</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Servlet API依赖 -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.29</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
|
||||
<packaging>war</packaging>
|
||||
|
||||
</project>
|
@ -0,0 +1,30 @@
|
||||
package org.example.Goods;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JDBCUtil {
|
||||
private static final String URL = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC";
|
||||
private static final String USERNAME = "root";
|
||||
private static final String PASSWORD = "123456";
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DriverManager.getConnection(URL, USERNAME, PASSWORD);
|
||||
}
|
||||
|
||||
public static void closeConnection(Connection connection) {
|
||||
if (connection!= null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package org.example.Goods;
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryAllGoods")
|
||||
public class QueryAllGoodsServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
String sql = "SELECT * FROM goods";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int goodsId = resultSet.getInt("goods_id");
|
||||
String goodsName = resultSet.getString("goods_name");
|
||||
String specification = resultSet.getString("specification");
|
||||
String productionDate = resultSet.getString("production_date");
|
||||
int belongingWarehouseId = resultSet.getInt("belonging_warehouse_id");
|
||||
int supplierId = resultSet.getInt("supplier_id");
|
||||
jsonBuilder.append("{\"goods_id\":\"").append(goodsId).append("\",\"goods_name\":\"").append(goodsName).append("\",\"specification\":\"").append(specification).append("\",\"production_date\":\"").append(productionDate).append("\",\"belonging_warehouse_id\":\"").append(belongingWarehouseId).append("\",\"supplier_id\":\"").append(supplierId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package org.example.Goods;
|
||||
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryGoodsByName")
|
||||
public class QueryGoodsByName extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
String warehouseIdStr = request.getParameter("name");
|
||||
if (warehouseIdStr == null || warehouseIdStr.trim().isEmpty()) {
|
||||
out.print("[]");
|
||||
return;
|
||||
}
|
||||
int warehouseId;
|
||||
try {
|
||||
warehouseId = Integer.parseInt(warehouseIdStr);
|
||||
} catch (NumberFormatException e) {
|
||||
out.print("[]");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
String sql = "SELECT * FROM goods WHERE goods_id =?";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setInt(1, warehouseId);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int goodsId = resultSet.getInt("goods_id");
|
||||
String goodsName = resultSet.getString("goods_name");
|
||||
String specification = resultSet.getString("specification");
|
||||
String productionDate = resultSet.getString("production_date");
|
||||
int supplierId = resultSet.getInt("supplier_id");
|
||||
jsonBuilder.append("{\"goods_id\":\"").append(goodsId).append("\",\"goods_name\":\"").append(goodsName).append("\",\"specification\":\"").append(specification).append("\",\"production_date\":\"").append(productionDate).append("\",\"supplier_id\":\"").append(supplierId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.example.boundrecord;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JDBCUtil {
|
||||
private static final String URL = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC";
|
||||
private static final String USERNAME = "root";
|
||||
private static final String PASSWORD = "123456";
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DriverManager.getConnection(URL, USERNAME, PASSWORD);
|
||||
}
|
||||
|
||||
public static void closeConnection(Connection connection) {
|
||||
if (connection!= null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.example.boundrecord;
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryAllRecords")
|
||||
public class QueryAllRecordsServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
// 通过关联 goods 表,将 inboundrecord、outboundrecord 和 goods 三个表连接起来查询所有信息
|
||||
String sql = "SELECT ir.inbound_id, ir.goods_id, g.goods_name, ir.warehouse_id, ir.quantity_in, ir.inbound_date, orr.quantity_out, orr.outbound_date, g.specification, g.production_date, g.belonging_warehouse_id, g.supplier_id " +
|
||||
"FROM inboundrecord ir " +
|
||||
"LEFT JOIN goods g ON ir.goods_id = g.goods_id " +
|
||||
"LEFT JOIN outboundrecord orr ON ir.goods_id = orr.goods_id";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int inboundId = resultSet.getInt("inbound_id");
|
||||
int goodsId = resultSet.getInt("goods_id");
|
||||
String goodsName = resultSet.getString("goods_name");
|
||||
int warehouseId = resultSet.getInt("warehouse_id");
|
||||
int quantityIn = resultSet.getInt("quantity_in");
|
||||
String inboundDate = resultSet.getString("inbound_date");
|
||||
int quantityOut = resultSet.getInt("quantity_out");
|
||||
String outboundDate = resultSet.getString("outbound_date");
|
||||
String specification = resultSet.getString("specification");
|
||||
String productionDate = resultSet.getString("production_date");
|
||||
int belongingWarehouseId = resultSet.getInt("belonging_warehouse_id");
|
||||
int supplierId = resultSet.getInt("supplier_id");
|
||||
jsonBuilder.append("{\"inbound_id\":\"").append(inboundId).append("\",\"goods_id\":\"").append(goodsId).append("\",\"goods_name\":\"").append(goodsName).append("\",\"warehouse_id\":\"").append(warehouseId).append("\",\"quantity_in\":\"").append(quantityIn).append("\",\"inbound_date\":\"").append(inboundDate).append("\",\"quantity_out\":\"").append(quantityOut).append("\",\"outbound_date\":\"").append(outboundDate).append("\",\"specification\":\"").append(specification).append("\",\"production_date\":\"").append(productionDate).append("\",\"belonging_warehouse_id\":\"").append(belongingWarehouseId).append("\",\"supplier_id\":\"").append(supplierId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package org.example.boundrecord;
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryRecordsByGoodsId")
|
||||
public class QueryRecordsByGoodsIdServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
String goodsIdStr = request.getParameter("goods_id");
|
||||
if (goodsIdStr == null || goodsIdStr.trim().isEmpty()) {
|
||||
out.print("[]");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
// 通过商品id关联查询入库记录、出库记录以及商品表的相关信息
|
||||
String sql = "SELECT ir.inbound_id, ir.goods_id, g.goods_name, ir.warehouse_id, ir.quantity_in, ir.inbound_date, orr.quantity_out, orr.outbound_date, g.specification, g.production_date, g.belonging_warehouse_id, g.supplier_id " +
|
||||
"FROM inboundrecord ir " +
|
||||
"LEFT JOIN goods g ON ir.goods_id = g.goods_id " +
|
||||
"LEFT JOIN outboundrecord orr ON ir.goods_id = orr.goods_id " +
|
||||
"WHERE ir.goods_id =?";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setInt(1, Integer.parseInt(goodsIdStr));
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int inboundId = resultSet.getInt("inbound_id");
|
||||
int goodsId = resultSet.getInt("goods_id");
|
||||
String goodsName = resultSet.getString("goods_name");
|
||||
int warehouseId = resultSet.getInt("warehouse_id");
|
||||
int quantityIn = resultSet.getInt("quantity_in");
|
||||
String inboundDate = resultSet.getString("inbound_date");
|
||||
int quantityOut = resultSet.getInt("quantity_out");
|
||||
String outboundDate = resultSet.getString("outbound_date");
|
||||
String specification = resultSet.getString("specification");
|
||||
String productionDate = resultSet.getString("production_date");
|
||||
int belongingWarehouseId = resultSet.getInt("belonging_warehouse_id");
|
||||
int supplierId = resultSet.getInt("supplier_id");
|
||||
jsonBuilder.append("{\"inbound_id\":\"").append(inboundId).append("\",\"goods_id\":\"").append(goodsId).append("\",\"goods_name\":\"").append(goodsName).append("\",\"warehouse_id\":\"").append(warehouseId).append("\",\"quantity_in\":\"").append(quantityIn).append("\",\"inbound_date\":\"").append(inboundDate).append("\",\"quantity_out\":\"").append(quantityOut).append("\",\"outbound_date\":\"").append(outboundDate).append("\",\"specification\":\"").append(specification).append("\",\"production_date\":\"").append(productionDate).append("\",\"belonging_warehouse_id\":\"").append(belongingWarehouseId).append("\",\"supplier_id\":\"").append(supplierId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.example.employee;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JDBCUtil {
|
||||
private static final String URL = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC";
|
||||
private static final String USERNAME = "root";
|
||||
private static final String PASSWORD = "123456";
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return DriverManager.getConnection(URL, USERNAME, PASSWORD);
|
||||
}
|
||||
|
||||
public static void closeConnection(Connection connection) {
|
||||
if (connection!= null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package org.example.employee;
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryAllEmployees")
|
||||
public class QueryAllEmployeesServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
String sql = "SELECT * FROM employee";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int employeeId = resultSet.getInt("employee_id");
|
||||
String employeeName = resultSet.getString("employee_name");
|
||||
String department = resultSet.getString("department");
|
||||
String contactInfo = resultSet.getString("contact_info");
|
||||
int managedWarehouseId = resultSet.getInt("managed_warehouse_id");
|
||||
jsonBuilder.append("{\"employee_id\":\"").append(employeeId).append("\",\"employee_name\":\"").append(employeeName).append("\",\"department\":\"").append(department).append("\",\"contact_info\":\"").append(contactInfo).append("\",\"managed_warehouse_id\":\"").append(managedWarehouseId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package org.example.employee;
|
||||
|
||||
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.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@WebServlet("/queryEmployeeByName")
|
||||
public class QueryEmployeeByNameServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
String employeeName = request.getParameter("name");
|
||||
if (employeeName == null || employeeName.trim().isEmpty()) {
|
||||
out.print("[]");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
connection = JDBCUtil.getConnection();
|
||||
String sql = "SELECT * FROM employee WHERE employee_name LIKE?";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, "%" + employeeName + "%");
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
StringBuilder jsonBuilder = new StringBuilder("[");
|
||||
while (resultSet.next()) {
|
||||
int employeeId = resultSet.getInt("employee_id");
|
||||
String department = resultSet.getString("department");
|
||||
String contactInfo = resultSet.getString("contact_info");
|
||||
int managedWarehouseId = resultSet.getInt("managed_warehouse_id");
|
||||
String employeeNameDB = resultSet.getString("employee_name");
|
||||
jsonBuilder.append("{\"employee_id\":\"").append(employeeId).append("\",\"employee_name\":\"").append(employeeNameDB).append("\",\"department\":\"").append(department).append("\",\"contact_info\":\"").append(contactInfo).append("\",\"managed_warehouse_id\":\"").append(managedWarehouseId).append("\"},");
|
||||
}
|
||||
if (jsonBuilder.length() > 1) {
|
||||
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
|
||||
}
|
||||
jsonBuilder.append("]");
|
||||
out.print(jsonBuilder.toString());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
out.print("[]");
|
||||
} finally {
|
||||
try {
|
||||
if (resultSet!= null) {
|
||||
resultSet.close();
|
||||
}
|
||||
if (preparedStatement!= null) {
|
||||
preparedStatement.close();
|
||||
}
|
||||
if (connection!= null) {
|
||||
JDBCUtil.closeConnection(connection);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.example.login;
|
||||
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DBUtil {
|
||||
private static final String URL = "jdbc:mysql://localhost:3306/test"; // 修改为你的数据库地址
|
||||
private static final String USER = "root"; // 修改为你的数据库用户名
|
||||
private static final String PASSWORD = "123456"; // 修改为你的数据库密码
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() {
|
||||
try {
|
||||
return DriverManager.getConnection(URL, USER, PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("数据库连接失败!");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.example.login;
|
||||
|
||||
|
||||
|
||||
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.SQLException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
|
||||
@WebServlet("/register")
|
||||
public class RegisterServlet extends HttpServlet {
|
||||
private UserDAO userDAO = new UserDAO();
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
|
||||
boolean isRegistered = userDAO.register(username, password);
|
||||
if (isRegistered) {
|
||||
// 注册成功,设置提示信息
|
||||
request.setAttribute("success", "注册成功,请登录!");
|
||||
request.getRequestDispatcher("register.jsp").forward(request, response);
|
||||
} else {
|
||||
// 注册失败,设置错误信息
|
||||
request.setAttribute("error", "用户名已存在或注册失败!");
|
||||
request.getRequestDispatcher("register.jsp").forward(request, response);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.example.login;
|
||||
|
||||
|
||||
public class User {
|
||||
private int id;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
// Constructors
|
||||
public User() {}
|
||||
|
||||
public User(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package org.example.login;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class UserDAO {
|
||||
// 注册用户
|
||||
public boolean register(String username, String password) {
|
||||
String sql = "INSERT INTO user (username, password) VALUES (?, ?)";
|
||||
try (Connection conn = DBUtil.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, password);
|
||||
pstmt.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证登录
|
||||
public boolean login(String username, String password) {
|
||||
String sql = "SELECT * FROM user WHERE username = ? AND password = ?";
|
||||
try (Connection conn = DBUtil.getConnection();
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, password);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
return rs.next(); // 如果有结果,说明用户名密码匹配
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue