├── img └── example.png ├── IDEAColor └── settings.jar ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── src ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── service │ │ │ ├── BookService.java │ │ │ ├── HotBookService.java │ │ │ ├── ArtService.java │ │ │ ├── CommentService.java │ │ │ ├── MovieService.java │ │ │ ├── MusicService.java │ │ │ ├── SentenceService.java │ │ │ ├── FlowService.java │ │ │ ├── UserService.java │ │ │ ├── FavorService.java │ │ │ └── Impl │ │ │ │ ├── HootBookServiceImpl.java │ │ │ │ ├── BookServiceImpl.java │ │ │ │ ├── MovieServiceImpl.java │ │ │ │ ├── MusicServiceImpl.java │ │ │ │ ├── SentenceServiceImpl.java │ │ │ │ ├── CommentServiceImpl.java │ │ │ │ ├── ArtServiceImpl.java │ │ │ │ ├── UserServiceImpl.java │ │ │ │ ├── FlowServiceImpl.java │ │ │ │ └── FavorServiceImpl.java │ │ │ ├── Dao │ │ │ ├── BookMapper.java │ │ │ ├── FlowMapper.java │ │ │ ├── UserMapper.java │ │ │ ├── FavorMapper.java │ │ │ ├── MusicMapper.java │ │ │ ├── CommentMapper.java │ │ │ ├── HotBookMapper.java │ │ │ ├── MovieMapper.java │ │ │ └── SentenceMapper.java │ │ │ ├── model │ │ │ ├── Movie.java │ │ │ ├── Sentence.java │ │ │ ├── Music.java │ │ │ ├── HotBook.java │ │ │ ├── Book.java │ │ │ ├── Comment.java │ │ │ ├── ArtBase.java │ │ │ ├── Flow.java │ │ │ ├── Favor.java │ │ │ └── User.java │ │ │ ├── utils │ │ │ ├── ResultUtils.java │ │ │ ├── Result.java │ │ │ ├── LocalUser.java │ │ │ ├── GlobalCors.java │ │ │ ├── RequestHelper.java │ │ │ ├── WxManager.java │ │ │ ├── Encryption.java │ │ │ └── TokenUtils.java │ │ │ ├── annotation │ │ │ └── AuthToken.java │ │ │ ├── exception │ │ │ ├── HttpException.java │ │ │ ├── AuthFailed.java │ │ │ ├── Success.java │ │ │ ├── Forbidden.java │ │ │ ├── NotFound.java │ │ │ └── GlobalException.java │ │ │ ├── DemoApplication.java │ │ │ ├── config │ │ │ └── wx.java │ │ │ ├── controller │ │ │ └── v1 │ │ │ │ ├── TestController.java │ │ │ │ ├── LikeController.java │ │ │ │ ├── UserController.java │ │ │ │ ├── TokenController.java │ │ │ │ ├── ClassicController.java │ │ │ │ └── BookController.java │ │ │ └── AOP │ │ │ └── aop.java │ └── resources │ │ └── application.yml └── test │ └── java │ └── com │ └── example │ └── demo │ └── DemoApplicationTests.java ├── README.md ├── .gitignore ├── LICENSE ├── pom.xml ├── mvnw.cmd ├── mvnw └── sql └── island-java.sql /img/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/towelong/island-java/HEAD/img/example.png -------------------------------------------------------------------------------- /IDEAColor/settings.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/towelong/island-java/HEAD/IDEAColor/settings.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/towelong/island-java/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | /** 4 | * @Author WeLong 5 | * @create 2019/10/27 14:36 6 | */ 7 | public interface BookService { 8 | void updateData(int art_id); 9 | void deleteData(int art_id); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/BookMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Book; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/27 13:10 9 | */ 10 | public interface BookMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/FlowMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Flow; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 19:06 9 | */ 10 | public interface FlowMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.User; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 12:32 9 | */ 10 | public interface UserMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/FavorMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Favor; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 23:29 9 | */ 10 | public interface FavorMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/MusicMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Music; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:27 9 | */ 10 | public interface MusicMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/CommentMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Comment; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/27 16:02 9 | */ 10 | public interface CommentMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/HotBookMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.HotBook; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/27 12:15 9 | */ 10 | public interface HotBookMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/MovieMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Movie; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:28 9 | */ 10 | public interface MovieMapper extends BaseMapper { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/HotBookService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | 4 | import com.example.demo.model.HotBook; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @Author WeLong 10 | * @create 2019/10/27 12:14 11 | */ 12 | public interface HotBookService { 13 | 14 | List getAll(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Dao/SentenceMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.Dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.demo.model.Sentence; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:27 9 | */ 10 | public interface SentenceMapper extends BaseMapper { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Movie.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:15 9 | */ 10 | @Data 11 | @TableName(value = "movie") 12 | public class Movie extends ArtBase { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # island-java 2 | 3 | 4 | 5 | > 根据慕课网课程:从0到1手把手教你用Node.js+KOA2打造超好用的Web框架 6 | > 7 | > 根据旧岛小样koa2服务端的API文档重构,已完成所有接口的编写 8 | 9 | 10 | 11 | ![example](https://raw.githubusercontent.com/ToWeLong/island-java/master/img/example.png) 12 | 13 | - [x] 微信登录 14 | - [x] 完成所有接口测试以及编写 15 | - [x] 欢迎学习交流 16 | 17 | 2019年10月29日20:08:49 18 | 已完成所有接口的编写 -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Sentence.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:16 9 | */ 10 | @Data 11 | @TableName(value = "sentence") 12 | public class Sentence extends ArtBase { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/ArtService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 22:15 8 | */ 9 | public interface ArtService { 10 | 11 | Object getData(int art_id, int type); 12 | void updataData(int art_id, int type); 13 | void deleteData(int art_id, int type); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Music.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 20:16 9 | */ 10 | @Data 11 | @TableName(value = "music") 12 | public class Music extends ArtBase { 13 | 14 | private String url; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Comment; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @Author WeLong 9 | * @create 2019/10/27 16:02 10 | */ 11 | public interface CommentService { 12 | void add(Comment comment); 13 | Map getComment(int book_id); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | url: jdbc:mysql://localhost:3306/island-java?useSSL=false&serverTimezone=GMT%2B8 5 | username: root 6 | password: password 7 | #logging: 8 | # level: 9 | # root: warn 10 | # com.example.demo.Dao: trace 11 | # pattern: 12 | # console: '%p%m%n' 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/MovieService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Movie; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 20:51 8 | */ 9 | public interface MovieService { 10 | Object getData(int art_id,int type); 11 | void updataData(int art_id, int type); 12 | void deleteData(int art_id, int type); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/MusicService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Music; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 20:51 8 | */ 9 | public interface MusicService { 10 | 11 | Object getData(int art_id, int type); 12 | void updataData(int art_id, int type); 13 | void deleteData(int art_id, int type); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | /** 4 | * @Author WeLong 5 | * @create 2019/10/23 11:38 6 | */ 7 | public class ResultUtils { 8 | 9 | public static Result success(T msg) { 10 | Result result = new Result(); 11 | result.setMsg(msg); 12 | result.setCode(0); 13 | return result; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/SentenceService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Sentence; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 20:51 8 | */ 9 | public interface SentenceService { 10 | Object getData(int art_id, int type); 11 | void updataData(int art_id, int type); 12 | void deleteData(int art_id, int type); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/annotation/AuthToken.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/21 16:41 8 | */ 9 | 10 | @Target({ElementType.METHOD, ElementType.TYPE}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface AuthToken { 14 | String[] role_name() default "user"; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/FlowService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | 4 | import com.example.demo.model.Flow; 5 | 6 | 7 | /** 8 | * @Author WeLong 9 | * @create 2019/10/25 19:07 10 | */ 11 | public interface FlowService { 12 | Object findLastest(); 13 | Object findNext(int indexs); 14 | Object findLast(int index); 15 | Object findDetail(int type,int id); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/HttpException.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import com.example.demo.utils.RequestHelper; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/23 10:01 9 | */ 10 | @Data 11 | public class HttpException extends RuntimeException { 12 | 13 | 14 | private String msg; 15 | private int code; 16 | private String request = RequestHelper.getRequestUrl(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/HotBook.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/27 12:12 9 | */ 10 | @Data 11 | public class HotBook { 12 | private int id; 13 | @JsonProperty("index") 14 | private int indexs; 15 | private String image; 16 | private String author; 17 | private String title; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/AuthFailed.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/23 13:04 8 | */ 9 | @Data 10 | public class AuthFailed extends HttpException{ 11 | private String msg = "无权限访问"; 12 | private int code = -2; 13 | 14 | public AuthFailed(String msg) { 15 | this.msg = msg; 16 | } 17 | public AuthFailed() { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/Success.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 11:30 9 | */ 10 | 11 | @Data 12 | @NoArgsConstructor 13 | public class Success extends HttpException { 14 | private int code = 0; 15 | private String msg = "请求成功"; 16 | public Success(String msg){ 17 | this.msg = msg; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/Forbidden.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 14:22 8 | */ 9 | @Data 10 | public class Forbidden extends HttpException { 11 | 12 | private String msg = "资源已存在"; 13 | private int code = 10001; 14 | 15 | public Forbidden(String msg) { 16 | this.msg = msg; 17 | } 18 | public Forbidden() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/NotFound.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/23 10:05 8 | */ 9 | 10 | @Data 11 | public class NotFound extends HttpException { 12 | 13 | private String msg = "资源不存在"; 14 | private int code = 999; 15 | 16 | public NotFound(String msg) { 17 | this.msg = msg; 18 | } 19 | public NotFound() { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/Result.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/23 9:48 8 | */ 9 | @Data 10 | public class Result { 11 | private int code = 0; 12 | private String url = RequestHelper.getRequestUrl(); 13 | private T msg; 14 | 15 | public Result() { 16 | 17 | } 18 | public Result( T msg) { 19 | this.msg = msg; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.amdelamar.jhash.exception.InvalidHashException; 4 | import com.example.demo.model.User; 5 | 6 | /** 7 | * @Author WeLong 8 | * @create 2019/10/25 13:31 9 | */ 10 | public interface UserService { 11 | void createUser(User user); 12 | User findByNickname(String nickname); 13 | String verifyUser(User user) throws InvalidHashException; 14 | long createMiniUser(String openid); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan("com.example.demo.Dao") 9 | public class DemoApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DemoApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/config/wx.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @作者 WeLong 3 | * @博客 $ https://towelong.cn 4 | * @开源项目 $ https://github.com/ToWeLong 5 | * @创建时间 2019/10/28 21:59 6 | */ 7 | package com.example.demo.config; 8 | 9 | public class wx { 10 | final String appId = "wxe8eff559addc1195"; 11 | final String appSecret = "0633f8f1e0ea552f12a97316b37a5785"; 12 | 13 | public String getAppId() { 14 | return appId; 15 | } 16 | 17 | public String getAppSecret() { 18 | return appSecret; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | import lombok.Data; 8 | 9 | /** 10 | * @Author WeLong 11 | * @create 2019/10/27 13:06 12 | */ 13 | @TableName(value = "book") 14 | @Data 15 | public class Book { 16 | private int id; 17 | @JsonProperty(value = "fav_nums") 18 | private int favNums=0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/FavorService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Favor; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * @Author WeLong 10 | * @create 2019/10/25 23:30 11 | */ 12 | public interface FavorService { 13 | 14 | void like(Favor favor); 15 | void dislike(Favor favor); 16 | boolean userLikeIt(int art_id,int type); 17 | Object getLikeInfo(int art_id,int type); 18 | List getfindMyFavor(); 19 | int selectMyFavorBook(); 20 | Map findBookLike(int book_id); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/LocalUser.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | import com.example.demo.model.User; 4 | 5 | /** 6 | * @Author WeLong 7 | * @create 2019/10/25 15:01 8 | */ 9 | public class LocalUser { 10 | private static ThreadLocal local = new ThreadLocal<>(); 11 | 12 | public static User getLocalUser() { 13 | return LocalUser.local.get(); 14 | } 15 | 16 | public static void setLocalUser(User user) { 17 | LocalUser.local.set(user); 18 | } 19 | 20 | public static T getLocalUser(Class clazz) { 21 | return (T) local.get(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/GlobalCors.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @Author WeLong 9 | * @create 2019/10/24 12:43 10 | */ 11 | 12 | @Configuration 13 | public class GlobalCors implements WebMvcConfigurer { 14 | @Override 15 | public void addCorsMappings(CorsRegistry registry) { 16 | registry.addMapping("/**") 17 | .allowedOrigins("*") 18 | .allowCredentials(true) 19 | .allowedMethods("GET", "POST", "PUT", "DELETE") 20 | .maxAge(3600); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/HootBookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | import com.example.demo.Dao.HotBookMapper; 4 | import com.example.demo.model.HotBook; 5 | import com.example.demo.service.HotBookService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @Author WeLong 13 | * @create 2019/10/27 12:16 14 | */ 15 | @Service 16 | public class HootBookServiceImpl implements HotBookService { 17 | 18 | @Autowired 19 | HotBookMapper hotBookMapper; 20 | @Override 21 | public List getAll(){ 22 | List hotBooks = hotBookMapper.selectList(null); 23 | return hotBooks; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/RequestHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | import org.springframework.web.context.request.RequestContextHolder; 4 | import org.springframework.web.context.request.ServletRequestAttributes; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * @Author WeLong 10 | * @create 2019/10/23 10:33 11 | */ 12 | public class RequestHelper { 13 | 14 | public static HttpServletRequest getRequest() { 15 | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 16 | return request; 17 | } 18 | public static String getRequestUrl() { 19 | String methods = getRequest().getMethod(); 20 | return methods+" "+getRequest().getServletPath(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Comment.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import lombok.Data; 9 | 10 | import javax.validation.constraints.Min; 11 | 12 | /** 13 | * @Author WeLong 14 | * @create 2019/10/27 15:58 15 | */ 16 | @Data 17 | @TableName(value = "comment") 18 | public class Comment { 19 | @TableId(type = IdType.AUTO) 20 | @JsonIgnore 21 | private int id; 22 | private String content; 23 | private int nums=0; 24 | 25 | @JsonProperty("book_id") 26 | @Min(value = 1,message = "book_id必须为正整数") 27 | @JsonIgnore 28 | private int bookId; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/TestController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @作者 WeLong 3 | * @博客 $ https://towelong.cn 4 | * @开源项目 $ https://github.com/ToWeLong 5 | * @创建时间 2019/10/30 12:27 6 | */ 7 | package com.example.demo.controller.v1; 8 | 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | import java.util.Map; 15 | 16 | @ResponseBody 17 | @RestController 18 | public class TestController { 19 | 20 | @PostMapping("/test") 21 | public String test(@RequestBody Map map) { 22 | String code = map.get("code").toString(); 23 | String type = map.get("type").toString(); 24 | int t = Integer.parseInt(type); 25 | return "code:" + code + ",type:" + t; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/WxManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @作者 WeLong 3 | * @博客 $ https://towelong.cn 4 | * @开源项目 $ https://github.com/ToWeLong 5 | * @创建时间 2019/10/28 19:51 6 | */ 7 | package com.example.demo.utils; 8 | 9 | import com.alibaba.fastjson.JSON; 10 | import com.alibaba.fastjson.JSONObject; 11 | import com.example.demo.config.wx; 12 | import org.springframework.web.client.RestTemplate; 13 | 14 | public class WxManager { 15 | public static String getOpenId(String code) { 16 | RestTemplate restTemplate = new RestTemplate(); 17 | wx wxs = new wx(); 18 | String url = "https://api.weixin.qq.com/sns/jscode2session?appid={appId}&secret={appSecret}&js_code={code}&grant_type=authorization_code"; 19 | String appId = wxs.getAppId(); 20 | String appSecret = wxs.getAppSecret(); 21 | String result = restTemplate.getForObject(url,String.class,appId,appSecret,code); 22 | JSONObject jsonObject = JSON.parseObject(result); 23 | String openId = jsonObject.get("openid").toString(); 24 | return openId; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 WeLong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/ArtBase.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import lombok.Data; 9 | 10 | import java.time.LocalDateTime; 11 | import java.util.Date; 12 | 13 | /** 14 | * @Author WeLong 15 | * @create 2019/10/25 20:17 16 | */ 17 | 18 | @Data 19 | public class ArtBase { 20 | 21 | private String image; 22 | private String title; 23 | @JSONField(format = "yyyy-MM-dd") 24 | private Date pubdate; 25 | private String content; 26 | @JSONField(name = "fav_nums") 27 | @JsonProperty("fav_nums") 28 | private int favNums; 29 | private int type; 30 | @TableId(type = IdType.AUTO) 31 | private int id; 32 | 33 | @JsonIgnore 34 | private LocalDateTime createdAt; 35 | 36 | 37 | @JsonIgnore 38 | private LocalDateTime updatedAt; 39 | 40 | @JsonIgnore 41 | private LocalDateTime deletedAt; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Flow.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import lombok.Data; 9 | 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * @Author WeLong 14 | * @create 2019/10/25 19:01 15 | */ 16 | 17 | @Data 18 | @TableName(value = "flow") 19 | public class Flow { 20 | private int indexs; 21 | @JSONField(name = "ard_id") 22 | @JsonProperty("art_id") 23 | private int artId; 24 | private int type; 25 | @TableId(value = "id",type = IdType.AUTO) 26 | private int id; 27 | @JSONField(deserialize = false) 28 | private int status; 29 | @JSONField(deserialize = false,name = "created_at") 30 | private LocalDateTime createdAt; 31 | @JSONField(deserialize = false,name = "updated_at") 32 | private LocalDateTime updatedAt; 33 | @JSONField(deserialize = false,name = "deleted_at") 34 | private LocalDateTime deletedAt; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/Encryption.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | import com.amdelamar.jhash.Hash; 4 | import com.amdelamar.jhash.algorithms.Type; 5 | import com.amdelamar.jhash.exception.InvalidHashException; 6 | 7 | /** 8 | * @Author WeLong 9 | * @create 2019/10/24 19:37 10 | */ 11 | public class Encryption { 12 | 13 | 14 | /** 15 | * 16 | * @param str 17 | * @return cryptPassword 18 | */ 19 | public static String crypt(String str) { 20 | char[] password = str.toCharArray(); 21 | String cryptPassword = Hash.password(password).algorithm(Type.BCRYPT).create(); 22 | return cryptPassword; 23 | } 24 | 25 | 26 | /** 27 | * 28 | * @param password 29 | * @param cryptPassword 30 | * @return boolean 31 | * @throws InvalidHashException 32 | */ 33 | public static boolean encrypt(String password,String cryptPassword) throws InvalidHashException { 34 | char[] chars = password.toCharArray(); 35 | if(Hash.password(chars).verify(cryptPassword)){ 36 | return true; 37 | }else{ 38 | return false; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Favor.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import lombok.Data; 9 | 10 | import javax.validation.constraints.Min; 11 | import java.time.LocalDateTime; 12 | 13 | /** 14 | * @Author WeLong 15 | * @create 2019/10/25 23:13 16 | */ 17 | @Data 18 | public class Favor { 19 | @TableId(type = IdType.AUTO) 20 | private int id; 21 | 22 | private int uid; 23 | 24 | @Min(value = 0,message = "art_id只能为整数") 25 | @JSONField(name = "art_id") 26 | @JsonProperty("art_id") 27 | private int artId; 28 | @Min(value = 0,message = "type只能为整数") 29 | private int type; 30 | 31 | @JSONField(name = "created_at",serialize = false) 32 | @JsonIgnore 33 | private LocalDateTime createdAt; 34 | 35 | @JSONField(name = "updated_at",serialize = false) 36 | @JsonIgnore 37 | private LocalDateTime updatedAt; 38 | 39 | @JSONField(name = "deleted_at",serialize = false) 40 | @JsonIgnore 41 | private LocalDateTime deletedAt; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/LikeController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller.v1; 2 | 3 | import com.example.demo.annotation.AuthToken; 4 | import com.example.demo.exception.Success; 5 | import com.example.demo.model.Favor; 6 | import com.example.demo.service.FavorService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.validation.annotation.Validated; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * @Author WeLong 16 | * @create 2019/10/25 23:46 17 | */ 18 | @RestController 19 | @RequestMapping("/v1/like") 20 | public class LikeController { 21 | 22 | @Autowired 23 | FavorService favorService; 24 | 25 | @PostMapping("/add") 26 | @AuthToken 27 | public void like(@RequestBody @Validated Favor favor) { 28 | favorService.like(favor); 29 | throw new Success("点赞成功!"); 30 | } 31 | 32 | @PostMapping("/cancel") 33 | @AuthToken 34 | public void dislike(@RequestBody @Validated Favor favor) { 35 | favorService.dislike(favor); 36 | throw new Success("取消点赞成功!"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller.v1; 2 | 3 | 4 | import com.amdelamar.jhash.exception.InvalidHashException; 5 | import com.example.demo.exception.Forbidden; 6 | import com.example.demo.model.User; 7 | import com.example.demo.service.UserService; 8 | import com.example.demo.utils.Result; 9 | import com.example.demo.utils.ResultUtils; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.validation.annotation.Validated; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | 18 | /** 19 | * @Author WeLong 20 | * @create 2019/10/24 20:10 21 | */ 22 | 23 | @RestController 24 | @ResponseBody 25 | @RequestMapping("/v1/user") 26 | public class UserController { 27 | 28 | @Autowired 29 | UserService userService; 30 | 31 | @PostMapping("/register") 32 | @ResponseBody 33 | public Result create(@RequestBody @Validated User user) { 34 | if(user.getType()!=100){ 35 | throw new Forbidden("登录类型不存在"); 36 | } 37 | userService.createUser(user); 38 | return ResultUtils.success("注册成功!"); 39 | } 40 | 41 | @PostMapping("/login") 42 | @ResponseBody 43 | public Map login(@RequestBody @Validated User user) throws InvalidHashException { 44 | String token = userService.verifyUser(user); 45 | Map map = new HashMap(); 46 | map.put("token",token); 47 | return map; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/TokenController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @作者 WeLong 3 | * @博客 $ https://towelong.cn 4 | * @开源项目 $ https://github.com/ToWeLong 5 | * @创建时间 2019/10/28 22:32 6 | */ 7 | package com.example.demo.controller.v1; 8 | 9 | import com.example.demo.exception.Forbidden; 10 | import com.example.demo.model.User; 11 | import com.example.demo.service.UserService; 12 | import com.example.demo.utils.TokenUtils; 13 | import com.example.demo.utils.WxManager; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | @RestController 21 | @RequestMapping("/v1") 22 | public class TokenController { 23 | 24 | @Autowired 25 | UserService userService; 26 | 27 | @PostMapping("/token") 28 | public Map getToken(@RequestBody User user){ 29 | Map map = new HashMap(); 30 | int type =user.getType(); 31 | if(type != 200){ 32 | throw new Forbidden("类型不存在"); 33 | } 34 | String account = user.getAccount(); 35 | String openId = WxManager.getOpenId(account); 36 | long uid = userService.createMiniUser(openId); 37 | TokenUtils tokenUtils = new TokenUtils(); 38 | String token = tokenUtils.CreateToken(uid,16); 39 | map.put("token",token); 40 | return map; 41 | } 42 | @PostMapping("/token/verify") 43 | public Map verifyToken(@RequestBody User user){ 44 | TokenUtils tokenUtils = new TokenUtils(); 45 | Map map = new HashMap(); 46 | map.put("result",tokenUtils.VerifyToken(user.getToken())); 47 | return map; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.example.demo.Dao.BookMapper; 6 | import com.example.demo.exception.NotFound; 7 | import com.example.demo.model.Book; 8 | import com.example.demo.service.BookService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * @Author WeLong 14 | * @create 2019/10/27 14:37 15 | */ 16 | @Service 17 | public class BookServiceImpl implements BookService { 18 | @Autowired 19 | BookMapper bookMapper; 20 | 21 | public void updateData(int art_id){ 22 | QueryWrapper bookQueryWrapper = new QueryWrapper<>(); 23 | bookQueryWrapper.eq("id",art_id); 24 | Book book = bookMapper.selectOne(bookQueryWrapper); 25 | if(book==null){ 26 | Book b = new Book(); 27 | b.setId(art_id); 28 | b.setFavNums(1); 29 | bookMapper.insert(b); 30 | }else{ 31 | Book books = new Book(); 32 | books.setFavNums(book.getFavNums()+1); 33 | bookMapper.update(books,bookQueryWrapper); 34 | } 35 | } 36 | 37 | public void deleteData(int art_id){ 38 | QueryWrapper bookQueryWrapper = new QueryWrapper<>(); 39 | bookQueryWrapper.eq("id",art_id); 40 | Book book = bookMapper.selectOne(bookQueryWrapper); 41 | if(book!=null){ 42 | Book books = new Book(); 43 | books.setId(art_id); 44 | books.setFavNums(book.getFavNums()-1); 45 | bookMapper.update(books,bookQueryWrapper); 46 | }else { 47 | throw new NotFound(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/MovieServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.example.demo.Dao.MovieMapper; 6 | import com.example.demo.model.Movie; 7 | import com.example.demo.service.MovieService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @Author WeLong 13 | * @create 2019/10/25 20:55 14 | */ 15 | @Service 16 | public class MovieServiceImpl implements MovieService{ 17 | @Autowired 18 | MovieMapper movieMapper; 19 | 20 | @Override 21 | public Object getData(int art_id, int type){ 22 | QueryWrapper movieQueryWrapper = new QueryWrapper<>(); 23 | movieQueryWrapper.eq("id",art_id).eq("type",type); 24 | Movie art = movieMapper.selectOne(movieQueryWrapper); 25 | return art; 26 | } 27 | 28 | @Override 29 | public void updataData(int art_id, int type){ 30 | QueryWrapper movieQueryWrapper = new QueryWrapper<>(); 31 | movieQueryWrapper.eq("id",art_id).eq("type",type); 32 | Movie art = movieMapper.selectOne(movieQueryWrapper); 33 | Movie movie = new Movie(); 34 | movie.setFavNums(art.getFavNums()+1); 35 | movie.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 36 | movieMapper.update(movie,movieQueryWrapper); 37 | } 38 | 39 | @Override 40 | public void deleteData(int art_id, int type){ 41 | QueryWrapper movieQueryWrapper = new QueryWrapper<>(); 42 | movieQueryWrapper.eq("id",art_id).eq("type",type); 43 | Movie art = movieMapper.selectOne(movieQueryWrapper); 44 | Movie movie = new Movie(); 45 | movie.setFavNums(art.getFavNums()-1); 46 | movie.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 47 | movieMapper.update(movie,movieQueryWrapper); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/MusicServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.example.demo.Dao.MusicMapper; 6 | import com.example.demo.model.Music; 7 | import com.example.demo.service.MusicService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @Author WeLong 13 | * @create 2019/10/25 20:56 14 | */ 15 | @Service 16 | public class MusicServiceImpl implements MusicService { 17 | 18 | @Autowired 19 | MusicMapper musicMapper; 20 | 21 | @Override 22 | public Object getData(int art_id, int type){ 23 | QueryWrapper musicQueryWrapper = new QueryWrapper<>(); 24 | musicQueryWrapper.eq("id",art_id).eq("type",type); 25 | Music art = musicMapper.selectOne(musicQueryWrapper); 26 | return art; 27 | } 28 | 29 | @Override 30 | public void updataData(int art_id, int type){ 31 | QueryWrapper musicQueryWrapper = new QueryWrapper<>(); 32 | musicQueryWrapper.eq("id",art_id).eq("type",type); 33 | Music art = musicMapper.selectOne(musicQueryWrapper); 34 | Music music = new Music(); 35 | music.setFavNums(art.getFavNums()+1); 36 | music.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 37 | musicMapper.update(music,musicQueryWrapper); 38 | } 39 | 40 | @Override 41 | public void deleteData(int art_id, int type){ 42 | QueryWrapper musicQueryWrapper = new QueryWrapper<>(); 43 | musicQueryWrapper.eq("id",art_id).eq("type",type); 44 | Music art = musicMapper.selectOne(musicQueryWrapper); 45 | Music music = new Music(); 46 | music.setFavNums(art.getFavNums()-1); 47 | music.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 48 | musicMapper.update(music,musicQueryWrapper); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/SentenceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.example.demo.Dao.SentenceMapper; 6 | import com.example.demo.model.Sentence; 7 | import com.example.demo.service.SentenceService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @Author WeLong 13 | * @create 2019/10/25 20:56 14 | */ 15 | @Service 16 | public class SentenceServiceImpl implements SentenceService { 17 | @Autowired 18 | SentenceMapper sentenceMapper; 19 | 20 | @Override 21 | public Object getData(int art_id,int type){ 22 | QueryWrapper sentenceQueryWrapper = new QueryWrapper<>(); 23 | sentenceQueryWrapper.eq("id",art_id).eq("type",type); 24 | Sentence art = sentenceMapper.selectOne(sentenceQueryWrapper); 25 | return art; 26 | } 27 | 28 | @Override 29 | public void updataData(int art_id, int type){ 30 | QueryWrapper sentenceQueryWrapper = new QueryWrapper<>(); 31 | sentenceQueryWrapper.eq("id",art_id).eq("type",type); 32 | Sentence art = sentenceMapper.selectOne(sentenceQueryWrapper); 33 | Sentence sentence = new Sentence(); 34 | sentence.setFavNums(art.getFavNums()+1); 35 | sentence.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 36 | sentenceMapper.update(sentence,sentenceQueryWrapper); 37 | } 38 | 39 | @Override 40 | public void deleteData(int art_id, int type){ 41 | QueryWrapper sentenceQueryWrapper = new QueryWrapper<>(); 42 | sentenceQueryWrapper.eq("id",art_id).eq("type",type); 43 | Sentence art = sentenceMapper.selectOne(sentenceQueryWrapper); 44 | Sentence sentence = new Sentence(); 45 | sentence.setFavNums(art.getFavNums()-1); 46 | sentence.setType(art.getType()); // 留个疑问,更新操作时,type会被赋值为0 47 | sentenceMapper.update(sentence,sentenceQueryWrapper); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/CommentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.example.demo.Dao.CommentMapper; 5 | import com.example.demo.exception.NotFound; 6 | import com.example.demo.model.Comment; 7 | import com.example.demo.service.CommentService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * @Author WeLong 18 | * @create 2019/10/27 16:03 19 | */ 20 | @Service 21 | public class CommentServiceImpl implements CommentService { 22 | @Autowired 23 | CommentMapper commentMapper; 24 | 25 | @Override 26 | public void add(Comment comment){ 27 | QueryWrapper commentQueryWrapper = new QueryWrapper<>(); 28 | String content = comment.getContent(); 29 | commentQueryWrapper.eq("content",content).eq("book_id",comment.getBookId()); 30 | Comment exit = commentMapper.selectOne(commentQueryWrapper); 31 | if(exit != null){ 32 | exit.setNums(exit.getNums()+1); 33 | commentMapper.update(exit,commentQueryWrapper); 34 | } 35 | else { 36 | comment.setBookId(comment.getBookId()); 37 | comment.setContent(comment.getContent()); 38 | comment.setNums(1); 39 | commentMapper.insert(comment); 40 | } 41 | } 42 | 43 | @Override 44 | public Map getComment(int book_id){ 45 | QueryWrapper commentQueryWrapper = new QueryWrapper<>(); 46 | commentQueryWrapper.eq("book_id",book_id); 47 | Comment exit = commentMapper.selectOne(commentQueryWrapper); 48 | if(exit == null){ 49 | throw new NotFound(); 50 | } 51 | Map map = new HashMap(); 52 | List list = new ArrayList(); 53 | list.add(exit); 54 | map.put("book_id",book_id); 55 | map.put("comment",list); 56 | return map; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.amdelamar.jhash.Hash; 5 | import com.amdelamar.jhash.algorithms.Type; 6 | import com.amdelamar.jhash.exception.InvalidHashException; 7 | import com.baomidou.mybatisplus.annotation.IdType; 8 | import com.baomidou.mybatisplus.annotation.TableField; 9 | import com.baomidou.mybatisplus.annotation.TableId; 10 | import com.baomidou.mybatisplus.annotation.TableName; 11 | import com.fasterxml.jackson.annotation.JsonProperty; 12 | import lombok.Data; 13 | 14 | import javax.validation.constraints.NotEmpty; 15 | import java.time.LocalDateTime; 16 | import java.util.Date; 17 | 18 | /** 19 | * @Author WeLong 20 | * @create 2019/10/21 18:38 21 | */ 22 | @Data 23 | @TableName(value = "user") 24 | public class User { 25 | @TableId(value = "id",type = IdType.AUTO) 26 | private Long id; 27 | private String nickname; 28 | private String email; 29 | private String password; 30 | private String openid; 31 | @TableField(exist = false) 32 | private int type; 33 | @TableField(exist = false) 34 | private String account; 35 | @TableField(exist = false) 36 | private String token; 37 | 38 | @JSONField(name = "created_at") 39 | @JsonProperty("created_at") 40 | private LocalDateTime createdAt; 41 | @JSONField(name = "updated_at") 42 | @JsonProperty("updated_at") 43 | private LocalDateTime updatedAt; 44 | @JSONField(name = "deleted_at") 45 | @JsonProperty("deleted_at") 46 | private LocalDateTime deletedAt; 47 | 48 | 49 | /** 50 | * 设置密文密码 51 | * 52 | * @param password 原始密码 53 | */ 54 | public void setPasswordEncrypt(String password) { 55 | char[] chars = password.toCharArray(); 56 | this.password = Hash.password(chars).algorithm(Type.PBKDF2_SHA256).create(); 57 | } 58 | 59 | /** 60 | * 验证加密密码 61 | * 62 | * @param password 密文密码 63 | * @return valid 64 | */ 65 | public boolean verify(String password) { 66 | char[] chars = password.toCharArray(); 67 | try { 68 | return Hash.password(chars).verify(this.password); 69 | } catch (InvalidHashException e) { 70 | return false; 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/ArtServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | import com.example.demo.exception.NotFound; 4 | import com.example.demo.service.*; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @Author WeLong 11 | * @create 2019/10/25 20:11 12 | */ 13 | @Service 14 | public class ArtServiceImpl implements ArtService { 15 | @Autowired 16 | MovieService movieService; 17 | @Autowired 18 | MusicService musicService; 19 | @Autowired 20 | SentenceService sentenceService; 21 | @Autowired 22 | BookService bookService; 23 | 24 | @Override 25 | public Object getData(int art_id, int type){ 26 | switch (type){ 27 | case 100: 28 | return movieService.getData(art_id,type); 29 | case 200: 30 | return musicService.getData(art_id,type); 31 | case 300: 32 | return sentenceService.getData(art_id,type); 33 | case 400: 34 | break; 35 | default: 36 | throw new NotFound("资源未找到"); 37 | } 38 | throw new NotFound("资源未找到"); 39 | } 40 | 41 | @Override 42 | public void updataData(int art_id, int type){ 43 | switch (type){ 44 | case 100: 45 | movieService.updataData(art_id,type); 46 | break; 47 | case 200: 48 | musicService.updataData(art_id,type); 49 | break; 50 | case 300: 51 | sentenceService.updataData(art_id,type); 52 | break; 53 | case 400: 54 | bookService.updateData(art_id); 55 | break; 56 | default: 57 | throw new NotFound("点赞失败!"); 58 | } 59 | } 60 | 61 | @Override 62 | public void deleteData(int art_id, int type){ 63 | switch (type){ 64 | case 100: 65 | movieService.deleteData(art_id,type); 66 | break; 67 | case 200: 68 | musicService.deleteData(art_id,type); 69 | break; 70 | case 300: 71 | sentenceService.deleteData(art_id,type); 72 | break; 73 | case 400: 74 | bookService.deleteData(art_id); 75 | break; 76 | default: 77 | throw new NotFound("取消点赞失败!"); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/ClassicController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller.v1; 2 | 3 | 4 | import com.example.demo.annotation.AuthToken; 5 | import com.example.demo.service.FavorService; 6 | import com.example.demo.service.FlowService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.validation.annotation.Validated; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.constraints.Min; 12 | import java.util.List; 13 | 14 | /** 15 | * @Author WeLong 16 | * @create 2019/10/25 19:17 17 | */ 18 | 19 | @RestController 20 | @RequestMapping("/v1/classic") 21 | public class ClassicController { 22 | 23 | @Autowired 24 | FlowService flowService; 25 | 26 | @Autowired 27 | FavorService favorService; 28 | 29 | @GetMapping("/latest") 30 | @AuthToken 31 | @ResponseBody 32 | public Object findLatest(){ 33 | return flowService.findLastest(); 34 | } 35 | 36 | @GetMapping("/{index}/next") 37 | @AuthToken 38 | @ResponseBody 39 | public Object findNext(@Validated @Min(value = 1,message = "index必须为整数") @PathVariable int index){ 40 | return flowService.findNext(index); 41 | } 42 | 43 | @GetMapping("/{index}/previous") 44 | @AuthToken 45 | @ResponseBody 46 | public Object findLast(@Validated @Min(value = 1,message = "index必须为整数") @PathVariable int index){ 47 | return flowService.findLast(index); 48 | } 49 | 50 | @GetMapping("/{type}/{id}") 51 | @AuthToken 52 | @ResponseBody 53 | public Object findDetail(@Validated 54 | @Min(value = 1,message = "index必须为正整数") 55 | @PathVariable int type, 56 | @Min(value = 1,message = "id必须为正整数") 57 | @PathVariable int id){ 58 | return flowService.findDetail(type,id); 59 | } 60 | @GetMapping("/{type}/{id}/favor") 61 | @AuthToken 62 | @ResponseBody 63 | public Object findFavor(@Validated 64 | @Min(value = 1,message = "index必须为正整数") 65 | @PathVariable int type, 66 | @Min(value = 1,message = "id必须为正整数") 67 | @PathVariable int id){ 68 | return favorService.getLikeInfo(id,type); 69 | } 70 | 71 | @GetMapping("/favor") 72 | @AuthToken 73 | @ResponseBody 74 | public List findMyFavor(){ 75 | // art_id uid type 76 | return favorService.getfindMyFavor(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/AOP/aop.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.AOP; 2 | 3 | import com.example.demo.annotation.AuthToken; 4 | import com.example.demo.exception.AuthFailed; 5 | import com.example.demo.exception.NotFound; 6 | import com.example.demo.utils.ResultUtils; 7 | import com.example.demo.utils.TokenUtils; 8 | import org.aspectj.lang.ProceedingJoinPoint; 9 | import org.aspectj.lang.annotation.Around; 10 | import org.aspectj.lang.annotation.Aspect; 11 | import org.aspectj.lang.annotation.Pointcut; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.web.context.request.RequestContextHolder; 14 | import org.springframework.web.context.request.ServletRequestAttributes; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | 18 | /** 19 | * @Author WeLong 20 | * @create 2019/10/21 16:44 21 | */ 22 | @Aspect 23 | @Component 24 | public class aop { 25 | 26 | @Pointcut("@annotation(authToken)") 27 | public void doToken(AuthToken authToken) { 28 | 29 | } 30 | 31 | @Around("doToken(authToken)") 32 | public Object deBefore(ProceedingJoinPoint pjp, AuthToken authToken) throws Throwable { 33 | // 获取访问该方法所需的role_name信息 34 | String[] role_name = authToken.role_name(); 35 | for(int i=0;i wrapper = new QueryWrapper<>(); 43 | wrapper.eq("openid",openid); 44 | User exit = userMapper.selectOne(wrapper); 45 | User user = new User(); 46 | if(exit != null){ 47 | throw new Forbidden("小程序用户已存在"); 48 | } 49 | user.setOpenid(openid); 50 | user.setCreatedAt(LocalDateTime.now()); 51 | userMapper.insert(user); 52 | long uid = user.getId(); 53 | return uid; 54 | } 55 | 56 | @Override 57 | public User findByNickname(String nickname) { 58 | QueryWrapper wrapper = new QueryWrapper<>(); 59 | wrapper.eq("nickname", nickname); 60 | User exist = userMapper.selectOne(wrapper); 61 | return exist; 62 | } 63 | 64 | @Override 65 | public String verifyUser(User user) throws InvalidHashException { 66 | User exist= this.findByNickname(user.getNickname()); 67 | if(exist == null){ 68 | throw new NotFound("用户不存在"); 69 | } 70 | String password = this.findByNickname(user.getNickname()).getPassword(); 71 | Long uid = this.findByNickname(user.getNickname()).getId(); 72 | boolean rightPsw=Encryption.encrypt(user.getPassword(),password); 73 | if(rightPsw) { 74 | TokenUtils tokenUtils = new TokenUtils(); 75 | String res = tokenUtils.CreateToken(uid,16); 76 | return res; 77 | } 78 | throw new Forbidden("密码错误"); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/com/example/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import com.auth0.jwt.JWT; 4 | import com.auth0.jwt.JWTVerifier; 5 | import com.auth0.jwt.interfaces.Claim; 6 | import com.auth0.jwt.interfaces.DecodedJWT; 7 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 8 | import com.example.demo.Dao.UserMapper; 9 | import com.example.demo.model.User; 10 | import com.example.demo.utils.TokenUtils; 11 | import org.junit.jupiter.api.Test; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | import com.amdelamar.jhash.Hash; 15 | import com.amdelamar.jhash.algorithms.Type; 16 | import com.amdelamar.jhash.exception.InvalidHashException; 17 | import org.springframework.web.client.RestOperations; 18 | import org.springframework.web.client.RestTemplate; 19 | 20 | 21 | import java.util.Date; 22 | 23 | 24 | @SpringBootTest 25 | class DemoApplicationTests { 26 | 27 | 28 | @Autowired 29 | UserMapper userMapper; 30 | 31 | 32 | @Test 33 | void contextLoads() { 34 | RestTemplate restTemplate = new RestTemplate(); 35 | // http://t.yushu.im/v3/book/search?q={s}&count={s}&start={s}&summary={s} 36 | String url = "http://t.yushu.im/v2/book/id/{s}"; 37 | Object s = restTemplate.getForObject(url,Object.class,1120); 38 | System.out.println(s); 39 | } 40 | 41 | 42 | @Test 43 | public void jwt() { 44 | TokenUtils tokenUtils = new TokenUtils(); 45 | int scope = 16; 46 | String token = tokenUtils.CreateToken(1L,scope); 47 | System.out.println(token); 48 | 49 | } 50 | @Test 51 | public void jwtVerify() { 52 | TokenUtils tokenUtils = new TokenUtils(); 53 | // scope为16 54 | String token1 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInNjb3BlIjoxNiwiZXhwIjoxNTcxODE3MTU5fQ.qtG1Cz3Kpl7ZbDECJXWPQ0hFd7q3gCBOeGKCVU-S8J4"; 55 | boolean b = tokenUtils.VerifyToken(token1); 56 | System.out.println(b); 57 | 58 | } 59 | @Test 60 | public void j() { 61 | com.auth0.jwt.algorithms.Algorithm algorithm = com.auth0.jwt.algorithms.Algorithm.HMAC256("secret"); 62 | JWTVerifier verifier = JWT.require(algorithm) 63 | .acceptExpiresAt(4) 64 | .build(); //Reusable verifier instance 65 | DecodedJWT jwt = verifier.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInNjb3BlIjoxNiwiZXhwIjoxNTcxNzI1NTM2fQ.MybYIKlw4_a-OTmklOkpQGI7NuPSf7rGcglMm1PosoY"); 66 | Date expire = jwt.getExpiresAt(); 67 | expire.getTime(); 68 | Claim a = jwt.getClaim("scope"); 69 | a.asInt(); 70 | a.asDate(); 71 | } 72 | 73 | /** 74 | * 设置密文密码 75 | * 76 | * @param password 原始密码 77 | */ 78 | public void setPasswordEncrypt(String password) { 79 | char[] chars = password.toCharArray(); 80 | String s= Hash.password(chars).algorithm(Type.BCRYPT).create(); 81 | System.out.println(s); 82 | } 83 | 84 | /** 85 | * 验证加密密码 86 | * 87 | * @param password 密文密码 88 | * @return valid 89 | */ 90 | public boolean verify(String password) { 91 | char[] chars = password.toCharArray(); 92 | try { 93 | return Hash.password(chars).verify(password); 94 | } catch (InvalidHashException e) { 95 | return false; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/utils/TokenUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.utils; 2 | 3 | 4 | import com.auth0.jwt.JWT; 5 | import com.auth0.jwt.JWTVerifier; 6 | import com.auth0.jwt.algorithms.Algorithm; 7 | import com.auth0.jwt.interfaces.Claim; 8 | import com.auth0.jwt.interfaces.DecodedJWT; 9 | import com.example.demo.exception.Forbidden; 10 | import com.example.demo.exception.NotFound; 11 | import org.springframework.web.context.request.RequestContextHolder; 12 | import org.springframework.web.context.request.ServletRequestAttributes; 13 | 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import java.util.Date; 17 | 18 | 19 | /** 20 | * @Author WeLong 21 | * @create 2019/10/21 19:54 22 | */ 23 | public class TokenUtils { 24 | 25 | public String CreateToken(Long uid, int scope) { 26 | Algorithm algorithm = Algorithm.HMAC256("secret"); 27 | Date expireDate = this.getExpireDate(1000 * 60 * 60 * 24); 28 | String token = JWT.create() 29 | .withClaim("uid", uid) 30 | .withClaim("scope", scope) 31 | .withExpiresAt(expireDate) 32 | .sign(algorithm); 33 | return token; 34 | } 35 | 36 | public boolean VerifyToken(String token) { 37 | Algorithm algorithm = Algorithm.HMAC256("secret"); 38 | JWTVerifier verifier = JWT.require(algorithm) 39 | .acceptExpiresAt(4) 40 | .build(); 41 | DecodedJWT jwt = verifier.verify(token); 42 | 43 | Claim a = jwt.getClaim("scope"); 44 | Date d = jwt.getExpiresAt(); 45 | long tokenTime = d.getTime(); 46 | long localTime = new Date().getTime(); 47 | int scope = a.asInt(); 48 | int admin = 8; 49 | if(tokenTime <= localTime){ 50 | throw new Forbidden("token已过期"); 51 | } 52 | if (scope > admin) { 53 | return true; 54 | } else { 55 | return false; 56 | } 57 | 58 | 59 | } 60 | 61 | /** 62 | * 获得过期时间 63 | * 64 | * @param expire 过期时间 65 | * @return Date 66 | */ 67 | private Date getExpireDate(long expire) { 68 | long nowTime = new Date().getTime(); 69 | long expireTime = nowTime + expire; 70 | Date expireDate = new Date(expireTime); 71 | return expireDate; 72 | } 73 | 74 | public int getUid() { 75 | String token; 76 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 77 | HttpServletRequest request = attributes.getRequest(); 78 | String header = request.getHeader("Authorization"); 79 | if(!(header != null && header.length()!=0)){ 80 | throw new NotFound("token不合法"); 81 | } 82 | else { 83 | // 去除请求头的Bearer 取出token 84 | token = header.substring(7); 85 | if (header.startsWith("Bearer")){ 86 | boolean isVerify = this.VerifyToken(token); 87 | if(isVerify){ 88 | Algorithm algorithm = Algorithm.HMAC256("secret"); 89 | JWTVerifier verifier = JWT.require(algorithm) 90 | .acceptExpiresAt(4) 91 | .build(); 92 | DecodedJWT jwt = verifier.verify(token); 93 | Claim uid = jwt.getClaim("uid"); 94 | return uid.asInt(); 95 | } 96 | throw new NotFound("token不合法"); 97 | } 98 | throw new NotFound("token不合法"); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.0.RELEASE 9 | 10 | 11 | com.example 12 | demo 13 | 0.0.1-SNAPSHOT 14 | demo 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | jcenter 23 | https://jcenter.bintray.com/ 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | 35 | com.auth0 36 | java-jwt 37 | 3.8.3 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-aop 43 | 44 | 45 | 46 | com.amdelamar 47 | jotp 48 | 1.2.0 49 | 50 | 51 | com.amdelamar 52 | jhash 53 | 2.0.0 54 | 55 | 56 | 57 | com.baomidou 58 | mybatis-plus-boot-starter 59 | 3.2.0 60 | 61 | 62 | 63 | mysql 64 | mysql-connector-java 65 | 66 | 67 | com.alibaba 68 | fastjson 69 | 1.2.61 70 | 71 | 72 | 73 | org.projectlombok 74 | lombok 75 | true 76 | 77 | 78 | org.springframework.boot 79 | spring-boot-starter-test 80 | test 81 | 82 | 83 | org.junit.vintage 84 | junit-vintage-engine 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-maven-plugin 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/v1/BookController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller.v1; 2 | 3 | import com.example.demo.annotation.AuthToken; 4 | import com.example.demo.exception.Success; 5 | import com.example.demo.model.Comment; 6 | import com.example.demo.model.HotBook; 7 | import com.example.demo.service.CommentService; 8 | import com.example.demo.service.FavorService; 9 | import com.example.demo.service.HotBookService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.validation.annotation.Validated; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.client.RestTemplate; 14 | 15 | import javax.validation.constraints.Min; 16 | import javax.validation.constraints.NotEmpty; 17 | import java.util.*; 18 | 19 | /** 20 | * @Author WeLong 21 | * @create 2019/10/27 12:47 22 | */ 23 | 24 | @RestController 25 | @RequestMapping("/v1/book") 26 | @Validated 27 | public class BookController { 28 | @Autowired 29 | HotBookService hotBookService; 30 | @Autowired 31 | FavorService favorService; 32 | @Autowired 33 | CommentService commentService; 34 | 35 | @GetMapping("/hot_list") 36 | @AuthToken 37 | public List getAll(){ 38 | return hotBookService.getAll(); 39 | } 40 | 41 | @GetMapping("/{id}/detail") 42 | @AuthToken 43 | public Object getBooks(@PathVariable @Min(value = 1,message = "id必须为正整数") int id){ 44 | RestTemplate restTemplate = new RestTemplate(); 45 | String url = "http://t.yushu.im/v2/book/id/{s}"; 46 | Object result = restTemplate.getForObject(url,Object.class,id); 47 | return result; 48 | } 49 | @GetMapping("/favor/count") 50 | @AuthToken 51 | public Map getMyFavorBookCount(){ 52 | int count = favorService.selectMyFavorBook(); 53 | Map map = new HashMap(); 54 | map.put("count",count); 55 | return map; 56 | } 57 | 58 | @GetMapping("/search") 59 | @AuthToken 60 | public Object getBookDetail(@RequestParam(name = "q") 61 | @NotEmpty(message = "q参数不能为空") 62 | String q, 63 | @RequestParam(name = "count",defaultValue = "20") 64 | @Min(value = 0,message = "count参数不合法") 65 | int count, 66 | @RequestParam(name = "start",defaultValue = "0") 67 | @Min(value = 0,message = "start参数不合法") 68 | int start 69 | ){ 70 | String url = "http://t.yushu.im/v2/book/search?start={start}&count={count}&summary=1&q={q}"; 71 | RestTemplate restTemplate = new RestTemplate(); 72 | return restTemplate.getForObject(url,Object.class,start,count,q); 73 | } 74 | 75 | @GetMapping("/{book_id}/favor") 76 | @AuthToken 77 | public Map getBookFavor(@PathVariable 78 | @Min(value = 0,message = "book_id只能为正整数") int book_id){ 79 | return favorService.findBookLike(book_id); 80 | } 81 | 82 | @GetMapping("/hot_keyword") 83 | @AuthToken 84 | public Map getKeyWord(){ 85 | List list = Arrays.asList("Fluent Python", 86 | "Python", 87 | "小程序Java核心编程", 88 | "慕课网7七月", 89 | "微信小程序开发入门与实践", 90 | "C++"); 91 | Map map = new HashMap(); 92 | map.put("hot",list); 93 | return map; 94 | } 95 | @PostMapping("/add/short_comment") 96 | @AuthToken 97 | public void addComment(@RequestBody @Validated Comment comment){ 98 | commentService.add(comment); 99 | throw new Success(); 100 | } 101 | 102 | @GetMapping("/{book_id}/short_comment") 103 | @AuthToken 104 | public Map addComment(@PathVariable @Min(value = 1,message = "book_id必须为正整数") int book_id){ 105 | return commentService.getComment(book_id); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/FlowServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 6 | import com.example.demo.Dao.FlowMapper; 7 | import com.example.demo.exception.NotFound; 8 | import com.example.demo.model.Flow; 9 | import com.example.demo.service.ArtService; 10 | import com.example.demo.service.FavorService; 11 | import com.example.demo.service.FlowService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @Author WeLong 19 | * @create 2019/10/25 19:09 20 | */ 21 | @Service 22 | public class FlowServiceImpl implements FlowService { 23 | @Autowired 24 | FlowMapper flowMapper; 25 | 26 | @Autowired 27 | FavorService favorService; 28 | 29 | @Autowired 30 | ArtService artService; 31 | 32 | @Override 33 | public Object findLastest(){ 34 | QueryWrapper wrapper = new QueryWrapper<>(); 35 | wrapper.orderByDesc("indexs"); 36 | List list = flowMapper.selectList(wrapper); 37 | int index = list.get(0).getIndexs(); 38 | int art_id = list.get(0).getArtId(); 39 | int type = list.get(0).getType(); 40 | String str = JSON.toJSONString(artService.getData(art_id,type)); 41 | Object object = JSON.parseObject(str); 42 | boolean likeIt = favorService.userLikeIt(art_id,type); 43 | if(likeIt){ 44 | ((JSONObject) object).put("like_status",1); 45 | }else { 46 | ((JSONObject) object).put("like_status",0); 47 | } 48 | ((JSONObject) object).put("index",index); 49 | ((JSONObject) object).put("image","http://127.0.0.1:5000/"+((JSONObject) object).get("image")); 50 | return object; 51 | } 52 | 53 | @Override 54 | public Object findNext(int index){ 55 | return this.find(index+1); 56 | } 57 | 58 | @Override 59 | public Object findLast(int index){ 60 | return this.find(index-1); 61 | } 62 | 63 | /** 64 | * 65 | * @param type flow中的type号 66 | * @param id flow中的id号 67 | * @return Object 68 | */ 69 | @Override 70 | public Object findDetail(int type,int id){ 71 | QueryWrapper wrapper = new QueryWrapper<>(); 72 | wrapper.eq("type",type).eq("id",id); 73 | Flow flow = flowMapper.selectOne(wrapper); 74 | if(flow == null){ 75 | throw new NotFound(); 76 | } 77 | String str = JSON.toJSONString(artService.getData(flow.getArtId(),type)); 78 | Object object = JSON.parseObject(str); 79 | boolean likeIt = favorService.userLikeIt(flow.getArtId(),type); 80 | if(likeIt){ 81 | ((JSONObject) object).put("like_status",1); 82 | }else { 83 | ((JSONObject) object).put("like_status",0); 84 | } 85 | ((JSONObject) object).put("index",flow.getIndexs()); 86 | ((JSONObject) object).put("image","http://127.0.0.1:5000/"+((JSONObject) object).get("image")); 87 | return object; 88 | } 89 | 90 | 91 | public Object find(int index){ 92 | QueryWrapper wrapper = new QueryWrapper<>(); 93 | wrapper.eq("indexs",index); 94 | Flow exit = flowMapper.selectOne(wrapper); 95 | if(exit == null){ 96 | throw new NotFound(); 97 | } 98 | String str = JSON.toJSONString(artService.getData(exit.getArtId(),exit.getType())); 99 | Object object = JSON.parseObject(str); 100 | boolean likeIt = favorService.userLikeIt(exit.getArtId(),exit.getType()); 101 | if(likeIt){ 102 | ((JSONObject) object).put("like_status",1); 103 | }else { 104 | ((JSONObject) object).put("like_status",0); 105 | } 106 | ((JSONObject) object).put("index",index); 107 | ((JSONObject) object).put("image","http://127.0.0.1:5000/"+((JSONObject) object).get("image")); 108 | return object; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import com.auth0.jwt.exceptions.TokenExpiredException; 4 | import com.example.demo.utils.RequestHelper; 5 | import org.springframework.http.converter.HttpMessageNotReadableException; 6 | import org.springframework.validation.BindingResult; 7 | import org.springframework.web.bind.MethodArgumentNotValidException; 8 | import org.springframework.web.bind.MissingServletRequestParameterException; 9 | import org.springframework.web.bind.annotation.ControllerAdvice; 10 | import org.springframework.web.bind.annotation.ExceptionHandler; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; 13 | 14 | 15 | import javax.validation.ConstraintViolation; 16 | import javax.validation.ConstraintViolationException; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * @Author WeLong 22 | * @create 2019/10/23 10:08 23 | */ 24 | 25 | @ControllerAdvice 26 | @ResponseBody 27 | public class GlobalException { 28 | /** 29 | * 捕获系统异常 30 | * 31 | * @param e 32 | * @return map 33 | */ 34 | @ExceptionHandler(value = Exception.class) 35 | public Map getSysError(Exception e) { 36 | Map map = new HashMap<>(); 37 | map.put("code", -1); 38 | map.put("msg", e.getMessage()); 39 | map.put("request", RequestHelper.getRequestUrl()); 40 | return map; 41 | } 42 | 43 | /** 44 | * 捕获自定义异常 45 | * 46 | * @param ex 47 | * @return map 48 | */ 49 | @ExceptionHandler(value = HttpException.class) 50 | public Map errorHandler(HttpException ex) { 51 | Map map = new HashMap<>(); 52 | map.put("code", ex.getCode()); 53 | map.put("msg", ex.getMsg()); 54 | map.put("request", ex.getRequest()); 55 | return map; 56 | } 57 | 58 | /** 59 | * 捕获不合法参数异常 60 | * 61 | * @param e 62 | * @return map 63 | */ 64 | @ExceptionHandler(value = MethodArgumentNotValidException.class) 65 | public Map getValidError(MethodArgumentNotValidException e) { 66 | BindingResult result = e.getBindingResult(); 67 | String msg = result.getFieldError().getDefaultMessage(); 68 | Map map = new HashMap<>(); 69 | map.put("code", -2); 70 | map.put("msg", msg); 71 | map.put("request", RequestHelper.getRequestUrl()); 72 | return map; 73 | } 74 | 75 | /** 76 | * 请求体为空异常 77 | * 78 | * @param e 79 | * @return map 80 | */ 81 | @ExceptionHandler(value = HttpMessageNotReadableException.class) 82 | public Map getReadError(HttpMessageNotReadableException e) { 83 | String msg = "请求体不可为空"; 84 | Map map = new HashMap<>(); 85 | map.put("code", -3); 86 | map.put("msg", msg); 87 | map.put("request", RequestHelper.getRequestUrl()); 88 | return map; 89 | } 90 | 91 | //MissingServletRequestParameterException 92 | @ExceptionHandler(value = MissingServletRequestParameterException.class) 93 | public Map getReadError(MissingServletRequestParameterException e) { 94 | String msg = "参数" + e.getParameterName() + "缺失"; 95 | Map map = new HashMap<>(); 96 | map.put("code", -4); 97 | map.put("msg", msg); 98 | map.put("request", RequestHelper.getRequestUrl()); 99 | return map; 100 | } 101 | 102 | 103 | @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) 104 | public Map getReadError(MethodArgumentTypeMismatchException e) { 105 | String msg = e.getValue() + "类型错误"; 106 | Map map = new HashMap<>(); 107 | map.put("code", -5); 108 | map.put("msg", msg); 109 | map.put("request", RequestHelper.getRequestUrl()); 110 | return map; 111 | } 112 | 113 | // ConstraintViolationException 获取Path参数异常 114 | @ExceptionHandler(value = ConstraintViolationException.class) 115 | public Map getReadError(ConstraintViolationException e) { 116 | String msg = "参数异常"; 117 | for (ConstraintViolation s : e.getConstraintViolations()) { 118 | msg = s.getMessage(); 119 | } 120 | Map map = new HashMap<>(); 121 | map.put("code", -6); 122 | map.put("msg", msg); 123 | map.put("request", RequestHelper.getRequestUrl()); 124 | return map; 125 | } 126 | 127 | /** 128 | * token过期异常 129 | * 130 | * @param e 131 | * @return map 132 | */ 133 | @ExceptionHandler(value = TokenExpiredException.class) 134 | public Map getReadError(TokenExpiredException e) { 135 | String msg = "token已过期"; 136 | Map map = new HashMap<>(); 137 | map.put("code", -7); 138 | map.put("msg", msg); 139 | map.put("request", RequestHelper.getRequestUrl()); 140 | return map; 141 | } 142 | } 143 | 144 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if (mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if (mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if (!outputFile.getParentFile().exists()) { 87 | if (!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/Impl/FavorServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service.Impl; 2 | 3 | 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 7 | import com.example.demo.Dao.BookMapper; 8 | import com.example.demo.Dao.FavorMapper; 9 | import com.example.demo.exception.Forbidden; 10 | import com.example.demo.exception.NotFound; 11 | import com.example.demo.model.Book; 12 | import com.example.demo.model.Favor; 13 | import com.example.demo.service.ArtService; 14 | import com.example.demo.service.FavorService; 15 | import com.example.demo.service.MovieService; 16 | import com.example.demo.utils.TokenUtils; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Service; 19 | import org.springframework.transaction.annotation.Transactional; 20 | 21 | import java.time.LocalDateTime; 22 | import java.util.*; 23 | 24 | /** 25 | * @Author WeLong 26 | * @create 2019/10/25 23:33 27 | */ 28 | @Service 29 | @Transactional 30 | public class FavorServiceImpl implements FavorService { 31 | 32 | @Autowired 33 | FavorMapper favorMapper; 34 | @Autowired 35 | BookMapper bookMapper; 36 | @Autowired 37 | ArtService artService; 38 | 39 | @Override 40 | public void like(Favor favor){ 41 | this.likes(favor.getArtId(),favor.getType()); 42 | } 43 | 44 | @Override 45 | public void dislike(Favor favor){ 46 | this.dislikes(favor.getArtId(),favor.getType()); 47 | 48 | } 49 | 50 | public void likes(int art_id,int type){ 51 | int uid = new TokenUtils().getUid(); 52 | QueryWrapper favorQueryWrapper = new QueryWrapper<>(); 53 | favorQueryWrapper.eq("art_id",art_id).eq("type",type).eq("uid",uid); 54 | Favor exit = favorMapper.selectOne(favorQueryWrapper); 55 | if(exit != null){ 56 | throw new Forbidden("你已经点赞过"); 57 | } 58 | Favor favors = new Favor(); 59 | favors.setArtId(art_id); 60 | favors.setType(type); 61 | favors.setUid(uid); 62 | favors.setCreatedAt(LocalDateTime.now()); 63 | favors.setUpdatedAt(LocalDateTime.now()); 64 | favorMapper.insert(favors); 65 | artService.updataData(art_id,type); 66 | } 67 | 68 | public void dislikes(int art_id,int type){ 69 | int uid = new TokenUtils().getUid(); 70 | QueryWrapper favorQueryWrapper = new QueryWrapper<>(); 71 | favorQueryWrapper.eq("art_id",art_id).eq("type",type).eq("uid",uid); 72 | Favor exit = favorMapper.selectOne(favorQueryWrapper); 73 | if(exit != null){ 74 | favorMapper.delete(favorQueryWrapper); 75 | artService.deleteData(art_id,type); 76 | }else{ 77 | throw new NotFound("未找到该记录"); 78 | } 79 | } 80 | @Override 81 | public boolean userLikeIt(int art_id,int type){ 82 | int uid = new TokenUtils().getUid(); 83 | QueryWrapper favorQueryWrapper = new QueryWrapper<>(); 84 | favorQueryWrapper.eq("art_id",art_id).eq("type",type).eq("uid",uid); 85 | Favor exit = favorMapper.selectOne(favorQueryWrapper); 86 | return exit!=null ? true : false; 87 | } 88 | 89 | @Override 90 | public Object getLikeInfo(int art_id,int type){ 91 | QueryWrapper favorQueryWrapper = new QueryWrapper<>(); 92 | favorQueryWrapper.eq("art_id",art_id).eq("type",type); 93 | Favor favor = favorMapper.selectOne(favorQueryWrapper); 94 | if(favor == null){ 95 | throw new NotFound(); 96 | } 97 | String s = JSON.toJSONString(artService.getData(favor.getArtId(),favor.getType())); 98 | Object object = JSON.parseObject(s); 99 | String fav_nums = JSON.toJSONString(((JSONObject) object).get("fav_nums")); 100 | String id = JSON.toJSONString(((JSONObject) object).get("id")); 101 | int like_status = this.userLikeIt(art_id,type)? 1 : 0; 102 | Map map = new HashMap<>(); 103 | map.put("fav_nums",fav_nums); 104 | map.put("id",id); 105 | map.put("like_status",like_status); 106 | return map; 107 | } 108 | @Override 109 | public List getfindMyFavor(){ 110 | int uid = new TokenUtils().getUid(); 111 | Map map = new HashMap<>(); 112 | map.put("uid",uid); 113 | favorMapper.selectByMap(map); 114 | List list = favorMapper.selectByMap(map); 115 | List data = new ArrayList(); 116 | if(list.size()==0){ 117 | throw new NotFound(); 118 | } 119 | for(int i=0;i favorQueryWrapper= new QueryWrapper<>(); 137 | favorQueryWrapper.eq("type",400).eq("uid",uid); 138 | return favorMapper.selectCount(favorQueryWrapper); 139 | } 140 | 141 | @Override 142 | public Map findBookLike(int book_id){ 143 | QueryWrapper favorQueryWrapper= new QueryWrapper<>(); 144 | favorQueryWrapper.eq("art_id",book_id); 145 | Favor favor = favorMapper.selectOne(favorQueryWrapper); 146 | if(favor == null){ 147 | throw new NotFound(); 148 | } 149 | int bookId = favor.getArtId(); 150 | QueryWrapper bookQueryWrapper= new QueryWrapper<>(); 151 | bookQueryWrapper.eq("id",bookId); 152 | Book book = bookMapper.selectOne(bookQueryWrapper); 153 | if(book == null){ 154 | throw new NotFound(); 155 | } 156 | int favNums = book.getFavNums(); 157 | Map map = new HashMap(); 158 | map.put("like_status",this.userLikeIt(book_id,400)?1:0); 159 | map.put("id",bookId); 160 | map.put("fav_nums",favNums); 161 | return map; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /sql/island-java.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost_3306 5 | Source Server Version : 80015 6 | Source Host : localhost:3306 7 | Source Database : island-java 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 80015 11 | File Encoding : 65001 12 | 13 | Date: 2019-10-27 17:10:55 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for book 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `book`; 22 | CREATE TABLE `book` ( 23 | `id` int(11) NOT NULL, 24 | `fav_nums` int(11) NOT NULL DEFAULT '0', 25 | `created_at` datetime DEFAULT NULL, 26 | `updated_at` datetime DEFAULT NULL, 27 | `deleted_at` datetime DEFAULT NULL 28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 29 | 30 | -- ---------------------------- 31 | -- Records of book 32 | -- ---------------------------- 33 | INSERT INTO `book` VALUES ('1120', '1', null, null, null); 34 | 35 | -- ---------------------------- 36 | -- Table structure for comment 37 | -- ---------------------------- 38 | DROP TABLE IF EXISTS `comment`; 39 | CREATE TABLE `comment` ( 40 | `id` int(11) NOT NULL AUTO_INCREMENT, 41 | `content` varchar(12) DEFAULT NULL, 42 | `nums` int(11) DEFAULT '0', 43 | `book_id` int(11) DEFAULT NULL, 44 | `created_at` datetime DEFAULT NULL, 45 | `updated_at` datetime DEFAULT NULL, 46 | `deleted_at` datetime DEFAULT NULL, 47 | PRIMARY KEY (`id`) 48 | ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 49 | 50 | -- ---------------------------- 51 | -- Records of comment 52 | -- ---------------------------- 53 | INSERT INTO `comment` VALUES ('12', '真好看', '5', '1120', null, null, null); 54 | INSERT INTO `comment` VALUES ('13', '真好看', '4', '1000', null, null, null); 55 | 56 | -- ---------------------------- 57 | -- Table structure for favor 58 | -- ---------------------------- 59 | DROP TABLE IF EXISTS `favor`; 60 | CREATE TABLE `favor` ( 61 | `id` int(11) NOT NULL AUTO_INCREMENT, 62 | `art_id` int(11) DEFAULT NULL, 63 | `type` int(11) DEFAULT NULL, 64 | `created_at` datetime NOT NULL, 65 | `updated_at` datetime NOT NULL, 66 | `deleted_at` datetime DEFAULT NULL, 67 | `uid` int(11) DEFAULT NULL, 68 | PRIMARY KEY (`id`) 69 | ) ENGINE=InnoDB AUTO_INCREMENT=94 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 70 | 71 | -- ---------------------------- 72 | -- Records of favor 73 | -- ---------------------------- 74 | INSERT INTO `favor` VALUES ('74', '1', '100', '2019-10-26 14:02:06', '2019-10-26 14:02:06', null, '8'); 75 | INSERT INTO `favor` VALUES ('93', '1120', '400', '2019-10-27 15:24:38', '2019-10-27 15:24:38', null, '8'); 76 | 77 | -- ---------------------------- 78 | -- Table structure for flow 79 | -- ---------------------------- 80 | DROP TABLE IF EXISTS `flow`; 81 | CREATE TABLE `flow` ( 82 | `created_at` datetime DEFAULT NULL, 83 | `status` smallint(6) DEFAULT NULL, 84 | `id` int(11) NOT NULL AUTO_INCREMENT, 85 | `indexs` int(11) NOT NULL, 86 | `type` int(11) NOT NULL, 87 | `art_id` int(11) NOT NULL, 88 | `updated_at` datetime DEFAULT NULL, 89 | `deleted_at` datetime DEFAULT NULL, 90 | PRIMARY KEY (`id`) USING BTREE 91 | ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPACT; 92 | 93 | -- ---------------------------- 94 | -- Records of flow 95 | -- ---------------------------- 96 | INSERT INTO `flow` VALUES ('2019-04-05 17:11:14', '1', '1', '1', '200', '3', null, null); 97 | INSERT INTO `flow` VALUES ('2019-04-05 17:11:21', '1', '2', '2', '300', '2', null, null); 98 | INSERT INTO `flow` VALUES ('2019-04-05 17:11:27', '1', '3', '3', '200', '2', null, null); 99 | INSERT INTO `flow` VALUES ('2019-04-02 17:11:50', '1', '4', '4', '100', '2', null, null); 100 | INSERT INTO `flow` VALUES ('2019-04-17 17:11:56', '1', '5', '6', '300', '1', null, null); 101 | INSERT INTO `flow` VALUES ('2019-04-05 17:12:00', '1', '6', '7', '200', '1', null, null); 102 | INSERT INTO `flow` VALUES ('2019-04-05 17:12:04', '1', '7', '8', '100', '1', null, null); 103 | INSERT INTO `flow` VALUES ('2019-04-05 17:12:07', '1', '8', '5', '200', '4', null, null); 104 | 105 | -- ---------------------------- 106 | -- Table structure for hot_book 107 | -- ---------------------------- 108 | DROP TABLE IF EXISTS `hot_book`; 109 | CREATE TABLE `hot_book` ( 110 | `created_at` datetime DEFAULT NULL, 111 | `status` smallint(6) DEFAULT NULL, 112 | `id` int(11) NOT NULL AUTO_INCREMENT, 113 | `indexs` int(11) DEFAULT NULL, 114 | `image` varchar(64) DEFAULT NULL, 115 | `author` varchar(25) DEFAULT NULL, 116 | `title` varchar(50) DEFAULT NULL, 117 | `updated_at` datetime DEFAULT NULL, 118 | `deleted_at` datetime DEFAULT NULL, 119 | PRIMARY KEY (`id`) USING BTREE 120 | ) ENGINE=InnoDB AUTO_INCREMENT=51665 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT; 121 | 122 | -- ---------------------------- 123 | -- Records of hot_book 124 | -- ---------------------------- 125 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '7', '1', 'https://img3.doubanio.com/lpic/s4669554.jpg', '[美]保罗·格雷厄姆', '黑客与画家', null, null); 126 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '65', '2', 'https://img3.doubanio.com/lpic/s4059293.jpg', 'MarkPilgrim', 'Dive Into Python 3', null, null); 127 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '183', '3', 'https://img3.doubanio.com/lpic/s4387251.jpg', 'MagnusLieHetland', 'Python基础教程', null, null); 128 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1002', '4', 'https://img3.doubanio.com/lpic/s6384944.jpg', '[哥伦比亚]加西亚·马尔克斯', '百年孤独', null, null); 129 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1049', '5', 'https://img1.doubanio.com/view/subject/l/public/s29775868.jpg', '[日]岩井俊二', '情书', null, null); 130 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1061', '6', 'https://img3.doubanio.com/lpic/s1358984.jpg', '[美]乔治·R·R·马丁', '冰与火之歌(卷一)', null, null); 131 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1120', '7', 'https://img3.doubanio.com/lpic/s4610502.jpg', '[日]东野圭吾', '白夜行', null, null); 132 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1166', '8', 'https://img1.doubanio.com/lpic/s23632058.jpg', '金庸', '天龙八部', null, null); 133 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1308', '9', 'https://img3.doubanio.com/lpic/s3814606.jpg', '[日]东野圭吾', '恶意', null, null); 134 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1339', '10', 'https://img3.doubanio.com/lpic/s1074376.jpg', '[英]J·K·罗琳', '哈利·波特与阿兹卡班的囚徒', null, null); 135 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1383', '11', 'https://img1.doubanio.com/lpic/s3557848.jpg', '韩寒', '他的国', null, null); 136 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1398', '12', 'https://img1.doubanio.com/lpic/s2752367.jpg', '[英]J·K·罗琳', '哈利·波特与死亡圣器', null, null); 137 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '1560', '13', 'https://img1.doubanio.com/lpic/s3463069.jpg', '王小波', '三十而立', null, null); 138 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '7821', '14', 'https://img3.doubanio.com/lpic/s6144591.jpg', '[伊朗]玛赞·莎塔碧', '我在伊朗长大', null, null); 139 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '8854', '15', 'https://img1.doubanio.com/lpic/s29494718.jpg', '[日]村上春树', '远方的鼓声', null, null); 140 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '8866', '16', 'https://img3.doubanio.com/lpic/s2393243.jpg', '三毛', '梦里花落知多少', null, null); 141 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '15198', '17', 'https://img1.doubanio.com/lpic/s1080179.jpg', '韩寒', '像少年啦飞驰', null, null); 142 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '15984', '18', 'https://img3.doubanio.com/lpic/s27970504.jpg', '鲁迅', '朝花夕拾', null, null); 143 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '21050', '19', 'https://img3.doubanio.com/lpic/s2853431.jpg', '[日]井上雄彦', '灌篮高手31', null, null); 144 | INSERT INTO `hot_book` VALUES ('0000-00-00 00:00:00', '1', '51664', '20', 'https://img3.doubanio.com/lpic/s29034294.jpg', '[日]新井一二三', '东京时味记', null, null); 145 | 146 | -- ---------------------------- 147 | -- Table structure for movie 148 | -- ---------------------------- 149 | DROP TABLE IF EXISTS `movie`; 150 | CREATE TABLE `movie` ( 151 | `created_at` datetime DEFAULT NULL, 152 | `status` smallint(6) DEFAULT NULL, 153 | `id` int(11) NOT NULL AUTO_INCREMENT, 154 | `image` varchar(64) DEFAULT NULL, 155 | `content` varchar(300) DEFAULT NULL, 156 | `pubdate` date DEFAULT NULL, 157 | `fav_nums` int(11) DEFAULT NULL, 158 | `title` varchar(50) DEFAULT NULL, 159 | `type` int(11) DEFAULT NULL, 160 | `updated_at` datetime DEFAULT NULL, 161 | `deleted_at` datetime DEFAULT NULL, 162 | PRIMARY KEY (`id`) USING BTREE 163 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT; 164 | 165 | -- ---------------------------- 166 | -- Records of movie 167 | -- ---------------------------- 168 | INSERT INTO `movie` VALUES ('2019-10-25 23:21:21', '1', '1', 'images/movie.8.png', '人生不能像做菜,把所有的料准备好才下锅', '2018-06-22', '171', '李安《饮食男女 》', '100', '2019-10-25 02:40:48', null); 169 | INSERT INTO `movie` VALUES ('2019-10-25 23:21:30', '1', '2', 'images/movie.4.png', '在变换的生命里,岁月原来是最大的小偷', '2018-06-22', '46', '罗启锐《岁月神偷》', '100', '2019-10-25 04:34:38', null); 170 | 171 | -- ---------------------------- 172 | -- Table structure for music 173 | -- ---------------------------- 174 | DROP TABLE IF EXISTS `music`; 175 | CREATE TABLE `music` ( 176 | `created_at` datetime DEFAULT NULL, 177 | `status` smallint(6) DEFAULT NULL, 178 | `id` int(11) NOT NULL AUTO_INCREMENT, 179 | `image` varchar(64) DEFAULT NULL, 180 | `content` varchar(300) DEFAULT NULL, 181 | `url` varchar(100) DEFAULT NULL, 182 | `pubdate` date DEFAULT NULL, 183 | `fav_nums` int(11) DEFAULT NULL, 184 | `type` int(11) DEFAULT NULL, 185 | `title` varchar(50) DEFAULT NULL, 186 | `deleted_at` datetime DEFAULT NULL, 187 | `updated_at` datetime DEFAULT NULL, 188 | PRIMARY KEY (`id`) USING BTREE 189 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT; 190 | 191 | -- ---------------------------- 192 | -- Records of music 193 | -- ---------------------------- 194 | INSERT INTO `music` VALUES ('2019-10-25 23:22:04', '1', '1', 'images/music.7.png', '无人问我粥可温 风雨不见江湖人', 'http://music.163.com/song/media/outer/url?id=393926.mp3', '2018-06-22', '95', '200', '月之门《枫华谷的枫林》', null, '2019-10-25 18:25:12'); 195 | INSERT INTO `music` VALUES ('2019-10-25 23:22:11', '1', '2', 'images/music.1.png', '你陪我步入蝉夏 越过城市喧嚣', 'http://music.163.com/song/media/outer/url?id=516076896.mp3', '2018-06-22', '47', '200', '花粥 《纸短情长》', null, '2019-10-25 09:13:12'); 196 | INSERT INTO `music` VALUES ('2019-10-25 23:22:15', '1', '3', 'images/music.3.png', '岁月长,衣裳薄', 'http://music.163.com/song/media/outer/url?id=317245.mp3', '2018-06-22', '44', '200', '杨千嬅《再见二丁目》', null, '2019-10-25 11:59:49'); 197 | INSERT INTO `music` VALUES ('2019-10-25 23:22:20', '1', '4', 'images/music.5.png', '许多人来来去去,相聚又别离', 'http://music.163.com/song/media/outer/url?id=26427662.mp3', '2018-06-22', '68', '200', '好妹妹 《一个人的北京》', null, '2019-10-25 23:22:37'); 198 | 199 | -- ---------------------------- 200 | -- Table structure for sentence 201 | -- ---------------------------- 202 | DROP TABLE IF EXISTS `sentence`; 203 | CREATE TABLE `sentence` ( 204 | `created_at` datetime DEFAULT NULL, 205 | `status` smallint(6) DEFAULT NULL, 206 | `id` int(11) NOT NULL AUTO_INCREMENT, 207 | `image` varchar(64) DEFAULT NULL, 208 | `content` varchar(300) DEFAULT NULL, 209 | `pubdate` date DEFAULT NULL, 210 | `fav_nums` int(11) DEFAULT NULL, 211 | `title` varchar(50) DEFAULT NULL, 212 | `type` int(11) DEFAULT NULL, 213 | `updated_at` datetime DEFAULT NULL, 214 | `deleted_at` datetime DEFAULT NULL, 215 | PRIMARY KEY (`id`) USING BTREE 216 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT; 217 | 218 | -- ---------------------------- 219 | -- Records of sentence 220 | -- ---------------------------- 221 | INSERT INTO `sentence` VALUES ('2019-10-25 23:22:50', '1', '1', 'images/sentence.6.png', '心上无垢,林间有风', '2018-06-22', '72', '未名', '300', '2019-10-25 12:13:37', null); 222 | INSERT INTO `sentence` VALUES ('2019-10-25 23:22:54', '1', '2', 'images/sentence.2.png', '这个夏天又是一个毕业季', '2018-06-22', '33', '未名', '300', '2019-10-25 09:13:28', null); 223 | 224 | -- ---------------------------- 225 | -- Table structure for user 226 | -- ---------------------------- 227 | DROP TABLE IF EXISTS `user`; 228 | CREATE TABLE `user` ( 229 | `id` int(11) NOT NULL AUTO_INCREMENT, 230 | `email` varchar(255) DEFAULT NULL, 231 | `nickname` varchar(255) DEFAULT NULL, 232 | `openid` varchar(64) DEFAULT NULL, 233 | `password` varchar(255) DEFAULT NULL, 234 | `created_at` datetime NOT NULL, 235 | `updated_at` datetime DEFAULT NULL, 236 | `deleted_at` datetime DEFAULT NULL, 237 | PRIMARY KEY (`id`), 238 | UNIQUE KEY `openid` (`openid`) 239 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 240 | 241 | -- ---------------------------- 242 | -- Records of user 243 | -- ---------------------------- 244 | INSERT INTO `user` VALUES ('8', '1191430240@qq.com', 'fuwelong', null, 'pbkdf2sha256:64000:18:24:n:kBIl1FzIxK2BwLSncU36uRlarZIlKUVE:oMMDoaCptFcBP5DSsTzzUaeH', '2019-10-25 14:25:40', null, null); 245 | --------------------------------------------------------------------------------