how2j.cn

下载区
文件名 文件大小
请先登录 353k
增值内容 353k
353k
使用站长秘制下载工具

4分51秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)

步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 指数数据   
步骤 4 : IndexData   
步骤 5 : IndexDataService   
步骤 6 : IndexDataController   
步骤 7 : 测试   

步骤 1 :

先运行,看到效果,再学习

edit edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.pojo; public class IndexData { String date; float closePoint; public String getDate() { return date; } public void setDate(String date) { this.date = date; } public float getClosePoint() { return closePoint; } public void setClosePoint(float closePoint) { this.closePoint = closePoint; } }
package cn.how2j.trend.pojo;

public class IndexData {

	String date;
	float closePoint;
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public float getClosePoint() {
		return closePoint;
	}
	public void setClosePoint(float closePoint) {
		this.closePoint = closePoint;
	}
	
}
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
IndexDataService
package cn.how2j.trend.service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import cn.how2j.trend.pojo.IndexData; import cn.how2j.trend.util.SpringContextUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.convert.Convert; @Service @CacheConfig(cacheNames="index_datas") public class IndexDataService { private Map<String, List<IndexData>> indexDatas=new HashMap<>(); @Autowired RestTemplate restTemplate; @HystrixCommand(fallbackMethod = "third_part_not_connected") public List<IndexData> fresh(String code) { List<IndexData> indexeDatas =fetch_indexes_from_third_part(code); indexDatas.put(code, indexeDatas); System.out.println("code:"+code); System.out.println("indexeDatas:"+indexDatas.get(code).size()); IndexDataService indexDataService = SpringContextUtil.getBean(IndexDataService.class); indexDataService.remove(code); return indexDataService.store(code); } @CacheEvict(key="'indexData-code-'+ #p0") public void remove(String code){ } @CachePut(key="'indexData-code-'+ #p0") public List<IndexData> store(String code){ return indexDatas.get(code); } @Cacheable(key="'indexData-code-'+ #p0") public List<IndexData> get(String code){ return CollUtil.toList(); } public List<IndexData> fetch_indexes_from_third_part(String code){ List<Map> temp= restTemplate.getForObject("http://127.0.0.1:8090/indexes/"+code+".json",List.class); return map2IndexData(temp); } private List<IndexData> map2IndexData(List<Map> temp) { List<IndexData> indexDatas = new ArrayList<>(); for (Map map : temp) { String date = map.get("date").toString(); float closePoint = Convert.toFloat(map.get("closePoint")); IndexData indexData = new IndexData(); indexData.setDate(date); indexData.setClosePoint(closePoint); indexDatas.add(indexData); } return indexDatas; } public List<IndexData> third_part_not_connected(String code){ System.out.println("third_part_not_connected()"); IndexData index= new IndexData(); index.setClosePoint(0); index.setDate("n/a"); return CollectionUtil.toList(index); } }
步骤 6 :

IndexDataController

edit edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.web; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import cn.how2j.trend.pojo.IndexData; import cn.how2j.trend.service.IndexDataService; @RestController public class IndexDataController { @Autowired IndexDataService indexDataService; // http://127.0.0.1:8001/freshIndexData/000300 // http://127.0.0.1:8001/getIndexData/000300 // http://127.0.0.1:8001/removeIndexData/000300 @GetMapping("/freshIndexData/{code}") public String fresh(@PathVariable("code") String code) throws Exception { indexDataService.fresh(code); return "fresh index data successfully"; } @GetMapping("/getIndexData/{code}") public List<IndexData> get(@PathVariable("code") String code) throws Exception { return indexDataService.get(code); } @GetMapping("/removeIndexData/{code}") public String remove(@PathVariable("code") String code) throws Exception { indexDataService.remove(code); return "remove index data successfully"; } }
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,379个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-趋势投资SpringCloud-采集和储存微服务-指数数据 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 982790551
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图