CsdnController.java 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
package com.kwan.springbootkwan.controller;

import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.resp.BusinessInfo;
import com.kwan.springbootkwan.service.CsdnService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/csdn")
public class CsdnController {

    @Autowired
    private CsdnService service;

    @ApiOperation(value = "获取数据", notes = "获取数据")
    @GetMapping("/list")
    public Result get() {
        final BusinessInfo businessInfo = service.list();
        final BusinessInfo.ArticleData data = businessInfo.getData();
        final List<BusinessInfo.ArticleData.Article> list = data.getList();
        final BusinessInfo.ArticleData.Article article = list.get(0);
        final String url = article.getUrl();
        final int index = url.lastIndexOf("/");
        final String articleId = url.substring(index + 1);
        System.out.println(articleId);

        service.getArticleInfo(articleId);
        return Result.ok(businessInfo);
    }
}