new
This commit is contained in:
109
library/pom.xml
Normal file
109
library/pom.xml
Normal file
@@ -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>2.6.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>library</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.14.1</version> <!-- 版本号可以根据你的需求进行更改 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.14.1</version> <!-- 版本号可以根据你的需求进行更改 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.7.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.11.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.18.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>2021.0.4.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.6.1 </version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.library;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@MapperScan("com.example.library.mapper")
|
||||
public class LibraryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LibraryApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
11
library/src/main/java/com/example/library/LoginUser.java
Normal file
11
library/src/main/java/com/example/library/LoginUser.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.example.library;
|
||||
public class LoginUser {
|
||||
private static int visitCount = 0;
|
||||
public static void addVisitCount() {
|
||||
LoginUser.visitCount++;
|
||||
}
|
||||
|
||||
public static int getVisitCount() {
|
||||
return LoginUser.visitCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.library.commom;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* mybatis-plus 分页插件
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan("com.example.demo.mapper")
|
||||
@MapperScan("com.example.demo.service")
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
65
library/src/main/java/com/example/library/commom/Result.java
Normal file
65
library/src/main/java/com/example/library/commom/Result.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.example.library.commom;
|
||||
|
||||
public class Result<T> {
|
||||
private String code;
|
||||
private String msg;
|
||||
private T data;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Result() {
|
||||
}
|
||||
|
||||
public Result(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static Result success() {
|
||||
Result result = new Result<>();
|
||||
result.setCode("0");
|
||||
result.setMsg("成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
Result<T> result = new Result<>(data);
|
||||
result.setCode("0");
|
||||
result.setMsg("成功");
|
||||
return result;
|
||||
}
|
||||
public static <T> Result<T> noAuth() {
|
||||
Result<T> result = new Result<>();
|
||||
result.setCode("401");
|
||||
result.setMsg("error");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String code, String msg) {
|
||||
Result result = new Result();
|
||||
result.setCode(code);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.Book;
|
||||
import com.example.library.mapper.BookMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/book")
|
||||
public class BookController {
|
||||
@Resource
|
||||
BookMapper BookMapper;
|
||||
|
||||
@PostMapping
|
||||
public Result<?> save(@RequestBody Book Book){
|
||||
BookMapper.insert(Book);
|
||||
return Result.success();
|
||||
}
|
||||
@PutMapping
|
||||
public Result<?> update(@RequestBody Book Book){
|
||||
BookMapper.updateById(Book);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
@PostMapping("/deleteBatch")
|
||||
public Result<?> deleteBatch(@RequestBody List<Integer> ids){
|
||||
BookMapper.deleteBatchIds(ids);
|
||||
return Result.success();
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Long id){
|
||||
BookMapper.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping
|
||||
public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(defaultValue = "") String search1,
|
||||
@RequestParam(defaultValue = "") String search2,
|
||||
@RequestParam(defaultValue = "") String search3){
|
||||
LambdaQueryWrapper<Book> wrappers = Wrappers.<Book>lambdaQuery();
|
||||
if(StringUtils.isNotBlank(search1)){
|
||||
wrappers.like(Book::getIsbn,search1);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search2)){
|
||||
wrappers.like(Book::getName,search2);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search3)){
|
||||
wrappers.like(Book::getAuthor,search3);
|
||||
}
|
||||
Page<Book> BookPage =BookMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
|
||||
return Result.success(BookPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.BookWithUser;
|
||||
import com.example.library.mapper.BookWithUserMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/bookwithuser")
|
||||
public class BookWithUserController {
|
||||
@Resource
|
||||
BookWithUserMapper BookWithUserMapper;
|
||||
//
|
||||
// @PostMapping
|
||||
// public Result<?> save(@RequestBody Book Book){
|
||||
// BookMapper.insert(Book);
|
||||
// return Result.success();
|
||||
// }
|
||||
|
||||
// // 批量删除
|
||||
// @PostMapping("/deleteBatch")
|
||||
// public Result<?> deleteBatch(@RequestBody List<Integer> ids){
|
||||
// BookMapper.deleteBatchIds(ids);
|
||||
// return Result.success();
|
||||
// }
|
||||
// @PutMapping
|
||||
// public Result<?> update(@RequestBody Book Book){
|
||||
// BookMapper.updateById(Book);
|
||||
// return Result.success();
|
||||
// }
|
||||
// @DeleteMapping("/{id}")
|
||||
// public Result<?> delete(@PathVariable Long id){
|
||||
// BookMapper.deleteById(id);
|
||||
// return Result.success();
|
||||
// }
|
||||
@PostMapping("/insertNew")
|
||||
public Result<?> insertNew(@RequestBody BookWithUser BookWithUser){
|
||||
BookWithUserMapper.insert(BookWithUser);
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping
|
||||
public Result<?> update(@RequestBody BookWithUser BookWithUser){
|
||||
UpdateWrapper<BookWithUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("isbn",BookWithUser.getIsbn()).eq("id",BookWithUser.getId());
|
||||
BookWithUserMapper.update(BookWithUser, updateWrapper);
|
||||
return Result.success();
|
||||
}
|
||||
//删除一条记录
|
||||
@PostMapping("/deleteRecord")
|
||||
public Result<?> deleteRecord(@RequestBody BookWithUser BookWithUser){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("isbn",BookWithUser.getIsbn());
|
||||
map.put("id",BookWithUser.getId());
|
||||
BookWithUserMapper.deleteByMap(map);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/deleteRecords")
|
||||
public Result<?> deleteRecords(@RequestBody List<BookWithUser> BookWithUsers){
|
||||
int len = BookWithUsers.size();
|
||||
for(int i=0;i<len;i++) {
|
||||
BookWithUser curRecord = BookWithUsers.get(i);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("isbn",curRecord.getIsbn());
|
||||
map.put("id",curRecord.getId());
|
||||
BookWithUserMapper.deleteByMap(map);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping
|
||||
public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(defaultValue = "") String search1,
|
||||
@RequestParam(defaultValue = "") String search2,
|
||||
@RequestParam(defaultValue = "") String search3){
|
||||
LambdaQueryWrapper<BookWithUser> wrappers = Wrappers.<BookWithUser>lambdaQuery();
|
||||
if(StringUtils.isNotBlank(search1)){
|
||||
wrappers.like(BookWithUser::getIsbn,search1);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search2)){
|
||||
wrappers.like(BookWithUser::getBookName,search2);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search3)){
|
||||
wrappers.like(BookWithUser::getId,search3);
|
||||
}
|
||||
Page<BookWithUser> BookPage =BookWithUserMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
|
||||
return Result.success(BookPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.example.library.LoginUser;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.Book;
|
||||
import com.example.library.entity.LendRecord;
|
||||
import com.example.library.entity.User;
|
||||
import com.example.library.mapper.BookMapper;
|
||||
import com.example.library.mapper.LendRecordMapper;
|
||||
import com.example.library.mapper.UserMapper;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dashboard")
|
||||
public class DashboardController {
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private LendRecordMapper lendRecordMapper;
|
||||
@Resource
|
||||
private BookMapper bookMapper;
|
||||
@GetMapping
|
||||
public Result<?> dashboardrecords(){
|
||||
int visitCount = LoginUser.getVisitCount();
|
||||
QueryWrapper<User> queryWrapper1=new QueryWrapper();
|
||||
int userCount = userMapper.selectCount(queryWrapper1);
|
||||
QueryWrapper<LendRecord> queryWrapper2=new QueryWrapper();
|
||||
int lendRecordCount = lendRecordMapper.selectCount(queryWrapper2);
|
||||
QueryWrapper<Book> queryWrapper3=new QueryWrapper();
|
||||
int bookCount = bookMapper.selectCount(queryWrapper3);
|
||||
Map<String, Object> map = new HashMap<>();//键值对形式
|
||||
map.put("visitCount", visitCount);//放置visitCount到map中
|
||||
map.put("userCount", userCount);
|
||||
map.put("lendRecordCount", lendRecordCount);
|
||||
map.put("bookCount", bookCount);
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.LendRecord;
|
||||
import com.example.library.mapper.LendRecordMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/LendRecord")
|
||||
public class LendRecordController {
|
||||
@Resource
|
||||
LendRecordMapper LendRecordMapper;
|
||||
|
||||
@DeleteMapping("/{isbn}")
|
||||
public Result<?> delete(@PathVariable String isbn){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("isbn",isbn);
|
||||
LendRecordMapper.deleteByMap(map);
|
||||
return Result.success();
|
||||
}
|
||||
//删除一条记录
|
||||
@PostMapping("/deleteRecord")
|
||||
public Result<?> deleteRecord(@RequestBody LendRecord LendRecord){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("isbn",LendRecord.getIsbn());
|
||||
map.put("borrownum",LendRecord.getBorrownum());
|
||||
LendRecordMapper.deleteByMap(map);
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping("/deleteRecords")
|
||||
public Result<?> deleteRecords(@RequestBody List<LendRecord> LendRecords){
|
||||
int len = LendRecords.size();
|
||||
for(int i=0;i<len;i++) {
|
||||
LendRecord curRecord = LendRecords.get(i);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("isbn",curRecord.getIsbn());
|
||||
map.put("borrownum",curRecord.getBorrownum());
|
||||
LendRecordMapper.deleteByMap(map);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping
|
||||
public Result<?> save(@RequestBody LendRecord LendRecord){
|
||||
LendRecordMapper.insert(LendRecord);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping
|
||||
public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(defaultValue = "") String search1,
|
||||
@RequestParam(defaultValue = "") String search2,
|
||||
@RequestParam(defaultValue = "") String search3){
|
||||
LambdaQueryWrapper<LendRecord> wrappers = Wrappers.<LendRecord>lambdaQuery();
|
||||
if(StringUtils.isNotBlank(search1)){
|
||||
wrappers.like(LendRecord::getIsbn,search1);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search2)){
|
||||
wrappers.like(LendRecord::getBookname,search2);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search3)){
|
||||
wrappers.like(LendRecord::getReaderId,search3);
|
||||
}
|
||||
Page<LendRecord> LendRecordPage =LendRecordMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
|
||||
return Result.success(LendRecordPage);
|
||||
}
|
||||
|
||||
@PutMapping("/{isbn}")
|
||||
public Result<?> update(@PathVariable String isbn,@RequestBody LendRecord lendRecord){
|
||||
UpdateWrapper<LendRecord> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("isbn",isbn);
|
||||
LendRecord lendrecord = new LendRecord();
|
||||
lendrecord.setLendTime(lendRecord.getLendTime());
|
||||
lendrecord.setReturnTime(lendRecord.getReturnTime());
|
||||
lendrecord.setStatus(lendRecord.getStatus());
|
||||
LendRecordMapper.update(lendrecord, updateWrapper);
|
||||
return Result.success();
|
||||
}
|
||||
@PutMapping("/{lendTime}")
|
||||
public Result<?> update2(@PathVariable Date lendTime, @RequestBody LendRecord lendRecord){
|
||||
UpdateWrapper<LendRecord> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("lendTime",lendTime);
|
||||
LendRecord lendrecord = new LendRecord();
|
||||
lendrecord.setReturnTime(lendRecord.getReturnTime());
|
||||
lendrecord.setStatus(lendRecord.getStatus());
|
||||
LendRecordMapper.update(lendrecord, updateWrapper);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.LendRecord;
|
||||
import com.example.library.mapper.LendRecordMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/LendRecord1")
|
||||
public class LendRecordController1 {
|
||||
@Resource
|
||||
LendRecordMapper LendRecordMapper;
|
||||
@PutMapping
|
||||
public Result<?> update2( @RequestBody LendRecord lendRecord){
|
||||
UpdateWrapper<LendRecord> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("isbn",lendRecord.getIsbn()).eq("reader_id",lendRecord.getReaderId()).eq("borrownum",lendRecord.getBorrownum());
|
||||
LendRecord lendrecord = new LendRecord();
|
||||
lendrecord.setReturnTime(lendRecord.getReturnTime());
|
||||
lendrecord.setStatus(lendRecord.getStatus());
|
||||
LendRecordMapper.update(lendrecord, updateWrapper);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.library.LoginUser;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.User;
|
||||
import com.example.library.mapper.UserMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.example.library.utils.TokenUtils;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
@PostMapping("/register")
|
||||
public Result<?> register(@RequestBody User user){
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()));
|
||||
if(res != null)
|
||||
{
|
||||
return Result.error("-1","用户名已重复");
|
||||
}
|
||||
userMapper.insert(user);
|
||||
return Result.success();
|
||||
}
|
||||
@CrossOrigin
|
||||
@PostMapping("/checkusername")
|
||||
public Result<?> checkusername(@RequestBody User user){
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","用户名不存在");
|
||||
}
|
||||
return Result.success("0");
|
||||
}
|
||||
@CrossOrigin
|
||||
@PostMapping("/sendsms")
|
||||
public Result<?> sendsms(@RequestBody User user, HttpServletRequest request){
|
||||
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getPhone,user.getPhone()).eq(User::getUsername,user.getUsername()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","手机号错误");
|
||||
}
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute("code",1234);
|
||||
System.out.println(session.getAttribute("code"));
|
||||
return Result.success("0");
|
||||
}
|
||||
@CrossOrigin
|
||||
@GetMapping("/checksms")
|
||||
public Result<?> checksms(HttpServletRequest request){
|
||||
HttpSession session = request.getSession();
|
||||
String code = (String)session.getAttribute("code");
|
||||
System.out.println(code);
|
||||
|
||||
try {
|
||||
if ("1234".equals(request.getParameter("code"))) {
|
||||
return Result.success("0");
|
||||
} else {
|
||||
return Result.error("-1", "验证码错误");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Result.error("-1", "验证码错误");
|
||||
}
|
||||
|
||||
}
|
||||
@CrossOrigin
|
||||
@PostMapping("/resetpassword")
|
||||
public Result<?> resetpassword(@RequestBody User user){
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()));
|
||||
//User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()).eq(User::getPhone,user.getPhone()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","用户名或手机号错误");
|
||||
}
|
||||
res.setPassword(user.getPassword());
|
||||
userMapper.updateById(res);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@PostMapping("/login")
|
||||
public Result<?> login(@RequestBody User user){
|
||||
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()).eq(User::getPassword,user.getPassword()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","用户名或密码错误");
|
||||
}
|
||||
String token = TokenUtils.genToken(res);
|
||||
res.setToken(token);
|
||||
LoginUser loginuser = new LoginUser();
|
||||
loginuser.addVisitCount();
|
||||
return Result.success(res);
|
||||
}
|
||||
@PostMapping("/info")
|
||||
public Result<?> userinfo(@RequestBody User user){
|
||||
System.out.println(user);
|
||||
User user1 = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId,user.getId()));
|
||||
System.out.println(user1);
|
||||
return Result.success(user1);
|
||||
}
|
||||
@PostMapping
|
||||
public Result<?> save(@RequestBody User user){
|
||||
if(user.getPassword() == null){
|
||||
user.setPassword("abc123456");
|
||||
}
|
||||
userMapper.insert(user);
|
||||
return Result.success();
|
||||
}
|
||||
@PutMapping("/password")
|
||||
public Result<?> update( @RequestParam Integer id,
|
||||
@RequestParam String password2){
|
||||
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id",id);
|
||||
User user = new User();
|
||||
user.setPassword(password2);
|
||||
userMapper.update(user,updateWrapper);
|
||||
return Result.success();
|
||||
}
|
||||
@PutMapping
|
||||
public Result<?> password(@RequestBody User user){
|
||||
userMapper.updateById(user);
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping("/deleteBatch")
|
||||
public Result<?> deleteBatch(@RequestBody List<Integer> ids){
|
||||
userMapper.deleteBatchIds(ids);
|
||||
return Result.success();
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Long id){
|
||||
userMapper.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
@GetMapping
|
||||
public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(defaultValue = "") String search){
|
||||
LambdaQueryWrapper<User> wrappers = Wrappers.<User>lambdaQuery();
|
||||
if(StringUtils.isNotBlank(search)){
|
||||
wrappers.like(User::getNickName,search);
|
||||
}
|
||||
wrappers.like(User::getRole,2);
|
||||
Page<User> userPage =userMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
|
||||
return Result.success(userPage);
|
||||
}
|
||||
@GetMapping("/usersearch")
|
||||
public Result<?> findPage2(@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(defaultValue = "") String search1,
|
||||
@RequestParam(defaultValue = "") String search2,
|
||||
@RequestParam(defaultValue = "") String search3,
|
||||
@RequestParam(defaultValue = "") String search4){
|
||||
LambdaQueryWrapper<User> wrappers = Wrappers.<User>lambdaQuery();
|
||||
if(StringUtils.isNotBlank(search1)){
|
||||
wrappers.like(User::getId,search1);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search2)){
|
||||
wrappers.like(User::getNickName,search2);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search3)){
|
||||
wrappers.like(User::getPhone,search3);
|
||||
}
|
||||
if(StringUtils.isNotBlank(search4)){
|
||||
wrappers.like(User::getAddress,search4);
|
||||
}
|
||||
wrappers.like(User::getRole,2);
|
||||
Page<User> userPage =userMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
|
||||
return Result.success(userPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.example.library.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.User;
|
||||
import com.example.library.mapper.UserMapper;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/forget")
|
||||
public class forgetController {
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
@CrossOrigin
|
||||
@PostMapping("/checkusername")
|
||||
public Result<?> checkusername(@RequestBody User user){
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","用户名不存在");
|
||||
}
|
||||
return Result.success("0");
|
||||
}
|
||||
@CrossOrigin
|
||||
@PostMapping("/sendsms")
|
||||
public Result<?> sendsms(@RequestBody User user, HttpServletRequest request){
|
||||
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getPhone,user.getPhone()).eq(User::getUsername,user.getUsername()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","手机号错误");
|
||||
}
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute("code",1234);
|
||||
System.out.println(session.getAttribute("code"));
|
||||
return Result.success("0");
|
||||
}
|
||||
@CrossOrigin
|
||||
@GetMapping("/checksms")
|
||||
public Result<?> checksms(HttpServletRequest request){
|
||||
HttpSession session = request.getSession();
|
||||
String code = (String)session.getAttribute("code");
|
||||
System.out.println(code);
|
||||
|
||||
try {
|
||||
if ("1234".equals(request.getParameter("code"))) {
|
||||
return Result.success("0");
|
||||
} else {
|
||||
return Result.error("-1", "验证码错误");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Result.error("-1", "验证码错误");
|
||||
}
|
||||
|
||||
}
|
||||
@CrossOrigin
|
||||
@PostMapping("/resetpassword")
|
||||
public Result<?> resetpassword(@RequestBody User user){
|
||||
User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()));
|
||||
//User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername,user.getUsername()).eq(User::getPhone,user.getPhone()));
|
||||
if(res == null)
|
||||
{
|
||||
return Result.error("-1","用户名或手机号错误");
|
||||
}
|
||||
res.setPassword(user.getPassword());
|
||||
userMapper.updateById(res);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
33
library/src/main/java/com/example/library/entity/Book.java
Normal file
33
library/src/main/java/com/example/library/entity/Book.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.example.library.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("book")
|
||||
@Data
|
||||
|
||||
public class Book {
|
||||
|
||||
@TableId (type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String isbn;
|
||||
private String name;
|
||||
private BigDecimal price;
|
||||
private String author;
|
||||
private Integer borrownum;
|
||||
private String publisher;
|
||||
@JsonFormat(locale="zh",timezone="GMT+8", pattern="yyyy-MM-dd")
|
||||
private Date createTime;
|
||||
private String status;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.example.library.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("bookwithuser")
|
||||
@Data
|
||||
public class BookWithUser {
|
||||
private Integer id;
|
||||
private String isbn;
|
||||
private String bookName;
|
||||
private String nickName;
|
||||
@JsonFormat(locale="zh",timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date lendtime;
|
||||
@JsonFormat(locale="zh",timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date deadtime;
|
||||
private Integer prolong;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.example.library.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("lend_record")
|
||||
@Data
|
||||
public class LendRecord {
|
||||
private Integer readerId;
|
||||
private String isbn;
|
||||
private String bookname;
|
||||
@JsonFormat(locale="zh",timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date lendTime;
|
||||
@JsonFormat(locale="zh",timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date returnTime;
|
||||
private String status;
|
||||
private Integer borrownum;
|
||||
|
||||
}
|
||||
24
library/src/main/java/com/example/library/entity/User.java
Normal file
24
library/src/main/java/com/example/library/entity/User.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.example.library.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@TableName("user")
|
||||
@Data
|
||||
public class User {
|
||||
@TableId (type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String nickName;
|
||||
private String password;
|
||||
private String sex;
|
||||
private String address;
|
||||
private String phone;
|
||||
@TableField(exist = false) //表中没有token不会报错仍能编译运行
|
||||
private String token;
|
||||
private Integer role;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.library.filter;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.example.library.commom.Result;
|
||||
import com.example.library.entity.User;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class AccessControlInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private User user;
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
// 获取请求中的所有 Cookie
|
||||
try {
|
||||
String token = request.getHeader("token");
|
||||
String aud = JWT.decode(token).getAudience().get(0);
|
||||
Integer userId = Integer.valueOf(aud);
|
||||
|
||||
if (userId != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
}
|
||||
response.setContentType("application/json");
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 将 ErrorResult 对象转换为 JSON 格式
|
||||
String jsonResponse = mapper.writeValueAsString(Result.noAuth());
|
||||
response.getWriter().println(jsonResponse);
|
||||
// 用户信息验证失败,返回 false,并返回错误响应或者重定向到登录页面等操作
|
||||
return false;
|
||||
}
|
||||
|
||||
// 用户信息验证的方法,可以根据具体业务逻辑来实现
|
||||
private boolean validateToken(String token) {
|
||||
return user.getToken().equals(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.library.filter;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("*") // 允许访问的域名,可以指定多个或使用通配符 *
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法
|
||||
.allowCredentials(true); // 允许传输凭证信息
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.example.library.filter;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse response = (HttpServletResponse) res;
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
|
||||
response.setHeader("Access-Control-Allow-Headers", "authorization, content-type, xsrf-token");
|
||||
response.setHeader("Access-Control-Max-Age", "3600");
|
||||
response.setHeader("allowCredentials","true");
|
||||
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
} else {
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.library.filter;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new AccessControlInterceptor())// 添加要拦截的路径
|
||||
.excludePathPatterns("/user/login").excludePathPatterns("/forget/**").excludePathPatterns("/user/register"); // 排除不需要拦截的路径
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.library.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.library.entity.Book;
|
||||
|
||||
|
||||
public interface BookMapper extends BaseMapper<Book> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.library.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.library.entity.BookWithUser;
|
||||
|
||||
public interface BookWithUserMapper extends BaseMapper<BookWithUser> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.library.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.library.entity.LendRecord;
|
||||
|
||||
|
||||
public interface LendRecordMapper extends BaseMapper<LendRecord> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.library.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.library.entity.User;
|
||||
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
// @Insert("INSERT INTO user_table (username, password, email) VALUES (#{username}, #{password}, #{email})")
|
||||
// void insertUser(User user);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.example.library.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
|
||||
import com.example.library.entity.User;
|
||||
import com.example.library.mapper.UserMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TokenUtils {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
private static UserMapper staticUserMapper;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
staticUserMapper = userMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成token
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static String genToken(User user) {
|
||||
return JWT.create().withExpiresAt(DateUtil.offsetDay(new Date(), 1)).withAudience(user.getId().toString())
|
||||
.sign(Algorithm.HMAC256(user.getPassword()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token中的用户信息
|
||||
* @return
|
||||
*/
|
||||
public static User getUser() {
|
||||
try {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
String token = request.getHeader("token");
|
||||
String aud = JWT.decode(token).getAudience().get(0);
|
||||
Integer userId = Integer.valueOf(aud);
|
||||
return staticUserMapper.selectById(userId);
|
||||
} catch (Exception e) {
|
||||
log.error("解析token失败", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
library/src/main/resources/application.yaml
Normal file
19
library/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
server:
|
||||
port: 9090
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/springboot-vue?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
|
||||
application:
|
||||
name: libirary-service
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.202.220:8848
|
||||
|
||||
1
library/src/main/resources/static/css/app.90e92dc6.css
Normal file
1
library/src/main/resources/static/css/app.90e92dc6.css
Normal file
@@ -0,0 +1 @@
|
||||
.icon[data-v-f4e55176]{width:40px;height:40px;padding-top:5px;padding-right:10px}.icon[data-v-f5394220]{width:30px;height:30px;padding-top:5px;padding-right:10px}*{margin:0;padding:0;box-sizing:border-box}.icon{width:1em;height:1em;vertical-align:-.15em;fill:currentColor;overflow:hidden}
|
||||
@@ -0,0 +1 @@
|
||||
.box-card[data-v-4dae75ff]{width:80%;margin-bottom:25px;margin-left:10px}.clearfix[data-v-4dae75ff]{text-align:center;font-size:15px}.text[data-v-4dae75ff]{text-align:center;font-size:24px;font-weight:700;vertical-align:super}#main[data-v-4dae75ff]{width:100%;height:450px;margin-top:20px}.icon[data-v-4dae75ff]{width:50px;height:50px;padding-top:5px;padding-right:10px}
|
||||
@@ -0,0 +1 @@
|
||||
.ValidCode[data-v-4bf328f2]{display:flex;justify-content:center;align-items:center;cursor:pointer}.ValidCode span[data-v-4bf328f2]{display:inline-block}.login-container[data-v-70b225b5]{position:fixed;width:100%;height:100%;background:url(../img/bg2.dd39329b.svg);background-size:contain}.login-page[data-v-70b225b5]{border-radius:5px;margin:180px auto;width:350px;padding:35px 35px 15px;background:#fff;border:1px solid #eaeaea;box-shadow:0 0 25px #cac6c6}
|
||||
@@ -0,0 +1 @@
|
||||
.avatar-uploader{border:1px dashed #d9d9d9;border-radius:6px;cursor:pointer;position:relative;overflow:hidden}.avatar-uploader:hover{border-color:#409eff}.avatar{width:178px;height:178px;display:block}.box-card{width:60%;margin:auto;padding:20px}
|
||||
@@ -0,0 +1 @@
|
||||
.ValidCode[data-v-4bf328f2]{display:flex;justify-content:center;align-items:center;cursor:pointer}.ValidCode span[data-v-4bf328f2]{display:inline-block}.login-container[data-v-a8e2f1f2]{position:fixed;width:100%;height:100vh;background:url(../img/bg2.dd39329b.svg);background-size:contain;overflow:hidden}.login-page[data-v-a8e2f1f2]{border-radius:5px;margin:180px auto;width:350px;padding:35px 35px 15px;background:#fff;border:1px solid #eaeaea;box-shadow:0 0 25px #cac6c6}
|
||||
File diff suppressed because one or more lines are too long
BIN
library/src/main/resources/static/favicon.ico
Normal file
BIN
library/src/main/resources/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
33
library/src/main/resources/static/img/bg2.dd39329b.svg
Normal file
33
library/src/main/resources/static/img/bg2.dd39329b.svg
Normal file
@@ -0,0 +1,33 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="100%" height="100%" viewBox="0 0 1400 800">
|
||||
|
||||
<rect x="1300" y="400" rx="40" ry="40" width="300" height="300" stroke="rgb(129, 201, 149)" fill="rgb(129, 201, 149)">
|
||||
<animateTransform attributeType="XML" attributeName="transform" begin="0s" dur="35s" type="rotate" from="0 1450 550" to="360 1450 550" repeatCount="indefinite"/>
|
||||
</rect>
|
||||
|
||||
<path d="M 100 350 A 150 150 0 1 1 400 350 Q400 370 380 370 L 250 370 L 120 370 Q100 370 100 350" stroke="rgb(253, 214, 99)" fill="rgb(253, 214, 99)">
|
||||
<animateMotion path="M 800 -200 L 800 -300 L 800 -200" dur="20s" begin="0s" repeatCount="indefinite"/>
|
||||
<animateTransform attributeType="XML" attributeName="transform" begin="0s" dur="30s" type="rotate" values="0 210 530 ; -30 210 530 ; 0 210 530" keyTimes="0 ; 0.5 ; 1" repeatCount="indefinite"/>
|
||||
</path>
|
||||
|
||||
<circle cx="200" cy="150" r="20" stroke="#1a73e8" fill="#1a73e8">
|
||||
<animateMotion path="M 0 0 L 40 20 Z" dur="5s" repeatCount="indefinite"/>
|
||||
</circle>
|
||||
|
||||
<!-- 三角形 -->
|
||||
<path d="M 165 580 L 270 580 Q275 578 270 570 L 223 483 Q220 480 217 483 L 165 570 Q160 578 165 580" stroke="rgb(238, 103, 92)" fill="rgb(238, 103, 92)">
|
||||
<animateTransform attributeType="XML" attributeName="transform" begin="0s" dur="35s" type="rotate" from="0 210 530" to="360 210 530" repeatCount="indefinite"/>
|
||||
</path>
|
||||
|
||||
<circle cx="1200" cy="600" r="30" stroke="rgb(241, 243, 244)" fill="rgb(241, 243, 244)">
|
||||
<animateMotion path="M 0 0 L -20 40 Z" dur="9s" repeatCount="indefinite"/>
|
||||
</circle>
|
||||
|
||||
<path d="M 100 350 A 40 40 0 1 1 180 350 L 180 430 A 40 40 0 1 1 100 430 Z" stroke="rgb(241, 243, 244)" fill="rgb(241, 243, 244)">
|
||||
<animateMotion path="M 140 390 L 180 360 L 140 390" dur="20s" begin="0s" repeatCount="indefinite"/>
|
||||
<animateTransform attributeType="XML" attributeName="transform" begin="0s" dur="30s" type="rotate" values="0 140 390; -60 140 390; 0 140 390" keyTimes="0 ; 0.5 ; 1" repeatCount="indefinite"/>
|
||||
</path>
|
||||
|
||||
<rect x="400" y="600" rx="40" ry="40" width="100" height="100" stroke="rgb(129, 201, 149)" fill="rgb(129, 201, 149)">
|
||||
<animateTransform attributeType="XML" attributeName="transform" begin="0s" dur="35s" type="rotate" from="-30 550 750" to="330 550 750" repeatCount="indefinite"/>
|
||||
</rect>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
BIN
library/src/main/resources/static/img/login.81e3ef50.png
Normal file
BIN
library/src/main/resources/static/img/login.81e3ef50.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
1
library/src/main/resources/static/index.html
Normal file
1
library/src/main/resources/static/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>vue_demo</title><link href="/css/chunk-0ef1ccea.91552112.css" rel="prefetch"><link href="/css/chunk-1d2b6d9d.750ab8fd.css" rel="prefetch"><link href="/css/chunk-1e6a6472.a9697564.css" rel="prefetch"><link href="/css/chunk-752ac4fb.e53c3c2c.css" rel="prefetch"><link href="/js/chunk-0be195b0.11a9a989.js" rel="prefetch"><link href="/js/chunk-0ef1ccea.8151085a.js" rel="prefetch"><link href="/js/chunk-1d2b6d9d.13081618.js" rel="prefetch"><link href="/js/chunk-1e6a6472.ed80c125.js" rel="prefetch"><link href="/js/chunk-25f25a31.25ed3d91.js" rel="prefetch"><link href="/js/chunk-2d0c0df2.9b822a3f.js" rel="prefetch"><link href="/js/chunk-2d0c1074.8dbc50ec.js" rel="prefetch"><link href="/js/chunk-33419c76.697ed836.js" rel="prefetch"><link href="/js/chunk-6cd47659.348c5279.js" rel="prefetch"><link href="/js/chunk-6fecba8e.e1b4f3ca.js" rel="prefetch"><link href="/js/chunk-752ac4fb.b6d0ae67.js" rel="prefetch"><link href="/css/app.90e92dc6.css" rel="preload" as="style"><link href="/css/chunk-vendors.041c0013.css" rel="preload" as="style"><link href="/js/app.3d87220e.js" rel="preload" as="script"><link href="/js/chunk-vendors.c2943193.js" rel="preload" as="script"><link href="/css/chunk-vendors.041c0013.css" rel="stylesheet"><link href="/css/app.90e92dc6.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but vue_demo doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.c2943193.js"></script><script src="/js/app.3d87220e.js"></script></body></html>
|
||||
2
library/src/main/resources/static/js/app.3d87220e.js
Normal file
2
library/src/main/resources/static/js/app.3d87220e.js
Normal file
File diff suppressed because one or more lines are too long
1
library/src/main/resources/static/js/app.3d87220e.js.map
Normal file
1
library/src/main/resources/static/js/app.3d87220e.js.map
Normal file
File diff suppressed because one or more lines are too long
279
library/src/main/resources/static/js/chunk-0be195b0.11a9a989.js
Normal file
279
library/src/main/resources/static/js/chunk-0be195b0.11a9a989.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-1e6a6472"],{c714:function(e,t,o){},ce40:function(e,t,o){"use strict";o.r(t);var n=o("7a23"),r=Object(n["createElementVNode"])("h2",{style:{padding:"30px"}},"个人信息",-1),c={key:0,style:{margin:"5px"}},a={key:1,style:{margin:"5px"}},l=Object(n["createTextVNode"])("男"),u=Object(n["createTextVNode"])("女"),d={style:{"text-align":"center"}},i=Object(n["createTextVNode"])("保存");function f(e,t,o,f,m,s){var b=Object(n["resolveComponent"])("el-input"),O=Object(n["resolveComponent"])("el-form-item"),j=Object(n["resolveComponent"])("el-radio"),p=Object(n["resolveComponent"])("el-form"),V=Object(n["resolveComponent"])("el-button"),h=Object(n["resolveComponent"])("el-card");return Object(n["openBlock"])(),Object(n["createElementBlock"])("div",null,[Object(n["createVNode"])(h,{style:{width:"40%","margin-left":"120px","margin-top":"40px"}},{default:Object(n["withCtx"])((function(){return[r,Object(n["createVNode"])(p,{model:m.form,ref:"form","label-width":"80px"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(O,{label:"用户名"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,{style:{width:"80%"},modelValue:m.form.username,"onUpdate:modelValue":t[0]||(t[0]=function(e){return m.form.username=e}),disabled:""},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(O,{label:"姓名"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,{style:{width:"80%"},modelValue:m.form.nickName,"onUpdate:modelValue":t[1]||(t[1]=function(e){return m.form.nickName=e})},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(O,{label:"权限"},{default:Object(n["withCtx"])((function(){return[1==m.form.role?(Object(n["openBlock"])(),Object(n["createElementBlock"])("span",c,"管理员")):Object(n["createCommentVNode"])("",!0),2==m.form.role?(Object(n["openBlock"])(),Object(n["createElementBlock"])("span",a,"读者")):Object(n["createCommentVNode"])("",!0)]})),_:1}),Object(n["createVNode"])(O,{label:"电话号码"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,{style:{width:"80%"},modelValue:m.form.phone,"onUpdate:modelValue":t[2]||(t[2]=function(e){return m.form.phone=e})},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(O,{label:"性别"},{default:Object(n["withCtx"])((function(){return[Object(n["createElementVNode"])("div",null,[Object(n["createVNode"])(j,{modelValue:m.form.sex,"onUpdate:modelValue":t[3]||(t[3]=function(e){return m.form.sex=e}),label:"男"},{default:Object(n["withCtx"])((function(){return[l]})),_:1},8,["modelValue"]),Object(n["createVNode"])(j,{modelValue:m.form.sex,"onUpdate:modelValue":t[4]||(t[4]=function(e){return m.form.sex=e}),label:"女"},{default:Object(n["withCtx"])((function(){return[u]})),_:1},8,["modelValue"])])]})),_:1}),Object(n["createVNode"])(O,{label:"地址"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,{type:"textarea",style:{width:"80%"},modelValue:m.form.address,"onUpdate:modelValue":t[5]||(t[5]=function(e){return m.form.address=e})},null,8,["modelValue"])]})),_:1})]})),_:1},8,["model"]),Object(n["createElementVNode"])("div",d,[Object(n["createVNode"])(V,{type:"primary",onClick:s.update},{default:Object(n["withCtx"])((function(){return[i]})),_:1},8,["onClick"])])]})),_:1})])}o("e9c4");var m=o("b775"),s=o("3ef4"),b={name:"Person",data:function(){return{form:{}}},created:function(){var e=sessionStorage.getItem("user")||"{}";this.form=JSON.parse(e)},methods:{update:function(){var e=this;m["a"].put("/user",this.form).then((function(t){console.log(t),"0"===t.code?(s["a"].success("更新成功"),sessionStorage.setItem("user",JSON.stringify(e.form)),e.$emit("userInfo")):s["a"].error(t.msg)}))}}},O=(o("fe6f"),o("6b0d")),j=o.n(O);const p=j()(b,[["render",f]]);t["default"]=p},e9c4:function(e,t,o){var n=o("23e7"),r=o("da84"),c=o("d066"),a=o("2ba4"),l=o("e330"),u=o("d039"),d=r.Array,i=c("JSON","stringify"),f=l(/./.exec),m=l("".charAt),s=l("".charCodeAt),b=l("".replace),O=l(1..toString),j=/[\uD800-\uDFFF]/g,p=/^[\uD800-\uDBFF]$/,V=/^[\uDC00-\uDFFF]$/,h=function(e,t,o){var n=m(o,t-1),r=m(o,t+1);return f(p,e)&&!f(V,r)||f(V,e)&&!f(p,n)?"\\u"+O(s(e,0),16):e},N=u((function(){return'"\\udf06\\ud834"'!==i("\udf06\ud834")||'"\\udead"'!==i("\udead")}));i&&n({target:"JSON",stat:!0,forced:N},{stringify:function(e,t,o){for(var n=0,r=arguments.length,c=d(r);n<r;n++)c[n]=arguments[n];var l=a(i,null,c);return"string"==typeof l?b(l,j,h):l}})},fe6f:function(e,t,o){"use strict";o("c714")}}]);
|
||||
//# sourceMappingURL=chunk-1e6a6472.ed80c125.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0c1074"],{"43fe":function(e,t,r){"use strict";r.r(t);var o=r("7a23"),n=Object(o["createTextVNode"])("提交"),a=Object(o["createTextVNode"])("重置");function s(e,t,r,s,c,u){var l=Object(o["resolveComponent"])("el-input"),d=Object(o["resolveComponent"])("el-form-item"),i=Object(o["resolveComponent"])("el-button"),f=Object(o["resolveComponent"])("el-form"),p=Object(o["resolveComponent"])("el-card");return Object(o["openBlock"])(),Object(o["createElementBlock"])("div",null,[Object(o["createVNode"])(p,{style:{width:"40%","margin-left":"120px","margin-top":"40px"}},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(f,{ref:"form",model:c.form,"status-icon":"",rules:c.rules,"label-width":"100px",class:"demo-ruleForm"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(d,{label:"老密码",prop:"password2"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(l,{modelValue:c.form.password2,"onUpdate:modelValue":t[0]||(t[0]=function(e){return c.form.password2=e}),type:"password",autocomplete:"off"},null,8,["modelValue"])]})),_:1}),Object(o["createVNode"])(d,{label:"新密码",prop:"password"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(l,{modelValue:c.form2.password,"onUpdate:modelValue":t[1]||(t[1]=function(e){return c.form2.password=e}),type:"password",autocomplete:"off"},null,8,["modelValue"])]})),_:1}),Object(o["createVNode"])(d,{label:"确认新密码",prop:"checkpassword"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(l,{modelValue:c.form.checkpassword,"onUpdate:modelValue":t[2]||(t[2]=function(e){return c.form.checkpassword=e}),type:"password",autocomplete:"off"},null,8,["modelValue"])]})),_:1}),Object(o["createVNode"])(d,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(i,{type:"primary",onClick:u.submitForm,style:{"text-align":"center"}},{default:Object(o["withCtx"])((function(){return[n]})),_:1},8,["onClick"]),Object(o["createVNode"])(i,{onClick:t[3]||(t[3]=function(e){return u.resetForm("form")}),style:{"text-align":"center"}},{default:Object(o["withCtx"])((function(){return[a]})),_:1})]})),_:1})]})),_:1},8,["model","rules"])]})),_:1})])}var c=r("b775"),u=r("3ef4"),l={name:"Password",data:function(){var e=this,t=function(t,r,o){""==r?o(new Error("请输入老密码")):(e.form.password2!==e.form.truepassword&&o(new Error("密码错误")),o())},r=function(e,t,r){""===t?r(new Error("请输入新密码")):r()},o=function(t,r,o){""===r?o(new Error("请再次输入密码")):r!==e.form2.password?o(new Error("两次输入密码不匹配")):o()};return{form:{password2:"",checkpassword:"",truepassword:""},form2:{password:"",id:0},rules:{password:[{validator:r,trigger:"blur",required:!0}],checkpassword:[{validator:o,trigger:"blur",required:!0}],password2:[{validator:t,trigger:"blur",required:!0}]}}},created:function(){var e=JSON.parse(sessionStorage.getItem("user"));this.form.truepassword=e.password,this.form2.id=e.id},methods:{submitForm:function(){var e=this;this.$refs["form"].validate((function(t){t&&c["a"].put("/user",e.form2).then((function(t){0==t.code?(u["a"].success("密码修改成功,请重新登录"),sessionStorage.removeItem("user"),e.$router.push("/login")):u["a"].error(t.msg)}))}))},resetForm:function(e){this.$refs[e].resetFields()}}},d=r("6b0d"),i=r.n(d);const f=i()(l,[["render",s]]);t["default"]=f}}]);
|
||||
//# sourceMappingURL=chunk-2d0c1074.8dbc50ec.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user