|
@@ -4,6 +4,7 @@ import com.keao.edu.common.controller.BaseController;
|
|
|
import com.keao.edu.user.entity.ShortUrl;
|
|
|
import com.keao.edu.user.service.ShortUrlService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @Author Joburgess
|
|
@@ -27,6 +29,9 @@ public class ShortUrlController extends BaseController {
|
|
|
@GetMapping(value = "/su/{id}")
|
|
|
public void redirectUrl(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
|
|
|
ShortUrl shortUrl = shortUrlService.get(id);
|
|
|
+ if(Objects.isNull(shortUrl)|| StringUtils.isBlank(shortUrl.getUrl())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
response.sendRedirect(shortUrl.getUrl());
|
|
|
}
|
|
|
|