다음이 비디오 웹 사이트의 링크 목록이라고 가정 해 봅시다. 다른 사람들이 데이터를 크롤링하려면 매우 쉽고 규칙을 볼 때 데이터베이스가 자체적으로 증가한다는 것을 알고 있습니다.
http://www.xxxx.com/video/1
http://www.xxxx.com/video/2
http://www.xxxx.com/video/3
그런 다음이 문제를 해결하고 짧은 주소를 사용하고 외부 세계에 실제 링크를 노출시키지 않으며 대칭 암호화를 사용하는 것이 좋은 솔루션입니다.
Hashids는 JS/PHP/Java/Python과 같은 프로그래밍 언어를 제공합니다.
다음은 블레이드 프레임 워크 (Blade Framework)에 의해 구축 된 Java 단편 주소 서비스입니다.
테이블 작성`t_url` (`id` int (10) not null auto_increment,`url` 텍스트 null, 기본 키 (`id`)) engine = innodb auto_increment = 15 기본 charset = utf8;
라우팅
@PhipPublic Class indexroute {// salt value private static final hashids = new Hashids ( "blade-shorturl"); 응답) {req.pathparam ( ": key") null == numbers.length <1) {int id = (int) 숫자 [0]; if (result == null) {response.text ( "찾기 없음"); "index";} @route (value = "/", method = httpmethod.post) 공개 문자열 저장 (문자열 resjsp = "index."; ". "오류", "실패한"); , url_hash = " + hash); return resvsp;} private integer save (string url) {return urlmodel.insert (). url) .ecuteandcommit ();} private urlmodel get (int id) {return urlmodel .fetchbypk (id) ;} 개인 최종 문자열 regx = "// b (https? | ftp | file) : // [-a-za-z0-9+@#/%? = ~ |!.]*[-s-za- z0-9+@#/%= ~ |] "; private boolean isurl (string url) {if (stringkit.isnotblank (url)) {Pattern Pattern = Pattern. (regex); matcher matcher = pattern.matcher (url) if (matcher.find ()) {return true;}} return false;}}구현 효과 :
코드 위치 : https://github.com/bladejava/blade- shorturl
위는이 기사의 모든 내용입니다.