首页 技术 正文
技术 2022年11月14日
0 收藏 849 点赞 2,379 浏览 1206 个字

感谢JDK8,让我们JAVA 程序员暂时不用担心失业.

有些情况,需要根据用户输入值,即时查询数据库,MYSQL显然不再适合这种业务.

mongoDB看似最适合,但是为了这么一个破功能,也不值得特意去搞一个

根据现有的redis,配合JDK8并行数据流,效果还不错

 <input autocomplete="off" data-provide="typeahead" class="form-control input-sm" name="itemCode" id="itemCode" placeholder="物品编码">
   function fillLocalData(typeaheadObj) {        $(typeaheadObj).typeahead({            source: function (query, process) {                if (isBlank(query) && query.length < 3)                    return;                $.get("/searchByKeyWord/" + query, function (data) {                    if (data.operateCode == "S") {                        process(data.datas);                    }                });            },//            items: 8,//最多显示个数            updater: function (item) {                return item.split(":")[0];//这里一定要return,否则选中不显示,外加调用display的时候null reference错误。            },            displayText: function (item) {                return item;//返回字符串            },            afterSelect: function (item) {                //选择项之后的事件 ,item是当前选中的。            },            delay: 0//延迟时间        });    }

数据在程序启动的时候已经缓存到redis键是ITEM_MAP

    public Map<String,String> getCacheMap() {        BoundHashOperations<String, String, String> hashOperations = redisTemplate.boundHashOps(ITEM_MAP);        return hashOperations.entries();    }

并行数据流在一定程度上弥补了redis查询的弱势

public String [] searchByKeyWord(String keyWord){        Map<String,String> cacheMap = this.getCacheMap();    return cacheMap.entrySet().stream().parallel().filter(entry->entry.getValue().indexOf(keyWord)!=-1).map(val->val.getKey()+":"+val.getValue()).limit(5).toArray(String [] ::new);}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,893
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,421
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,240
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,052
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,683
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,718