仿b站前后端分离微服务项目前后端完全运行

在运行项目之前需把中间件、springboot项目启动,参考之前的保姆级教程https://www.nowcoder.com/discuss/640368532730990592?sourceSSR=users

https://www.nowcoder.com/discuss/640865638906384384?sourceSSR=users

运行之后将github上的项目sqlhttps://github.com/aigcbilibili/aigcbilibili

执行,并在启动搜索服务后在Postman中发送请求创建视频和用户的es索引

post请求:http://localhost:8201/search/createIndex

{
    "indexName": "video",
    "properties": {
        "video_id": "integer",
        "video_name": "text",
        "intro": "text",
        "cover":"text",
        "length":"text",
        "create_time":"date",
        "author_name":"text",
        "author_id":"integer",
        "url":"text",
        "play_count":"integer",
        "danmaku_count":"integer",
        "collect_count":"integer"
    }
}

和post请求http://localhost:8201/search/createIndex

{
    "indexName": "user",
    "properties": {
        "id": "integer",
        "nickname": "text",
        "intro": "text",
        "cover":"text",
        "fans_count":"integer",
        "video_count":"integer"

    }
}

或将搜索服务中创建索引的接口createIndex上的@ApiIgnore注解去掉后浏览器输入localhost:8201/doc.html进入接口文档创建

package ljl.bilibili.search.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ljl.bilibili.client.pojo.RecommendVideo;
import ljl.bilibili.search.service.SearchService;
import ljl.bilibili.search.vo.request.EsKeywordRequest;
import ljl.bilibili.search.vo.response.UserKeyWordSearchResponse;
import ljl.bilibili.search.handler.MysqlToEsHandler;
import ljl.bilibili.search.vo.response.TotalCountSearchResponse;
import ljl.bilibili.search.vo.response.VideoKeywordSearchResponse;
import ljl.bilibili.search.vo.request.EsIndexRequest;
import ljl.bilibili.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/search")
@Api(tags = "搜索")
@Slf4j
@CrossOrigin(value = "*")
public class SearchController {
    @Resource
    SearchService searchService;
    @Resource
    MysqlToEsHandler mysqlToEsHandler;
    @GetMapping("/test")
    public Boolean test() throws Exception {
        mysqlToEsHandler.mysqlToEsHandler();
        return true;
    }
   
    @GetMapping("/totalKeywordSearch/{keyword}")
    @ApiOperation("关键字搜索后得出匹配视频和用户的总页数和总文档数")
    public Result<TotalCountSearchResponse> totalKeywordSearch(@PathVariable String keyword) {
        log.info("1");
        return searchService.totalKeywordSearch(keyword);
    }
   
    @GetMapping("/videoKeywordSearch/{keyword}/{pageNumber}/{type}")
    @ApiOperation("关键字搜索后得出匹配度降序排列的视频列表,得到对应页码的视频数据")
    public Result<List<VideoKeywordSearchResponse>> videoPageKeywordSearch(@PathVariable String keyword, @PathVariable Integer pageNumber, @PathVariable Integer type) throws JsonProcessingException {
        log.info("1");
        return searchService.videoPageKeywordSearch(keyword, pageNumber, type);
    }
   
    @GetMapping("/userKeywordSearch/{keyword}/{pageNumber}/{type}/{userId}")
    @ApiOperation("关键字搜索后得出匹配度降序排列的用户,得到对应页码的视频数据,传不同type决定再查询结果")
    public Result<List<UserKeyWordSearchResponse>> userPageKeywordSearch(@PathVariable String keyword, @PathVariable Integer pageNumber, @PathVariable Integer type, @PathVariable Integer userId) throws JsonProcessingException {
        log.info("1");
        return searchService.userPageKeywordSearch(keyword, pageNumber, type,userId);
    }
   
    @GetMapping("/likelyKeyWordSearch/{keyword}")
    @ApiOperation("输入关键字时停顿且未点确认导致跳转搜索结果页时对应的匹配度前十的近似关键字")
    public Result<List<String>> LikelykeyWordSearch(@PathVariable String keyword) throws IOException {
        log.info("1");
        return searchService.likelyKeywordSearch(keyword);
    }
    @GetMapping("/likelyVideoRecommend/{videoId}")
    @ApiOperation("推荐视频")
    @ApiIgnore
    public List<RecommendVideo> likelyVideoRecommend(@PathVariable String videoId) throws IOException {
        log.info("1");
        return searchService.likelyVideoRecommend(videoId);
    }
   
    @PostMapping("/addKeywordSearchRecord")
    @ApiOperation("增加搜索的历史记录")
    public Result<Boolean> addKeywordSearchRecord(@RequestBody EsKeywordRequest esKeywordRequest) throws IOException {
        log.info("1");
        return searchService.addKeywordSearchRecord(esKeywordRequest);
    }
   
    @PostMapping("/createIndex")
    @ApiIgnore     去掉
    public void crateIndex(@RequestBody EsIndexRequest esIndexRequest) {
        log.info("1");
        searchService.createIndex(esIndexRequest);
    }
    @PostMapping("/deleteIndex/{indexName}")
    @ApiIgnore   
    public void deleteIndex(@PathVariable String indexName) throws IOException {
        log.info("1");
        searchService.deleteIndex(indexName);
    }

}

未完待续

#项目##我的成功项目解析#

该专栏存放前后端分离仿b站微服务项目相关教程

全部评论
大佬,运行失败呀,登录和注册的请求都被JwtAuthorizationFilter拦截了,需要改什么吗
点赞 回复 分享
发布于 08-05 14:16 河北

相关推荐

10-14 21:33
门头沟学院 Java
认真的铁锤在改简历:12号进行二面的是不是都没变?
点赞 评论 收藏
分享
5 3 评论
分享
牛客网
牛客企业服务