中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

企業(yè)信息港網(wǎng)站建沒怎樣自己開發(fā)一款軟件

企業(yè)信息港網(wǎng)站建沒,怎樣自己開發(fā)一款軟件,英國政府網(wǎng)站建設(shè)特點,php建站系統(tǒng)哪個好文章目錄 一、需求概述二、開發(fā)方式1、傳統(tǒng)開發(fā)方式2、將接口視為資源文件1.)springmvc工程2.)springboot工程3.)nginx代理 三、接口數(shù)據(jù)如何更新1、原始數(shù)據(jù)文件生成接口數(shù)據(jù)1.)定義啟動類2.)啟動監(jiān)聽3.)文…

文章目錄

  • 一、需求概述
  • 二、開發(fā)方式
    • 1、傳統(tǒng)開發(fā)方式
    • 2、將接口視為資源文件
      • 1.)springmvc工程
      • 2.)springboot工程
      • 3.)nginx代理
  • 三、接口數(shù)據(jù)如何更新
    • 1、原始數(shù)據(jù)文件生成接口數(shù)據(jù)
      • 1.)定義啟動類
      • 2.)啟動監(jiān)聽
      • 3.)文件處理
      • 4.) 完整代碼
    • 2、借助crontab定時執(zhí)行

一、需求概述

通用查詢類接口的需求,在開發(fā)過程中是比較常見的一類需求,一般具有以下的特點:

  1. 數(shù)據(jù)更新頻率較低
  2. 無強制鑒權(quán)需求
  3. 短時間內(nèi)數(shù)據(jù)內(nèi)容固定

二、開發(fā)方式

1、傳統(tǒng)開發(fā)方式

傳統(tǒng)的開發(fā)方式,偏向于遵循MVC 模式使用@RestController注解來定義restful接口來進行后續(xù)開發(fā)。此開發(fā)模式大部分開發(fā)人員已經(jīng)司空見慣,駕輕就熟不再詳細(xì)闡述。

2、將接口視為資源文件

具體做法分為以下幾種情況

1.)springmvc工程

springmvc工程配置文件一般為spring-mvc.xml,在此文件添加如下配置指向外部文件目錄

	<mvc:resources mapping="/pics/**" location="file:C:\Users\DELL\Pictures\" />

注意:需要以file:絕對文件路徑 方式配置

參考項目:https://gitee.com/00fly/java-code-frame/blob/master/springmvc-dbutils/

2.)springboot工程

springboot工程一般以javaCofig代碼方式定義資源文件映射

@Slf4j
@Configuration
@ConditionalOnWebApplication
public class WebMvcConfig implements WebMvcConfigurer
{....../*** 加載靜態(tài)資源文件或文件映射<br>* 映射路徑優(yōu)先級順序為:META-INF/resources > resources > static > public*/@Overridepublic void addResourceHandlers(final ResourceHandlerRegistry registry){try{registry.addResourceHandler("/pics/**").addResourceLocations("classpath:/data/pic/");registry.addResourceHandler("/upload/**").addResourceLocations("file:" + new File("./upload/").getCanonicalPath() + "/");}catch (IOException e){log.error(e.getMessage(), e);}}

參考項目:https://gitcode.com/00fly/springboot-hello/
示例:https://00fly.online/upload/data.json

3.)nginx代理

nginx代理更方便,只需要在nginx根目錄添加文件即可
典型的nginx配置文件如下:
default.conf

server {listen       80;server_name  localhost;#access_log  /var/log/nginx/host.access.log  main;location / {root   /usr/share/nginx/html;index  index.html index.htm;} 
}

我們只需在目錄 /usr/share/nginx/html 放入資源文件即可。

示例:http://124.71.129.204/data.json

三、接口數(shù)據(jù)如何更新

上部分我們已經(jīng)解決了接口發(fā)布和訪問的問題,不要忘了:通用查詢類接口仍然有數(shù)據(jù)更新的需求,我們?nèi)绾蝸斫鉀Q這個需求呢?

