package com.redis.chat.controller;
import com.redis.chat.model.ChatSubscribeModel;
import com.redis.chat.redis.JedisClientSingle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import javax.annotation.PostConstruct;
import java.util.List;
@Controller
public class IndexController {
@Autowired
private JedisClientSingle jedisClientSingle;
@RequestMapping(value = "")
public String index() {
return "index";
}
@PostConstruct
public void action() {
//启动一个线程去获取数据
new Thread(new Runnable() {
public void run() {
try {
String room = "lsy";
ChatSubscribeModel subscribe = new ChatSubscribeModel();
jedisClientSingle.subscribe(subscribe, room);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
@RequestMapping(value = "/sendmessage")
public void sendmessage(String message) {
//这里使用spring整合的jedisPool,使用一会就不能使用了。
//先这样写吧
JedisPool jedisPool = new JedisPool("127.0.0.1",6379);
Jedis jedis = jedisPool.getResource();
jedis.publish("lsy",message);
jedis.close();
jedisPool.close();
}
@RequestMapping(value = "/receiveMessage")
@ResponseBody
public List<String> receiveMessage() {
return ChatSubscribeModel.messagelist;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
chat.zip (66个子文件)
chat
src
.DS_Store 6KB
main
resources
resource
Params.properties 0B
spring
applicationContext-service.xml 634B
springmvc.xml 2KB
applicationContext-redis.xml 2KB
.DS_Store 6KB
.DS_Store 8KB
java
com
.DS_Store 6KB
redis
chat
controller
IndexController.java 2KB
model
ChatSubscribeModel.java 1KB
redis
JedisClientSingle.java 1KB
JedisClient.java 218B
service
.DS_Store 6KB
.DS_Store 6KB
webapp
.DS_Store 6KB
res-build
res
jquery
jquery-1.8.3.min.js 91KB
jquery-form.js 44KB
jquery-1.8.3.js 260KB
jquery-1.11.2.min.js 94KB
src
index.js 1KB
.DS_Store 6KB
WEB-INF
jsp
index.jsp 6KB
.DS_Store 6KB
web.xml 2KB
.DS_Store 6KB
pom.xml 3KB
target
classes
com
redis
chat
controller
IndexController$1.class 1KB
IndexController.class 2KB
model
ChatSubscribeModel.class 2KB
redis
JedisClient.class 261B
JedisClientSingle.class 2KB
resource
Params.properties 0B
spring
applicationContext-service.xml 634B
springmvc.xml 2KB
applicationContext-redis.xml 2KB
generated-sources
annotations
.idea
misc.xml 566B
encodings.xml 236B
libraries
Maven__org_springframework_spring_web_4_1_3_RELEASE.xml 597B
Maven__commons_logging_commons_logging_1_2.xml 546B
Maven__org_apache_commons_commons_pool2_2_3.xml 544B
Maven__aopalliance_aopalliance_1_0.xml 502B
Maven__org_springframework_spring_aspects_4_1_3_RELEASE.xml 625B
Maven__org_aspectj_aspectjweaver_1_8_4.xml 530B
Maven__org_springframework_spring_webmvc_4_1_3_RELEASE.xml 618B
Maven__com_fasterxml_jackson_core_jackson_databind_2_7_3.xml 611B
Maven__org_springframework_spring_tx_4_1_3_RELEASE.xml 590B
Maven__org_springframework_spring_beans_4_1_3_RELEASE.xml 611B
Maven__com_fasterxml_jackson_core_jackson_core_2_7_3.xml 583B
Maven__org_springframework_spring_core_4_1_3_RELEASE.xml 604B
Maven__javax_servlet_servlet_api_2_5.xml 510B
Maven__org_springframework_spring_aop_4_1_3_RELEASE.xml 597B
Maven__org_springframework_spring_jdbc_4_1_3_RELEASE.xml 604B
Maven__javax_servlet_jsp_api_2_0.xml 482B
Maven__redis_clients_jedis_2_7_2.xml 482B
Maven__org_springframework_spring_context_4_1_3_RELEASE.xml 625B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_7_3.xml 632B
Maven__jstl_jstl_1_2.xml 425B
Maven__org_springframework_spring_expression_4_1_3_RELEASE.xml 646B
workspace.xml 57KB
dictionaries
liaoshiyao.xml 89B
artifacts
chat_war_exploded.xml 3KB
chat_war.xml 284B
inspectionProfiles
Project_Default.xml 397B
compiler.xml 633B
modules.xml 248B
chat.iml 3KB
共 66 条
- 1
资源评论
- gzyftk2020-07-07初学者有些帮助.
IT贱男
- 粉丝: 1w+
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功