首次提交
|
@ -0,0 +1,8 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<HTMLCodeStyleSettings>
|
||||
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
|
||||
</HTMLCodeStyleSettings>
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
|
@ -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="Springboot_01Demo" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="Springboot_01Demo" 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,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,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_17" default="true" 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,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,124 @@
|
|||
<?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.18-SNAPSHOT</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.xubx</groupId>
|
||||
<artifactId>Springboot_01Demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Springboot_01Demo</name>
|
||||
<description>Springboot_01Demo</description>
|
||||
<properties>
|
||||
<java.version>17</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.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--jsonwebtoken 生成token的库 -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.8.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</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,16 @@
|
|||
package com.xubx.springboot_01demo;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.xubx.springboot_01demo.mapper")
|
||||
|
||||
public class Springboot01DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Springboot01DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.xubx.springboot_01demo.controller;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Blogs;
|
||||
import com.xubx.springboot_01demo.service.BlogService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController //注解标识这是一个控制器类
|
||||
@CrossOrigin //加上CrossOrigin可解决跨域问题
|
||||
public class BlogsController {
|
||||
@Resource
|
||||
BlogService blogService;
|
||||
|
||||
//博客展示
|
||||
@GetMapping("/getBlogs")
|
||||
public List<Blogs> getBlogs (){
|
||||
return blogService.findAllBlogs();
|
||||
}
|
||||
//博客详情
|
||||
@GetMapping("/getBlogDetail")
|
||||
public Blogs getBlogDetail(@RequestParam("blogId") int id){
|
||||
return blogService.findByIdBlogs(id);
|
||||
}
|
||||
//新增博客
|
||||
@PostMapping("/addBlog")
|
||||
public void addBlog(@RequestBody Blogs blogs){
|
||||
blogService.addBlogs(blogs);
|
||||
}
|
||||
//修改博客
|
||||
@PostMapping("/updateBlog")
|
||||
public void updateBlog(@RequestBody Blogs blogs){
|
||||
blogService.updateBlogs(blogs);
|
||||
}
|
||||
//删除博客
|
||||
@GetMapping("/deleteBlog")
|
||||
public void deleteBlog(@RequestParam("blogId") int id){
|
||||
blogService.deleteBlogs(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.xubx.springboot_01demo.controller;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Comment;
|
||||
import com.xubx.springboot_01demo.pojo.Value;
|
||||
import com.xubx.springboot_01demo.service.CommentService;
|
||||
import com.xubx.springboot_01demo.utils.api.Result;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController //注解标识这是一个控制器类
|
||||
@CrossOrigin //加上CrossOrigin可解决跨域问题
|
||||
public class CommentController {
|
||||
@Resource
|
||||
CommentService commentService;
|
||||
//获取所有评论
|
||||
@GetMapping("/getComment")
|
||||
public List<Comment> getComment(@RequestParam("blogId") int article_id){
|
||||
System.out.println("article"+article_id);
|
||||
System.out.println("all:"+commentService.findAllComment(article_id));
|
||||
return commentService.findAllComment(article_id);
|
||||
}
|
||||
//新增评论
|
||||
@PostMapping("/addComment")
|
||||
public void addComment(@RequestBody Comment comment){
|
||||
commentService.addComment(comment);
|
||||
}
|
||||
@RequestMapping("testbg")
|
||||
public Result<Value> testbg(){
|
||||
Value value = new Value();
|
||||
value.setValue("sb大黄");
|
||||
List<Value> list = new ArrayList<>();
|
||||
list.add(value);
|
||||
return Result.ok("widget-text",list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.xubx.springboot_01demo.controller;
|
||||
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.User;
|
||||
import com.xubx.springboot_01demo.service.UserService;
|
||||
import com.xubx.springboot_01demo.utils.token.RedisUtil;
|
||||
import com.xubx.springboot_01demo.utils.token.TokenGenerate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController //注解标识这是一个控制器类
|
||||
@CrossOrigin //加上CrossOrigin可解决跨域问题
|
||||
public class UserController {
|
||||
@Resource
|
||||
UserService userService;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
public static String userName;
|
||||
public static String userNameToken;
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<String> register(@RequestBody User user) {
|
||||
//注册
|
||||
if (userService.insertUser(user)) {
|
||||
return ResponseEntity.ok("注册成功");
|
||||
}
|
||||
return ResponseEntity.ok("用户已经存在");
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public String login(@RequestBody User user) {
|
||||
//登陆
|
||||
if (userService.findUserByUsername(user)) {
|
||||
userName = user.getUsername();
|
||||
userNameToken = userName;
|
||||
String token = new TokenGenerate().generateToken(user.getUsername());
|
||||
redisUtil.addTokens(user.getUsername(), token);
|
||||
return token;
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
@GetMapping("/getUsername")
|
||||
public String getUserName() {
|
||||
System.out.println("当前线程id:" + Thread.currentThread().getId());
|
||||
|
||||
return userName;
|
||||
}
|
||||
|
||||
@RequestMapping("/uploadAvatar")
|
||||
public void uploadAvatar(MultipartFile file) throws IOException {
|
||||
System.out.println("当前线程id:" + Thread.currentThread().getId());
|
||||
|
||||
String pType = file.getContentType();
|
||||
pType = pType.substring(pType.indexOf("/") + 1);
|
||||
if ("jpeg".equals(pType)) {
|
||||
pType = "jpg";
|
||||
}
|
||||
long time = System.currentTimeMillis();
|
||||
String currentWorkingDirectory = System.getProperty("user.dir");
|
||||
String relativePath = "/images/avatar/" + time + "." + pType;
|
||||
String absolutePath = currentWorkingDirectory+"/static" + relativePath;
|
||||
file.transferTo(new File(absolutePath));
|
||||
System.out.println("导入数据库的路径:" + relativePath);
|
||||
userService.addAvatar(relativePath, userName);
|
||||
}
|
||||
|
||||
@GetMapping("/getAvatar")
|
||||
public ResponseEntity<String> getAvatar() {
|
||||
System.out.println("当前线程id:" + Thread.currentThread().getId());
|
||||
String path = userService.getAvatar(userName);
|
||||
System.out.println("发给前端的路径:" + path);
|
||||
return ResponseEntity.ok(path);
|
||||
}
|
||||
|
||||
@GetMapping("usernameChange")
|
||||
public ResponseEntity<String> usernameChange(@RequestParam("username") String username){
|
||||
if(userService.usernameChange(userName,username)){
|
||||
userName = username;
|
||||
return ResponseEntity.ok("修改成功!");
|
||||
}
|
||||
return ResponseEntity.ok("该用户已存在!");
|
||||
}
|
||||
|
||||
@GetMapping("passwordChange")
|
||||
public ResponseEntity<String> passwordChange(@RequestParam("oldPassword") String oldPassword,@RequestParam("newPassword") String newPassword){
|
||||
if(userService.passwordChange(userName,oldPassword,newPassword)){
|
||||
return ResponseEntity.ok("修改成功!");
|
||||
}
|
||||
return ResponseEntity.ok("原密码输入错误!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.xubx.springboot_01demo.mapper;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Blogs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BlogsMapper {
|
||||
//获取所有博客文章信息
|
||||
List<Blogs> findAllBlogs();
|
||||
//根据id获取博客
|
||||
Blogs findByIdBlogs(int id);
|
||||
//新增博客
|
||||
void addBlogs(Blogs blogs);
|
||||
//更新博客
|
||||
void updateBlogs(Blogs blogs);
|
||||
//删除博客
|
||||
void deleteBlogs(int id);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.xubx.springboot_01demo.mapper;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommentMapper {
|
||||
//获取该文章的所有评论
|
||||
List<Comment> findAllComment(int article_id);
|
||||
//新增评论
|
||||
void addComment(Comment comment);
|
||||
//获取回复评论区
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.xubx.springboot_01demo.mapper;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.User;
|
||||
|
||||
public interface UserMapper {
|
||||
//1. 查询用户接口
|
||||
User findUserByUsername(String username);
|
||||
//2.添加用户接口
|
||||
void insertUser(User user);
|
||||
//3.添加头像接口
|
||||
void addAvatar(String path,String username);
|
||||
//4.获取头像地址
|
||||
String getAvatar(String name);
|
||||
//5.修改用户名
|
||||
void usernameChange(String usernameNow,String username);
|
||||
//6.修改密码
|
||||
void passwordChange(String username,String newPassword);
|
||||
//7.通过用户名获取密码
|
||||
String getPasswordByname(String username);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.xubx.springboot_01demo.pojo;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class Blogs {
|
||||
private int id;
|
||||
private String title;
|
||||
private String description;
|
||||
private String content;
|
||||
private Timestamp created;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Blogs{" +
|
||||
"id=" + id +
|
||||
", title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", create='" + created + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Timestamp getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Timestamp create) {
|
||||
this.created = create;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.xubx.springboot_01demo.pojo;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class Comment {
|
||||
private int comment_id;
|
||||
private int article_id;
|
||||
private String username;
|
||||
private String content;
|
||||
private int parent_id;
|
||||
private String parent_name;
|
||||
|
||||
private String created;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Comment{" +
|
||||
"comment_id=" + comment_id +
|
||||
", article_id=" + article_id +
|
||||
", parent_name='" + parent_id + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", created='" + created + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getParent_name() {
|
||||
return parent_name;
|
||||
}
|
||||
|
||||
public void setParent_name(String parent_name) {
|
||||
this.parent_name = parent_name;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public void setComment_id(int comment_id) {
|
||||
this.comment_id = comment_id;
|
||||
}
|
||||
|
||||
public int getArticle_id() {
|
||||
return article_id;
|
||||
}
|
||||
|
||||
public void setArticle_id(int article_id) {
|
||||
this.article_id = article_id;
|
||||
}
|
||||
|
||||
public int getParent_id() {
|
||||
return parent_id;
|
||||
}
|
||||
|
||||
public void setParent_id(int parent_id) {
|
||||
this.parent_id = parent_id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(String created) {
|
||||
this.created = created;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.xubx.springboot_01demo.pojo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
|
||||
public class User {
|
||||
private String username;
|
||||
private String password;
|
||||
private String avatar;
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", avatar='" + avatar + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.xubx.springboot_01demo.pojo;
|
||||
|
||||
public class Value {
|
||||
private String value;
|
||||
|
||||
public Value() {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.xubx.springboot_01demo.service;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Blogs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BlogService {
|
||||
//获取所有博客
|
||||
List<Blogs> findAllBlogs();
|
||||
|
||||
//根据id获取博客
|
||||
Blogs findByIdBlogs(int id);
|
||||
//添加博客
|
||||
void addBlogs(Blogs blogs);
|
||||
//更新博客
|
||||
void updateBlogs(Blogs blogs);
|
||||
//删除博客
|
||||
void deleteBlogs(int id);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.xubx.springboot_01demo.service;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommentService {
|
||||
//获取所有评论
|
||||
List<Comment> findAllComment(int article_id);
|
||||
//新增评论
|
||||
void addComment(Comment comment);
|
||||
//获取回复评论区
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.xubx.springboot_01demo.service;
|
||||
|
||||
import com.xubx.springboot_01demo.pojo.User;
|
||||
|
||||
public interface UserService {
|
||||
//登陆判断
|
||||
Boolean findUserByUsername(User user);
|
||||
//新增用户
|
||||
Boolean insertUser(User user);
|
||||
//添加头像
|
||||
void addAvatar(String path,String username);
|
||||
//获取头像地址
|
||||
String getAvatar(String name);
|
||||
//5.修改用户名
|
||||
boolean usernameChange(String usernameNow,String username);
|
||||
//6.修改密码
|
||||
boolean passwordChange(String username,String oldPassword,String newPassword);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.xubx.springboot_01demo.service.impl;
|
||||
|
||||
import com.xubx.springboot_01demo.mapper.BlogsMapper;
|
||||
import com.xubx.springboot_01demo.pojo.Blogs;
|
||||
import com.xubx.springboot_01demo.service.BlogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BlogsServiceImpl implements BlogService {
|
||||
@Resource
|
||||
BlogsMapper blogsMapper;
|
||||
@Override
|
||||
public List<Blogs> findAllBlogs() {
|
||||
return blogsMapper.findAllBlogs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blogs findByIdBlogs(int id) {
|
||||
return blogsMapper.findByIdBlogs(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBlogs(Blogs blogs) {
|
||||
blogsMapper.addBlogs(blogs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBlogs(Blogs blogs) {
|
||||
blogsMapper.updateBlogs(blogs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlogs(int id) {
|
||||
blogsMapper.deleteBlogs(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.xubx.springboot_01demo.service.impl;
|
||||
|
||||
import com.xubx.springboot_01demo.controller.UserController;
|
||||
import com.xubx.springboot_01demo.mapper.CommentMapper;
|
||||
import com.xubx.springboot_01demo.pojo.Comment;
|
||||
import com.xubx.springboot_01demo.service.CommentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
@Resource
|
||||
CommentMapper commentMapper;
|
||||
@Override
|
||||
public List<Comment> findAllComment(int article_id) {
|
||||
return commentMapper.findAllComment(article_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addComment(Comment comment) {
|
||||
Comment comment1 = new Comment();
|
||||
comment1.setArticle_id(comment.getArticle_id());
|
||||
comment1.setUsername(UserController.userName);
|
||||
comment1.setContent(comment.getContent());
|
||||
comment1.setParent_id(comment.getParent_id());
|
||||
comment1.setParent_name(comment.getParent_name());
|
||||
comment1.setCreated(comment.getCreated());
|
||||
commentMapper.addComment(comment1);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.xubx.springboot_01demo.service.impl;
|
||||
|
||||
import com.xubx.springboot_01demo.mapper.UserMapper;
|
||||
import com.xubx.springboot_01demo.pojo.User;
|
||||
import com.xubx.springboot_01demo.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
|
||||
//Service进行具体的业务处理
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
|
||||
//登陆,获取User对象
|
||||
@Override
|
||||
public Boolean findUserByUsername(User user) {
|
||||
try {
|
||||
User userByUsername = userMapper.findUserByUsername(user.getUsername());
|
||||
|
||||
if (Objects.equals(userByUsername.getPassword(), user.getPassword())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e){
|
||||
System.out.println(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//注册,新增
|
||||
@Override
|
||||
public Boolean insertUser(User user) {
|
||||
// 检查用户名是否已存在
|
||||
if (userMapper.findUserByUsername(user.getUsername()) != null) {
|
||||
return false;
|
||||
}
|
||||
// 用户名不存在,插入新用户
|
||||
userMapper.insertUser(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAvatar(String path,String username) {
|
||||
userMapper.addAvatar(path,username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAvatar(String name) {
|
||||
return userMapper.getAvatar(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usernameChange(String usernameNow,String username) {
|
||||
// 检查用户名是否已存在
|
||||
if (userMapper.findUserByUsername(username) != null) {
|
||||
return false;
|
||||
}
|
||||
userMapper.usernameChange(usernameNow,username);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passwordChange(String username, String oldPassword, String newPassword) {
|
||||
//检查输入的原密码是否正确
|
||||
if(oldPassword.equals(userMapper.getPasswordByname(username))){
|
||||
userMapper.passwordChange(username,newPassword);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.xubx.springboot_01demo.utils.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Result<T> {
|
||||
//状态码
|
||||
private int code;
|
||||
//提示信息
|
||||
private String message;
|
||||
//推送的数据
|
||||
private ResultData<T> result;
|
||||
|
||||
public static <T> Result<T> ok(String chartType, List<T> data) {
|
||||
Result<T> r = new Result<>();
|
||||
r.setCode(200);
|
||||
r.setMessage("");
|
||||
ResultData<T> resultData = new ResultData<>();
|
||||
resultData.setChartType(chartType);
|
||||
resultData.setData(data);
|
||||
r.setResult(resultData);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Result{" +
|
||||
"code=" + code +
|
||||
", message='" + message + '\'' +
|
||||
", result=" + result +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@Data
|
||||
class ResultData<T> {
|
||||
// 图表类型
|
||||
private String chartType;
|
||||
// 数据
|
||||
private List<T> data;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.xubx.springboot_01demo.utils;
|
||||
|
||||
public class test {
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.xubx.springboot_01demo.utils.token;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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"); //登录
|
||||
|
||||
|
||||
|
||||
registry.addInterceptor(tokenInterceptor)//添加名为tokenInterceptor的拦截器
|
||||
.addPathPatterns("/**") //指定拦截所有路径
|
||||
.excludePathPatterns(excludePath);//排除不需要拦截的路径
|
||||
WebMvcConfigurer.super.addInterceptors(registry);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.xubx.springboot_01demo.utils.token;
|
||||
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
@Service
|
||||
public class RedisUtil {
|
||||
@Resource
|
||||
private RedisTemplate<String, String> stringRedisTemplate;//这是一个使用redis的API,可以直接用StringRedisTemplate
|
||||
|
||||
public void addTokens(String username, String token) {//存入token
|
||||
System.out.println(username+token+"打印addTokens");
|
||||
ValueOperations valueOperations = stringRedisTemplate.opsForValue();
|
||||
valueOperations.set(username, token);
|
||||
}
|
||||
public String getTokens(String username) {//获取token
|
||||
return stringRedisTemplate.opsForValue().get(username);
|
||||
}
|
||||
|
||||
public void delTokens(String username) {//删除token在前端已经进行
|
||||
stringRedisTemplate.delete(username);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.xubx.springboot_01demo.utils.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= 60*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){
|
||||
try {
|
||||
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(TOKEN_SECRET)).withIssuer("auth0").build();
|
||||
DecodedJWT jwt = verifier.verify(token);
|
||||
System.out.println("当前线程id:" + Thread.currentThread().getId());
|
||||
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,42 @@
|
|||
package com.xubx.springboot_01demo.utils.token;
|
||||
|
||||
|
||||
import com.xubx.springboot_01demo.controller.UserController;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
//token拦截器,对拦截下的接口检查其的token是否符合只有
|
||||
// 在提供一个有效的token时才能通过验证,否则给出认证失败的响应。
|
||||
@Component
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@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 = redisUtil.getTokens(UserController.userNameToken);
|
||||
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,15 @@
|
|||
spring.datasource.driverClassName=com.mysql.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://124.71.135.249:3306/vue
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=xbx123
|
||||
|
||||
server.port=8081
|
||||
#spring.web.resources.static-locations=classpath:/static/
|
||||
spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
|
||||
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
mybatis.type-aliases-package=com.xubx.springboot_01demo.pojo
|
||||
|
||||
spring.redis.host=124.71.135.249
|
||||
spring.redis.port=6379
|
||||
spring.redis.password=123456
|
|
@ -0,0 +1,12 @@
|
|||
${AnsiColor.BRIGHT_WHITE}
|
||||
__ __ _ _ _ ____
|
||||
\ \ / / | | | \ | | _ \
|
||||
\ V /_ _| |____ _| \| | |_) |
|
||||
> <| | | | '_ \ \/ / . ` | _ <
|
||||
/ . \ |_| | |_) > <| |\ | |_) |
|
||||
/_/ \_\__,_|_.__/_/\_\_| \_|____/
|
||||
|
||||
|
||||
|
||||
${AnsiColor.BRIGHT_RED}
|
||||
${AnsiColor.BLACK}
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.xubx.springboot_01demo.mapper.BlogsMapper">
|
||||
<resultMap id="BaseResultMap" type="com.xubx.springboot_01demo.pojo.Blogs">
|
||||
<id column="id" property="id" />
|
||||
<result column="id" property="id" />
|
||||
<result column="title" property="title" />
|
||||
<result column="description" property="description" />
|
||||
<result column="content" property="content" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 获取整个表 -->
|
||||
<select id="findAllBlogs" resultMap="BaseResultMap">
|
||||
select * from blog
|
||||
</select>
|
||||
|
||||
<!--根据id获取表 -->
|
||||
<select id="findByIdBlogs" resultMap="BaseResultMap">
|
||||
select * from blog where id = #{id}
|
||||
</select>
|
||||
|
||||
<!--新增博客-->
|
||||
<insert id="addBlogs" parameterType="com.xubx.springboot_01demo.pojo.Blogs">
|
||||
insert into blog (title, description, content, created)
|
||||
values (#{title}, #{description}, #{content}, #{created})
|
||||
</insert>
|
||||
|
||||
<!--更新博客-->
|
||||
<update id="updateBlogs" parameterType="com.xubx.springboot_01demo.pojo.Blogs">
|
||||
update blog
|
||||
set title = #{title},
|
||||
description = #{description},
|
||||
content = #{content}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!--删除博客-->
|
||||
<delete id="deleteBlogs" parameterType="int">
|
||||
delete from blog where id = #{id}
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.xubx.springboot_01demo.mapper.CommentMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.xubx.springboot_01demo.pojo.Comment">
|
||||
<id column="comment_id" property="comment_id" />
|
||||
<result column="article_id" property="article_id"/>
|
||||
<result column="username" property="username" />
|
||||
<result column="content" property="content" />
|
||||
<result column="parent_id" property="parent_id"/>
|
||||
<result column="parent_name" property="parent_name" />
|
||||
<result column="created" property="created" />
|
||||
|
||||
|
||||
</resultMap>
|
||||
|
||||
<!-- 根据id获取表 -->
|
||||
<select id="findAllComment" resultMap="BaseResultMap">
|
||||
select * from comment where article_id = #{article_id}
|
||||
</select>
|
||||
<!--新增评论-->
|
||||
<insert id="addComment" parameterType="com.xubx.springboot_01demo.pojo.Comment">
|
||||
insert into comment (article_id, username, content, parent_id, parent_name, created)
|
||||
values (#{article_id}, #{username}, #{content}, #{parent_id}, #{parent_name}, #{created})
|
||||
</insert>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.xubx.springboot_01demo.mapper.UserMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.xubx.springboot_01demo.pojo.User">
|
||||
<id column="username" property="username" />
|
||||
<result column="username" property="username" />
|
||||
<result column="password" property="password" />
|
||||
<result column="avatar" property="avatar"/>
|
||||
</resultMap>
|
||||
<!-- 查询用户 -->
|
||||
<select id="findUserByUsername" resultMap="BaseResultMap">
|
||||
select username, password from register where username = #{username}
|
||||
</select>
|
||||
<!-- 插入用户 -->
|
||||
<insert id="insertUser" parameterType="com.xubx.springboot_01demo.pojo.User" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into register(username, password) values(#{username}, #{password})
|
||||
</insert>
|
||||
<!--添加头像-->
|
||||
<insert id="addAvatar" parameterType="com.xubx.springboot_01demo.pojo.User">
|
||||
UPDATE register
|
||||
SET avatar = #{path}
|
||||
WHERE username = #{username};
|
||||
</insert>
|
||||
<!--获取头像地址-->
|
||||
<select id="getAvatar" resultType="java.lang.String">
|
||||
select avatar from register where username = #{username}
|
||||
</select>
|
||||
<!--修改用户名-->
|
||||
<insert id="usernameChange" >
|
||||
UPDATE register
|
||||
SET username = #{username}
|
||||
WHERE username = #{usernameNow}
|
||||
</insert>
|
||||
<!--修改密码-->
|
||||
<insert id="passwordChange" >
|
||||
UPDATE register
|
||||
SET password = #{newPassword}
|
||||
WHERE username = #{username}
|
||||
</insert>
|
||||
<!-- 根据name查密码 -->
|
||||
<select id="getPasswordByname" resultType="java.lang.String">
|
||||
select password from register where username = #{username}
|
||||
</select>
|
||||
</mapper>
|
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 99 KiB |