1、原始數(shù)據(jù)文件生成接口數(shù)據(jù)

具體概括為:監(jiān)聽原始數(shù)據(jù)文件,當(dāng)數(shù)據(jù)發(fā)生變化時,生成接口數(shù)據(jù)文件,適用于數(shù)據(jù)不定期更新

原始數(shù)據(jù):點擊獲取

1.)定義啟動類


import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.stream.Collectors;
import java.util.stream.Stream;import org.apache.commons.lang3.StringUtils;import lombok.extern.slf4j.Slf4j;@Slf4j
public class MainRun
{/*** 文件監(jiān)聽程序一直運行* * @param args* @throws IOException*/public static void main(String[] args)throws IOException{// 默認(rèn)監(jiān)聽項目當(dāng)前目錄String path = new File("").getCanonicalPath();URL url = MainRun.class.getProtectionDomain().getCodeSource().getLocation();if (url.getPath().endsWith(".jar")){log.info("please start jar like: java -jar files-listener-0.0.1.jar --path=/work/test");path = Stream.of(args).filter(arg -> arg.contains("--path")).map(arg -> StringUtils.substringAfter(arg, "=")).collect(Collectors.joining());if (StringUtils.isBlank(path) || !new File(path).exists() || !new File(path).isDirectory()){log.error("please check path is a exist directory!");return;}}FileMonitor.initJsonFilesMonitor(path);}
}

2.)啟動監(jiān)聽


import java.io.File;
import java.util.concurrent.TimeUnit;import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;import com.fly.simple.service.JsonDataService;import lombok.extern.slf4j.Slf4j;/*** 監(jiān)聽文件變化*/
@Slf4j
public class FileMonitor
{/*** 初始化文件監(jiān)聽器*/public static void initJsonFilesMonitor(String path){try{log.info("start monitor {} ......", path);FileAlterationObserver observer = new FileAlterationObserver(path, FileFilterUtils.suffixFileFilter(".json"));File dir = new File(path);observer.addListener(new FileAlterationListenerAdaptor(){@Overridepublic void onFileCreate(File file){log.info("★★★★★★★★ {} created.", file.getName());JsonDataService.parseDir(dir);}@Overridepublic void onFileChange(File file){log.info("★★★★★★★★ {} changed.", file.getName());JsonDataService.parseDir(dir);}@Overridepublic void onFileDelete(File file){log.info("★★★★★★★★ {} deleted.", file.getName());JsonDataService.parseDir(dir);}});// 開始監(jiān)聽new FileAlterationMonitor(TimeUnit.SECONDS.toMillis(10), observer).start();}catch (Exception e){log.error(e.getMessage(), e.getCause());}}
}

3.)文件處理


import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;import org.apache.commons.io.FileUtils;import com.fly.simple.entity.Article;
import com.fly.simple.entity.BlogData;
import com.fly.simple.utils.JsonBeanUtils;import lombok.extern.slf4j.Slf4j;/*** JsonData服務(wù)類*/
@Slf4j
public class JsonDataService
{private static File dir = new File(ResourceBundle.getBundle("config").getString("out"));public static void parseDir(File directory){try{// 遍歷目錄下json文件Collection<File> files = FileUtils.listFiles(directory, new String[] {"json"}, false);List<Article> data = files.stream().map(f -> parseToArticles(f)).flatMap(List::stream).distinct().collect(Collectors.toList());FileUtils.writeStringToFile(dir, JsonBeanUtils.beanToJson(data, true), StandardCharsets.UTF_8, false);log.info("articles length : {}", data.size());}catch (IOException e){log.error(e.getMessage(), e);}}/*** 解析File為List* * @param resource* @return*/private static List<Article> parseToArticles(File file){try{String jsonData = FileUtils.readFileToString(file, StandardCharsets.UTF_8);return JsonBeanUtils.jsonToBean(jsonData, BlogData.class, true).getData().getList();}catch (IOException e){log.error(e.getMessage(), e);return Collections.emptyList();}}
}

4.) 完整代碼

https://gitee.com/00fly/effict-side/tree/master/files-listener

2、借助crontab定時執(zhí)行

具體概括為:按照設(shè)定時間點生成接口數(shù)據(jù)文件,適用于數(shù)據(jù)固定周期更新

files-listener項目根目錄執(zhí)行打包

mvn clean package -f pom-json.xml

執(zhí)行后會在target文件目錄生成files-listener-0.0.1.jar,將jar上傳到服務(wù)器目錄如:/work/files-listener-0.0.1.jar
命令行執(zhí)行

#查看定時任務(wù)
crontab -l#編輯定時任務(wù)
crontab -e

編輯時輸入以下內(nèi)容

0 */12 * * * java -jar /work/files-listener-0.0.1.jar

此命令實現(xiàn),每12小時執(zhí)行一次Jar

不再詳細(xì)闡述,實現(xiàn)思路具體請查閱文章:服務(wù)器docker應(yīng)用一覽


有任何問題和建議,都可以向我提問討論,大家一起進步,謝謝!

-over-

http://m.risenshineclean.com/news/65687.html

相關(guān)文章:

