package com.caimei.www.controller.unlimitedApi; import com.caimei.www.service.link.ShortLinkService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.thymeleaf.util.StringUtils; import java.net.URI; /** * Description * * @author : plf * @date : 2021/6/24 */ @RestController public class ShortLinkApi { private ShortLinkService shortLinkService; @Autowired public void setShortLinkService(ShortLinkService shortLinkService) { this.shortLinkService = shortLinkService; } /** * 短链接跳转 * * @param link * @param response */ @GetMapping("/t/{link}") public void linkJump(@PathVariable String link, ServerHttpResponse response) { String jumpLink = shortLinkService.linkJump(link); response.setStatusCode(HttpStatus.FOUND); if (StringUtils.isEmpty(jumpLink)) { response.getHeaders().setLocation(URI.create("https://www.caimei365.com/404.html")); } response.getHeaders().setLocation(URI.create(jumpLink)); } }