parent
d817b03bed
commit
51b7169a18
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<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="demo" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="demo" 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,20 @@
|
||||
<?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="https://repo.maven.apache.org/maven2" />
|
||||
</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="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,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" project-jdk-name="17" 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,19 @@
|
||||
# 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
|
||||
#
|
||||
# http://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.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
|
@ -0,0 +1,109 @@
|
||||
<?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>3.4.2</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>demo</name>
|
||||
<description>demo</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- Apache Commons FileUpload -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>commons-fileupload</groupId>-->
|
||||
<!-- <artifactId>commons-fileupload</artifactId>-->
|
||||
<!-- <version>1.4</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web-services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter-test</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>4.4.0</version>
|
||||
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Demo4Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Demo4Application.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.example.demo.config;
|
||||
|
||||
import com.example.demo.pojo.Result;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
//重点
|
||||
@WebFilter({"/user/*","/api","/upload","/borrow"})
|
||||
public class MyFilter implements Filter{
|
||||
|
||||
List<String> exclude;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
System.out.println("初始化MyFilter==========================");
|
||||
exclude = new ArrayList<>();
|
||||
exclude.add("/user/login");
|
||||
exclude.add("/user/register");
|
||||
}
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
String requestURI = request.getRequestURI();
|
||||
if (exclude.contains(requestURI) ||
|
||||
requestURI.endsWith(".html") ||
|
||||
requestURI.endsWith(".js") ||
|
||||
requestURI.endsWith(".css") ||
|
||||
requestURI.endsWith(".png") ||
|
||||
requestURI.endsWith(".jpg") ||
|
||||
requestURI.endsWith(".jpeg")
|
||||
) {
|
||||
// 在排除列表中,继续过滤链
|
||||
filterChain.doFilter(servletRequest,servletResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean loginflag = request.getSession().getAttribute("username") != null;
|
||||
if(loginflag){
|
||||
//登陆成功
|
||||
//这就代码就是放行
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}else{
|
||||
//登陆失败,打回请求
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
response.getWriter().write(mapper.writeValueAsString(Result.error("未登录")));
|
||||
}
|
||||
|
||||
System.out.println("filter==========================");
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
System.out.println("销毁filter==========================");
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import com.example.demo.pojo.Article;
|
||||
import com.example.demo.pojo.Result;
|
||||
import com.example.demo.service.ArticleService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api")
|
||||
public class ArticleController {
|
||||
|
||||
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public Result<Article> addarticle(@RequestBody Article article) throws JsonProcessingException {
|
||||
System.out.println("Received article: " + article); // 添加此行以调试
|
||||
articleService.addarticle(article);
|
||||
return Result.success(article);
|
||||
}
|
||||
|
||||
@GetMapping("/select")
|
||||
public Result selectarticle(HttpServletRequest request) {
|
||||
List<Article> articles = articleService.selectarticle();
|
||||
System.out.println(request.getRequestURL());
|
||||
return Result.success(articles);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public Result deleteArticle(@PathVariable Long id) {
|
||||
boolean deleted = articleService.deletearticle(id);
|
||||
if (deleted) {
|
||||
return Result.success();
|
||||
} else {
|
||||
return Result.error("删除失败!");
|
||||
}
|
||||
}
|
||||
|
||||
//根据书籍名字搜索单个书籍信息
|
||||
@GetMapping("/selectone")
|
||||
public Result<Article> selectone(String title){
|
||||
Article article= articleService.selectonearticle(title);
|
||||
return Result.success(article);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import com.example.demo.pojo.Borrow;
|
||||
import com.example.demo.pojo.Result;
|
||||
import com.example.demo.service.BorrowService;
|
||||
|
||||
import com.example.demo.service.UserService;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/borrow")
|
||||
public class BorrowController {
|
||||
@Autowired
|
||||
private BorrowService borrowService;
|
||||
|
||||
|
||||
|
||||
//租借书
|
||||
@PostMapping("/borrowbook")
|
||||
public Result borrowbook(String title, HttpSession session){
|
||||
Borrow borrow=new Borrow();
|
||||
borrow.setTitle(title);
|
||||
borrow.setBorrower((String) session.getAttribute("username"));
|
||||
borrowService.borrow(borrow);
|
||||
return Result.success(borrow);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import com.example.demo.mapper.UserMapper;
|
||||
import com.example.demo.pojo.Result;
|
||||
import com.example.demo.pojo.User;
|
||||
import com.example.demo.pojo.info;
|
||||
import com.example.demo.service.UserService;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8877")
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
//获取用户登陆信息
|
||||
@GetMapping("/getinfo")
|
||||
public ResponseEntity<?> getInfo(HttpSession session) {
|
||||
String username = (String) session.getAttribute("username");
|
||||
if (username == null) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("{\"error\": \"Username not found in session\"}");
|
||||
}
|
||||
info info = userService.getinfo(username);
|
||||
System.out.println(info);
|
||||
if (info == null) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"error\": \"User information not found for username: " + username + "\"}");
|
||||
}
|
||||
return ResponseEntity.ok(info);
|
||||
}
|
||||
|
||||
|
||||
//注册
|
||||
@PostMapping("/register")
|
||||
public Result register(String username, String password) {
|
||||
User u = userService.findByUserName(username);
|
||||
if (u == null) {
|
||||
userService.register(username, password);
|
||||
return Result.success();
|
||||
} else {
|
||||
return Result.error("该用户名已被注册");
|
||||
}
|
||||
}
|
||||
//登陆
|
||||
@PostMapping("/login")
|
||||
public Result login(String username, String password,HttpSession session) {
|
||||
User u = userService.findByUserName(username);
|
||||
if (u != null) {
|
||||
userService.login(username, password);
|
||||
String pass=userMapper.login(username);
|
||||
|
||||
if (password.equals(pass)) {
|
||||
session.setAttribute("username",username);
|
||||
System.out.println("登陆成功!");
|
||||
return Result.success("登陆成功!");
|
||||
} else {
|
||||
//这里已经处理好了
|
||||
return Result.error("账号或密码错误!");
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//充值金额
|
||||
@PostMapping("/recharge")
|
||||
public Result recharge(float money,HttpSession session){
|
||||
userService.recharge(money, (String) session.getAttribute("username"));
|
||||
return Result.success("成功充值:"+money+"元");
|
||||
}
|
||||
|
||||
@GetMapping("/findmoney")
|
||||
public Result findmoney(HttpSession session){
|
||||
float money=userService.findmoney(session.getAttribute("username"));
|
||||
return Result.success("余额为:"+money+"元");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.demo.mapper;
|
||||
|
||||
|
||||
import com.example.demo.pojo.Article;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ArticleMapper {
|
||||
|
||||
@Insert("INSERT INTO article (title, content, url, state)\n" +
|
||||
"VALUES \n" +
|
||||
"(#{title}, #{content}, #{url},#{state})")
|
||||
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
|
||||
Long addarticle(Article article);
|
||||
|
||||
|
||||
//查询所有书籍所有信息
|
||||
@Select("SELECT * FROM article")
|
||||
List<Article> selectarticle();
|
||||
|
||||
//管理员删除书籍
|
||||
@Delete("DELETE FROM article WHERE id = #{id}")
|
||||
Integer deleteArticle(Long id);
|
||||
|
||||
@Select("SELECT * from article where title=#{title}")
|
||||
Article selectonearticle(String title);
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.example.demo.mapper;
|
||||
|
||||
import com.example.demo.pojo.Borrow;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BorrowMapper {
|
||||
@Insert("INSERT INTO borrow (title, borrower, borrow_time)\n" +
|
||||
"VALUES \n" +
|
||||
"(#{title}, #{borrower}, now())")
|
||||
void borrowrecord(Borrow borrow);
|
||||
|
||||
|
||||
@Insert("INSERT INTO borrow (title, borrower, return_time)\n" +
|
||||
"VALUES \n" +
|
||||
"(#{title}, #{borrower}, now())")
|
||||
void returnrecord(Borrow borrow);
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.example.demo.mapper;
|
||||
|
||||
|
||||
import com.example.demo.pojo.User;
|
||||
import com.example.demo.pojo.info;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
@Select("select * from user where username=#{username}")
|
||||
User findByUserName(String username);
|
||||
|
||||
@Insert("insert into user(username,password,vip,create_time,update_time,admin,balance)" +
|
||||
" values(#{username},#{password},#{vip},now(),now(),#{admin},#{balance})")
|
||||
void add(String username,String password,int vip,int admin,float balance);
|
||||
|
||||
@Select("SELECT password FROM user WHERE username=#{username}")
|
||||
String login(String username);
|
||||
|
||||
|
||||
@Select("select username,pic from user where username=#{username}")
|
||||
info getinfo( String username);
|
||||
|
||||
|
||||
//充钱
|
||||
@Update("UPDATE user\n" +
|
||||
"SET balance=balance+#{money1}\n" +
|
||||
"WHERE username=#{username};")
|
||||
void recharge(float money1,String username);
|
||||
|
||||
@Select("select balance from user where username=#{username}")
|
||||
float findbalance(Object username);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.example.demo.pojo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Article {
|
||||
private int id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String url;
|
||||
private String state;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.example.demo.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Borrow {
|
||||
private String title;
|
||||
private String borrower;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.demo.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String vip;
|
||||
private String userPic;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer admin;
|
||||
private float balance;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.example.demo.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class info {
|
||||
private String username;
|
||||
private String pic;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import com.example.demo.pojo.Article;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ArticleService {
|
||||
Long addarticle(Article article);
|
||||
|
||||
List<Article> selectarticle();
|
||||
|
||||
boolean deletearticle(Long id);
|
||||
|
||||
Article selectonearticle(String title);
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import com.example.demo.mapper.BorrowMapper;
|
||||
import com.example.demo.pojo.Borrow;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public interface BorrowService {
|
||||
|
||||
|
||||
void borrow(Borrow borrow);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import com.example.demo.pojo.User;
|
||||
import com.example.demo.pojo.info;
|
||||
|
||||
public interface UserService {
|
||||
User findByUserName(String username);
|
||||
|
||||
void register(String username, String password);
|
||||
|
||||
void login(String username, String password);
|
||||
|
||||
info getinfo(String username);
|
||||
|
||||
void recharge(float money, String username);
|
||||
|
||||
float findmoney(Object username);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.example.demo.service.impl;
|
||||
|
||||
import com.example.demo.mapper.ArticleMapper;
|
||||
import com.example.demo.pojo.Article;
|
||||
import com.example.demo.service.ArticleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Override
|
||||
public Long addarticle(Article article) {
|
||||
|
||||
return articleMapper.addarticle(article);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> selectarticle() {
|
||||
return articleMapper.selectarticle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletearticle(Long id) {
|
||||
final Integer integer = articleMapper.deleteArticle((long) Math.toIntExact(id));
|
||||
return integer == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Article selectonearticle(String title) {
|
||||
return articleMapper.selectonearticle(title);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.example.demo.service.impl;
|
||||
|
||||
|
||||
import com.example.demo.mapper.BorrowMapper;
|
||||
import com.example.demo.pojo.Article;
|
||||
import com.example.demo.pojo.Borrow;
|
||||
import com.example.demo.service.BorrowService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BorrowServiceImpl implements BorrowService {
|
||||
|
||||
@Autowired
|
||||
BorrowMapper borrowMapper ;
|
||||
|
||||
@Override
|
||||
public void borrow(Borrow borrow) {
|
||||
borrowMapper.borrowrecord(borrow);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.example.demo.service.impl;
|
||||
|
||||
|
||||
import com.example.demo.mapper.UserMapper;
|
||||
import com.example.demo.pojo.User;
|
||||
import com.example.demo.pojo.info;
|
||||
import com.example.demo.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public User findByUserName(String username) {
|
||||
User u=userMapper.findByUserName(username);
|
||||
return u;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(String username, String password) {
|
||||
userMapper.add(username,password,0,0,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void login(String username, String password) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public info getinfo(String username) {
|
||||
return userMapper.getinfo(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recharge(float money, String username) {
|
||||
userMapper.recharge(money,username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float findmoney(Object username) {
|
||||
return userMapper.findbalance(username);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.demo.utils;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class JwtUtil {
|
||||
|
||||
private static final String KEY = "itheima";
|
||||
|
||||
//接收业务数据,生成token并返回
|
||||
public static String genToken(Map<String, Object> claims) {
|
||||
return JWT.create()
|
||||
.withClaim("claims", claims)
|
||||
.withExpiresAt(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 12))
|
||||
.sign(Algorithm.HMAC256(KEY));
|
||||
}
|
||||
|
||||
//接收token,验证token,并返回业务数据
|
||||
public static Map<String, Object> parseToken(String token) {
|
||||
return JWT.require(Algorithm.HMAC256(KEY))
|
||||
.build()
|
||||
.verify(token)
|
||||
.getClaim("claims")
|
||||
.asMap();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
file.upload-dir=D:\\uploads\\files
|
||||
# MySQL ?????
|
||||
|
||||
#spring.datasource.url= jdbc:mysql://124.220.45.50:3306/big_event
|
||||
#spring.datasource.username= big_event
|
||||
#spring.datasource.password= 3cjBiCj3ZBafn3kP
|
||||
|
||||
#spring.datasource.url= jdbc:mysql://127.0.0.1:3306/big_event
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=hsp
|
||||
|
||||
|
||||
spring.datasource.url= jdbc:mysql://127.0.0.1:3306/big_event1
|
||||
spring.datasource.username= root
|
||||
spring.datasource.password= hsp
|
||||
|
||||
|
||||
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
server.port=8877
|
||||
spring.servlet.multipart.max-file-size=5MB
|
||||
spring.servlet.multipart.max-request-size=5MB
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Demo4ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
file.upload-dir=D:\\uploads\\files
|
||||
# MySQL ?????
|
||||
|
||||
#spring.datasource.url= jdbc:mysql://124.220.45.50:3306/big_event
|
||||
#spring.datasource.username= big_event
|
||||
#spring.datasource.password= 3cjBiCj3ZBafn3kP
|
||||
|
||||
#spring.datasource.url= jdbc:mysql://127.0.0.1:3306/big_event
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=hsp
|
||||
|
||||
|
||||
spring.datasource.url= jdbc:mysql://127.0.0.1:3306/big_event1
|
||||
spring.datasource.username= root
|
||||
spring.datasource.password= hsp
|
||||
|
||||
|
||||
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
server.port=8877
|
||||
spring.servlet.multipart.max-file-size=5MB
|
||||
spring.servlet.multipart.max-request-size=5MB
|
||||
|
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.
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.
Loading…
Reference in new issue