  • 網(wǎng)站技術(shù)規(guī)劃微信管理
  • 國外網(wǎng)站開發(fā)技術(shù)現(xiàn)狀高平網(wǎng)站優(yōu)化公司
  • 寧波建網(wǎng)站公司店鋪在百度免費定位
  • 杭州企業(yè)網(wǎng)站優(yōu)化短視頻營銷常用平臺有
  • 魔法網(wǎng)站小程序開發(fā)放單平臺大全app
  • 做外匯需要關(guān)注哪幾個網(wǎng)站企業(yè)產(chǎn)品推廣運營公司
  • 怎么查詢一個網(wǎng)站有沒有做競價谷歌外鏈代發(fā)
  • 網(wǎng)站建設(shè)新聞中心百度快照客服電話
  • 天津行業(yè)建站長春網(wǎng)站優(yōu)化流程
  • 網(wǎng)站編輯工具軟文廣告投放平臺
  • 怎么做視頻解析的網(wǎng)站如何設(shè)置友情鏈接
  • 抄襲網(wǎng)站案例seo查詢友情鏈接
  • 深圳有名的做公司網(wǎng)站廣州私人做網(wǎng)站
  • 紅杭州網(wǎng)站建設(shè)推銷廣告
  • 開發(fā)網(wǎng)站開發(fā)工程師附近的教育培訓(xùn)機構(gòu)有哪些
  • 浦東新區(qū)建設(shè)交通委網(wǎng)站鄭州seo線下培訓(xùn)
  • 青島網(wǎng)絡(luò)優(yōu)化seo 頁面
  • 多種語言獨立網(wǎng)站wordpress抖音廣告怎么投放
  • 無人高清影視在線觀看seo運營招聘
  • 佛山網(wǎng)站建設(shè)是哪個好東莞谷歌推廣
  • html5網(wǎng)站導(dǎo)航品牌策略怎么寫
  • 做家教網(wǎng)站要多少錢google安卓手機下載
  • 河南省城鄉(xiāng)建設(shè)廳官網(wǎng)seo優(yōu)化中商品權(quán)重主要由什么決定
  • 網(wǎng)站設(shè)計流程包括百度指數(shù)app官方下載
  • 商標(biāo) 做網(wǎng)站 是幾類谷歌seo優(yōu)化
  • 做網(wǎng)站應(yīng)該怎么做行業(yè)數(shù)據(jù)統(tǒng)計網(wǎng)站
  • 石家莊哪有個人建站的網(wǎng)頁設(shè)計素材網(wǎng)站
  • 做童裝在哪個網(wǎng)站找客戶搜索引擎優(yōu)化seo方案
  • 推銷別人做網(wǎng)站有什么作用專業(yè)搜索引擎優(yōu)化電話
  • 南京整站優(yōu)化推廣和競價代運營