后端代码
This commit is contained in:
parent
285a804d3a
commit
ad30563a97
|
@ -0,0 +1,8 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="vueDemo" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="vueDemo" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.sql.Connection,prepareStatement" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spring-milestones" />
|
||||
<option name="name" value="Spring Milestones" />
|
||||
<option name="url" value="https://repo.spring.io/milestone" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spring-snapshots" />
|
||||
<option name="name" value="Spring Snapshots" />
|
||||
<option name="url" value="https://repo.spring.io/snapshot" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (2)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (3)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (4)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (5)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (6)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (7)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.0.33 (8)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.0.33.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</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,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
|
@ -0,0 +1,95 @@
|
|||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.16-SNAPSHOT</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>vueDemo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>vueDemo</name>
|
||||
<description>vueDemo</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--jsonwebtoken 生成token的库 -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.8.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package com.example.vuedemo;
|
||||
|
||||
public class Product {
|
||||
private String state;
|
||||
private String approver;
|
||||
private String result;
|
||||
//补全getset方法
|
||||
public String getState() {
|
||||
return state;
|
||||
|
||||
}
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
public String getApprover() {
|
||||
return approver;
|
||||
|
||||
}
|
||||
public void setApprover(String approver) {
|
||||
this.approver = approver;
|
||||
}
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.example.vuedemo.Token;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//入口拦截,设置哪些接口需要拦截或不拦截(保护后端接口 防止未经授权的访问)
|
||||
@Configuration
|
||||
public class IntercepterConfig implements WebMvcConfigurer {
|
||||
private final TokenInterceptor tokenInterceptor;
|
||||
|
||||
// 构造方法
|
||||
public IntercepterConfig(TokenInterceptor tokenInterceptor) {
|
||||
this.tokenInterceptor = tokenInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//excludePathPatterns用来配置不需要拦截的路径
|
||||
List<String> excludePath = new ArrayList<>();//List用来保存所有不需要拦截的路径
|
||||
excludePath.add("/register"); //注册
|
||||
excludePath.add("/login"); //登录
|
||||
excludePath.add("/product");
|
||||
excludePath.add("/addProduct");
|
||||
excludePath.add("/deleteProduct");
|
||||
|
||||
|
||||
|
||||
registry.addInterceptor(tokenInterceptor)//添加名为tokenInterceptor的拦截器
|
||||
.addPathPatterns("/**") //指定拦截所有路径
|
||||
.excludePathPatterns(excludePath);//排除不需要拦截的路径
|
||||
WebMvcConfigurer.super.addInterceptors(registry);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.example.vuedemo.Token;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
public class TokenGenerate {
|
||||
|
||||
private static final long EXPIRE_TIME= 15*60*1000;
|
||||
private static final String TOKEN_SECRET="tokenqkj"; //密钥盐
|
||||
public String generateToken(String username){
|
||||
String token = null;
|
||||
try{
|
||||
Date expiresAt = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
||||
token = JWT.create()
|
||||
.withIssuer("auth0")
|
||||
.withClaim("username", username)
|
||||
.withExpiresAt(expiresAt)
|
||||
.sign(Algorithm.HMAC256(TOKEN_SECRET));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
/**
|
||||
* 签名验证
|
||||
*/
|
||||
public static boolean verify(String token){
|
||||
System.out.println("执行了token验证代码");
|
||||
|
||||
try {
|
||||
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(TOKEN_SECRET)).withIssuer("auth0").build();
|
||||
DecodedJWT jwt = verifier.verify(token);
|
||||
System.out.println("认证通过:");
|
||||
System.out.println("issuer: " + jwt.getIssuer());
|
||||
System.out.println("username: " + jwt.getClaim("username").asString());
|
||||
System.out.println("过期时间: " + jwt.getExpiresAt());
|
||||
return true;
|
||||
} catch (Exception e){
|
||||
System.out.println("没通过");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.example.vuedemo.Token;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
//token拦截器,对拦截下的接口检查其的token是否符合只有
|
||||
// 在提供一个有效的token时才能通过验证,否则给出认证失败的响应。
|
||||
@Component
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception{
|
||||
//Axios 发起跨域请求前,浏览器也会首先发起 OPTIONS 预检请求。检查服务器是否允许跨域访问。
|
||||
if(request.getMethod().equals("OPTIONS")){
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
System.out.println("允许跨域访问");
|
||||
return true;
|
||||
}
|
||||
|
||||
response.setCharacterEncoding("utf-8");
|
||||
String token = request.getHeader("token");
|
||||
if(token != null){
|
||||
boolean result = TokenGenerate.verify(token);
|
||||
if(result){
|
||||
System.out.println("通过拦截器");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
PrintWriter out = null;
|
||||
response.getWriter().write("认证失败,错误码:50000");
|
||||
return false;//原为false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.example.vuedemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class VueDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VueDemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.example.vuedemo;
|
||||
|
||||
import com.example.vuedemo.Token.TokenGenerate;
|
||||
import jdk.nashorn.internal.parser.Token;
|
||||
import mysql.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin //加上CrossOrigin可解决跨域问题
|
||||
public class vueControll {
|
||||
String token;
|
||||
@RequestMapping("/login")
|
||||
public String tologin(@RequestParam("username") String username,@RequestParam("password") String password) throws SQLException {
|
||||
ResultSet resultRegister = CheckRegister.MyAccount(username);
|
||||
if(resultRegister.next()) {
|
||||
if(username.equals(resultRegister.getString("username"))&&password.equals(resultRegister.getString("password"))) {
|
||||
token = new TokenGenerate().generateToken(username);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
@RequestMapping("/register")
|
||||
public String toRegister(@RequestParam("username") String username,@RequestParam("password") String password) throws SQLException {
|
||||
ResultSet resultRegister = CheckRegister.MyAccount(username);
|
||||
//还没有注册过
|
||||
if(resultRegister.next()){
|
||||
resultRegister.getString("username").equals(username);
|
||||
return "false";
|
||||
}
|
||||
AddRegister.add(username, password);
|
||||
return "true";
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/product")
|
||||
public ResponseEntity<List<Product>> getProduct(@RequestBody Product product) throws SQLException {
|
||||
//提取数据到List
|
||||
ResultSet resultProduct = CheckProduct.MyAccount();
|
||||
// 封装结果集到Product列表
|
||||
List<Product> productList = new ArrayList<>();
|
||||
while (resultProduct.next()) {
|
||||
Product p = new Product();
|
||||
p.setState(resultProduct.getString("state"));
|
||||
p.setApprover(resultProduct.getString("approver"));
|
||||
p.setResult(resultProduct.getString("result"));
|
||||
productList.add(p);
|
||||
}
|
||||
return ResponseEntity.ok(productList);
|
||||
}
|
||||
|
||||
@PostMapping("/addProduct")
|
||||
public ResponseEntity<List<Product>> addProduct(@RequestBody Product product) throws SQLException {
|
||||
//存入数据库
|
||||
AddProduct.add(product.getState(),product.getApprover(),product.getResult());
|
||||
//进行整体数据传输
|
||||
ResultSet resultProduct = CheckProduct.MyAccount();
|
||||
// 封装结果集到Product列表
|
||||
List<Product> productList = new ArrayList<>();
|
||||
while (resultProduct.next()) {
|
||||
Product p = new Product();
|
||||
p.setState(resultProduct.getString("state"));
|
||||
p.setApprover(resultProduct.getString("approver"));
|
||||
p.setResult(resultProduct.getString("result"));
|
||||
productList.add(p);
|
||||
}
|
||||
return ResponseEntity.ok(productList);
|
||||
}
|
||||
|
||||
@PostMapping("/deleteProduct")
|
||||
public ResponseEntity<List<Product>> deleteProduct(@RequestBody Product product) throws Exception {
|
||||
DeleteProduct.delete(product.getState(), product.getApprover(), product.getResult());
|
||||
//进行整体数据传输
|
||||
ResultSet resultProduct = CheckProduct.MyAccount();
|
||||
// 封装结果集到Product列表
|
||||
List<Product> productList = new ArrayList<>();
|
||||
while (resultProduct.next()) {
|
||||
Product p = new Product();
|
||||
p.setState(resultProduct.getString("state"));
|
||||
p.setApprover(resultProduct.getString("approver"));
|
||||
p.setResult(resultProduct.getString("result"));
|
||||
productList.add(p);
|
||||
}
|
||||
return ResponseEntity.ok(productList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AddProduct {
|
||||
public static void add(String state,String approver,String result) throws SQLException {
|
||||
String sql ="INSERT INTO product(state,approver,result) VALUES (?,?,?) ";
|
||||
PreparedStatement preparedStatement;
|
||||
preparedStatement = JDBC.getConnection().prepareStatement(sql);
|
||||
preparedStatement.setString(1,state);
|
||||
preparedStatement.setString(2,approver);
|
||||
preparedStatement.setString(3,result);
|
||||
|
||||
|
||||
preparedStatement.executeLargeUpdate();//插入数据
|
||||
preparedStatement.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AddRegister {
|
||||
public static void add(String username,String password) throws SQLException {
|
||||
String sql ="INSERT INTO register(username,password) VALUES (?,?) ";
|
||||
PreparedStatement preparedStatement;
|
||||
preparedStatement = JDBC.getConnection().prepareStatement(sql);
|
||||
preparedStatement.setString(1,username);
|
||||
preparedStatement.setString(2,password);
|
||||
|
||||
|
||||
preparedStatement.executeLargeUpdate();//插入数据
|
||||
preparedStatement.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class CheckProduct {
|
||||
public static ResultSet MyAccount() throws SQLException {
|
||||
String sql = "SELECT* FROM product";
|
||||
ResultSet resultSet;
|
||||
PreparedStatement preparedStatement;
|
||||
preparedStatement = JDBC.getConnection().prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();//查询数据
|
||||
return resultSet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class CheckRegister {
|
||||
public static ResultSet MyAccount(String username) throws SQLException {
|
||||
String sql = "SELECT* FROM register where username = ?";
|
||||
ResultSet resultSet;
|
||||
PreparedStatement preparedStatement;
|
||||
preparedStatement = JDBC.getConnection().prepareStatement(sql);
|
||||
preparedStatement.setString(1, username);
|
||||
resultSet = preparedStatement.executeQuery();//查询数据
|
||||
return resultSet;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class DeleteProduct {
|
||||
public static void delete(String state,String approver,String result ) throws Exception{
|
||||
String sql = "delete from product where state=? AND approver = ? AND result = ?";
|
||||
PreparedStatement preparedStatement;
|
||||
preparedStatement = JDBC.getConnection().prepareStatement(sql);
|
||||
|
||||
preparedStatement.setString(1, state);
|
||||
preparedStatement.setString(2, approver);
|
||||
preparedStatement.setString(3, result);
|
||||
|
||||
preparedStatement.executeUpdate();//插入数据
|
||||
preparedStatement.close();
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class JDBC {
|
||||
// static {
|
||||
// try {
|
||||
// Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
private static String url="jdbc:mysql://127.0.0.1:3306/vue";
|
||||
private static String username="root";
|
||||
private static String password="123456";
|
||||
|
||||
public static Connection getConnection() {
|
||||
Connection connection;
|
||||
try {
|
||||
connection= DriverManager.getConnection(url,username,password);
|
||||
return connection;
|
||||
} catch (SQLException e) {
|
||||
System.out.println("数据库未连接");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
server.port=8081
|
||||
|
||||
spring.datasource.url="jdbc:mysql://127.0.0.1:3306/vue"
|
||||
spring.datasource.username="root"
|
||||
spring.datasource.password="123456"
|
|
@ -0,0 +1,5 @@
|
|||
server.port=8081
|
||||
|
||||
spring.datasource.url="jdbc:mysql://127.0.0.1:3306/vue"
|
||||
spring.datasource.username="root"
|
||||
spring.datasource.password="123456"
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
artifactId=vueDemo
|
||||
groupId=com.example
|
||||
version=0.0.1-SNAPSHOT
|
|
@ -0,0 +1,12 @@
|
|||
mysql\AddProduct.class
|
||||
mysql\AddRegister.class
|
||||
com\example\vuedemo\Token\IntercepterConfig.class
|
||||
mysql\CheckRegister.class
|
||||
mysql\DeleteProduct.class
|
||||
mysql\CheckProduct.class
|
||||
com\example\vuedemo\Product.class
|
||||
com\example\vuedemo\Token\TokenGenerate.class
|
||||
com\example\vuedemo\vueControll.class
|
||||
mysql\JDBC.class
|
||||
com\example\vuedemo\Token\TokenInterceptor.class
|
||||
com\example\vuedemo\VueDemoApplication.class
|
|
@ -0,0 +1,12 @@
|
|||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\VueDemoApplication.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\Token\IntercepterConfig.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\AddRegister.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\JDBC.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\Token\TokenInterceptor.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\AddProduct.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\CheckRegister.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\Token\TokenGenerate.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\CheckProduct.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\Product.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\com\example\vuedemo\vueControll.java
|
||||
C:\Users\Xubx\IdeaProjects\vueDemo\src\main\java\mysql\DeleteProduct.java
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue