Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
御承扬
Campus
提交
cf31d83d
C
Campus
项目概览
御承扬
/
Campus
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Campus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cf31d83d
编写于
6月 15, 2020
作者:
7
7wc98#14
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update
上级
8ab976c9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
145 addition
and
5 deletion
+145
-5
src/main/java/com/pyc/campus/config/WebMVCConfig.java
src/main/java/com/pyc/campus/config/WebMVCConfig.java
+1
-0
src/main/java/com/pyc/campus/controller/ChatController.java
src/main/java/com/pyc/campus/controller/ChatController.java
+24
-0
src/main/java/com/pyc/campus/domain/PublishMessage.java
src/main/java/com/pyc/campus/domain/PublishMessage.java
+10
-0
src/main/java/com/pyc/campus/domain/ResponseMessage.java
src/main/java/com/pyc/campus/domain/ResponseMessage.java
+20
-0
src/main/resources/templates/PublicChatRoom.html
src/main/resources/templates/PublicChatRoom.html
+89
-0
src/main/resources/templates/page/ManageUser.html
src/main/resources/templates/page/ManageUser.html
+0
-5
src/main/resources/templates/page/UserCenter.html
src/main/resources/templates/page/UserCenter.html
+1
-0
未找到文件。
src/main/java/com/pyc/campus/config/WebMVCConfig.java
浏览文件 @
cf31d83d
...
...
@@ -24,5 +24,6 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter {
// registry.addViewController("/login").setViewName("page/Login");
// registry.addViewController("/home").setViewName("page/Home");
registry
.
addViewController
(
"/aboutLearn"
).
setViewName
(
"page/AboutLearn"
);
registry
.
addViewController
(
"/publicChatRoom"
).
setViewName
(
"PublicChatRoom"
);
}
}
src/main/java/com/pyc/campus/controller/ChatController.java
0 → 100644
浏览文件 @
cf31d83d
//IntelliJ IDEA
//campus
//ChatController
//2020/6/15
// Author:御承扬
//E-mail:2923616405@qq.com
package
com.pyc.campus.controller
;
import
com.pyc.campus.domain.PublishMessage
;
import
com.pyc.campus.domain.ResponseMessage
;
import
org.springframework.messaging.handler.annotation.MessageMapping
;
import
org.springframework.messaging.handler.annotation.SendTo
;
import
org.springframework.stereotype.Controller
;
@Controller
public
class
ChatController
{
@MessageMapping
(
"/publicChatRoom"
)
@SendTo
(
"/publicChat/getResponse"
)
public
ResponseMessage
say
(
PublishMessage
message
)
throws
Exception
{
Thread
.
sleep
(
500
);
return
new
ResponseMessage
(
message
.
getName
()+
":"
+
message
.
getContent
());
}
}
src/main/java/com/pyc/campus/domain/PublishMessage.java
浏览文件 @
cf31d83d
...
...
@@ -8,4 +8,14 @@
package
com.pyc.campus.domain
;
public
class
PublishMessage
{
private
String
content
;
private
String
name
;
public
String
getContent
()
{
return
content
;
}
public
String
getName
()
{
return
name
;
}
}
src/main/java/com/pyc/campus/domain/ResponseMessage.java
0 → 100644
浏览文件 @
cf31d83d
//IntelliJ IDEA
//campus
//ResponseMessage
//2020/6/15
// Author:御承扬
//E-mail:2923616405@qq.com
package
com.pyc.campus.domain
;
public
class
ResponseMessage
{
private
final
String
responseMessageContent
;
public
ResponseMessage
(
String
responseMessageContent
){
this
.
responseMessageContent
=
responseMessageContent
;
}
public
String
getResponseMessageContent
()
{
return
responseMessageContent
;
}
}
src/main/resources/templates/PublicChatRoom.html
0 → 100644
浏览文件 @
cf31d83d
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
lang=
"en"
>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
<title>
公共聊天室
</title>
<style>
body
{
font-family
:
Helvetica
Neue
,
Helvetica
,
Arial
,
sans-serif
;
font-size
:
14px
;
color
:
#000
;
margin
:
0
;
padding
:
0
;
background
:
#eee
url("../static/images/campus/logo.jpg")
center
no-repeat
fixed
;
}
.main
{
margin
:
10px
auto
;
width
:
800px
;
height
:
700px
;
}
</style>
</head>
<body
onload=
"disconnect()"
>
<noscript><h2
style=
"color: red"
>
貌似您的浏览器不支持WebSocket
</h2>
</noscript>
<div
class=
"main"
>
<div>
<div>
<button
id=
"connect"
onclick=
"connect();"
>
连接
</button>
<button
id=
"disconnect"
disabled=
"disabled"
onclick=
"disconnect();"
>
断开连接
</button>
</div>
<div
id=
"conversationDiv"
>
<label
for=
"name"
>
输入名字:
</label><input
type=
"text"
id=
"name"
/>
<label
for=
"content"
>
输入消息:
</label><input
type=
"text"
id=
"content"
>
<button
id=
"sendName"
onclick=
"sendName();"
>
发送
</button>
<br><h1>
聊天记录框
</h1>
<div
id=
"response"
style=
"width: 500px;min-height:600px;height: auto;font-size: 26px;border: 1px solid black;"
></div>
</div>
</div>
</div>
<script
src=
"js/sockjs.min.js"
></script>
<script
src=
"js/stomp.min.js"
></script>
<script
src=
"js/jquery.js"
></script>
<script
type=
"text/javascript"
>
var
stompClient
=
null
;
function
setConnected
(
connected
)
{
document
.
getElementById
(
'
connect
'
).
disabled
=
connected
;
document
.
getElementById
(
'
disconnect
'
).
disabled
=
!
connected
;
document
.
getElementById
(
'
conversationDiv
'
).
style
.
visibility
=
connected
?
'
visible
'
:
'
hidden
'
;
$
(
'
#response
'
).
html
();
}
function
connect
()
{
var
socket
=
new
SockJS
(
'
/endpointPublicChat
'
);
//1
stompClient
=
Stomp
.
over
(
socket
);
stompClient
.
connect
({},
function
(
frame
)
{
setConnected
(
true
);
console
.
log
(
'
Connected:
'
+
frame
);
stompClient
.
subscribe
(
'
/publicChat/getResponse
'
,
function
(
response
){
//2
showResponse
(
JSON
.
parse
(
response
.
body
).
responseMessageContent
);
});
});
}
function
disconnect
()
{
if
(
stompClient
!=
null
)
{
stompClient
.
disconnect
();
}
setConnected
(
false
);
console
.
log
(
"
Disconnected
"
);
}
function
sendName
()
{
var
name
=
$
(
'
#name
'
).
val
();
var
content
=
$
(
'
#content
'
).
val
();
//3
stompClient
.
send
(
"
/publicChatRoom
"
,
{},
JSON
.
stringify
({
'
name
'
:
name
,
'
content
'
:
content
}));
}
function
showResponse
(
message
)
{
// var response = $("#response");
// response.html(message+"
<
br
>
"
);
var div = document.getElementById(
"
response
"
);
var p = document.createElement(
"
p
"
);
p.innerHTML=message;
div.append(p);
}
</script>
</body>
\ No newline at end of file
src/main/resources/templates/page/ManageUser.html
浏览文件 @
cf31d83d
...
...
@@ -33,11 +33,6 @@
width
:
800px
;
height
:
700px
;
}
.questions-list
{
margin
:
10px
auto
;
width
:
800px
;
height
:
auto
;
}
</style>
</head>
<body>
...
...
src/main/resources/templates/page/UserCenter.html
浏览文件 @
cf31d83d
...
...
@@ -87,6 +87,7 @@
<li><a
href=
"/toQueryGrade"
>
查看课程成绩
</a>
</li>
<li><a
href=
"/toUpQuestion"
>
申请问题悬赏
</a>
</li>
<li><a
href=
"/toBrowserQuestion"
>
浏览悬赏问题
</a>
</li>
<li><a
href=
"/publicChatRoom"
>
公共聊天室
</a>
</li>
</ul>
<hr
class=
"hidden-sm hidden-md hidden-lg"
>
</div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录