-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
实现短链接功能
- Loading branch information
kechangqing
committed
Mar 10, 2022
1 parent
a3e8238
commit 1b351e3
Showing
32 changed files
with
935 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
DROP TABLE IF EXISTS config_map; | ||
CREATE TABLE IF NOT EXISTS config_map | ||
( | ||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', | ||
config_key VARCHAR(500) NOT NULL COMMENT '配置key', | ||
config_value VARCHAR(1000) NOT NULL COMMENT '配置value', | ||
creator VARCHAR(200) NOT NULL COMMENT '创建人', | ||
create_at DATETIME NOT NULL COMMENT '创建时间', | ||
modify_at DATETIME NOT NULL COMMENT '修改时间', | ||
modifier VARCHAR(200) NOT NULL COMMENT '最后修改人' | ||
) | ||
ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COMMENT = '内部配置表'; | ||
|
||
CREATE UNIQUE INDEX uniq_configkey ON config_map (config_key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
DROP TABLE IF EXISTS short_link; | ||
CREATE TABLE IF NOT EXISTS short_link | ||
( | ||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', | ||
long_link VARCHAR(1000) NOT NULL COMMENT '监控数据类型。(http: http监控;其他值: 关联data_name表)', | ||
create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' | ||
) | ||
ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COMMENT = '短链接表'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
DROP TABLE IF EXISTS config_map; | ||
CREATE TABLE IF NOT EXISTS config_map | ||
( | ||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', | ||
config_key VARCHAR(500) NOT NULL COMMENT '配置key', | ||
config_value VARCHAR(1000) NOT NULL COMMENT '配置value', | ||
creator VARCHAR(200) NOT NULL COMMENT '创建人', | ||
create_at DATETIME NOT NULL COMMENT '创建时间', | ||
modify_at DATETIME NOT NULL COMMENT '修改时间', | ||
modifier VARCHAR(200) NOT NULL COMMENT '最后修改人' | ||
) | ||
ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COMMENT = '内部配置表'; | ||
|
||
CREATE UNIQUE INDEX uniq_configkey ON config_map (config_key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
DROP TABLE IF EXISTS short_link; | ||
CREATE TABLE IF NOT EXISTS short_link | ||
( | ||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', | ||
long_link VARCHAR(1000) NOT NULL COMMENT '监控数据类型。(http: http监控;其他值: 关联data_name表)', | ||
create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' | ||
) | ||
ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COMMENT = '短链接表'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/IndexController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.autohome.frostmourne.monitor.controller; | ||
|
||
import java.util.Optional; | ||
import javax.annotation.Resource; | ||
|
||
import com.autohome.frostmourne.monitor.controller.annotation.PermissionLimit; | ||
import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; | ||
import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IShortLinkRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Controller | ||
public class IndexController { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(IndexController.class); | ||
|
||
@Resource | ||
private IShortLinkRepository shortLinkRepository; | ||
|
||
@PermissionLimit(limit = false) | ||
@RequestMapping(value = "/goto/{id}", method = RequestMethod.GET) | ||
public String jump(@PathVariable(value = "id") Long id) { | ||
if (id == null || id <= 0) { | ||
LOGGER.error("invalid short link id: {}", id); | ||
return "redirect:/dashboard.view"; | ||
} | ||
Optional<ShortLink> shortLinkOptional = shortLinkRepository.selectByPrimaryKey(id); | ||
if (shortLinkOptional.isPresent()) { | ||
return String.format("redirect:%s", shortLinkOptional.get().getLongLink()); | ||
} else { | ||
LOGGER.error("invalid short link id: {}", id); | ||
return "redirect:/dashboard.view"; | ||
} | ||
} | ||
} |
Oops, something went wrong.