forked from xdxTao/xdxIm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abb2f24
Showing
47 changed files
with
14,574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### xdxim1.0 | ||
|
||
基于websocket实现的聊天系统demo,如果你想做一个im聊天工具苦于找不到思路那么请看看xdxim1.0吧,一定会让你有所收获的。 | ||
|
||
**前端:** vue、elementUI、axios <br/> | ||
**后端:** springBoot <br/> | ||
**数据库:** mySql | ||
|
||
<br/> | ||
|
||
### xdxim2.0 | ||
|
||
敬请期待 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**基于websocket实现的聊天系统demo,如果你想做一个im聊天工具苦于找不到思路那么请看看xdxim1.0吧,一定会让你有所收获的。** | ||
|
||
如果对你有帮助可以关注我的微信公众号一个有趣的程序员:小道仙97 | ||
|
||
B站视频地址: | ||
|
||
文章地址:[https://www.xdx97.com/article/801097898778427392](https://www.xdx97.com/article/801097898778427392) | ||
|
||
<br/> | ||
|
||
### 一、运行demo | ||
|
||
下载代码后,先配置好数据库(other包下面有数据库)。启动java项目后访问 **http:127.0.0.1:1997** 即可 | ||
|
||
<br/> | ||
|
||
### 二、自己修改 | ||
|
||
如果你要修改你就要自己启动前端项目了,先安装node,然后安装npm。最后 npm run serve 即可。 | ||
|
||
<br/> | ||
|
||
### 三、其它 | ||
|
||
如果你修改完成之后也只想启动一个项目,就打包vue(npm run build)丢到java的static目录下面即可。(注意ip地址的修改) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ww.xdx97.com</groupId> | ||
<artifactId>socketDemo</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<!-- 导入SpringBoot项目依赖 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<version>2.2.0.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>2.2.0.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-websocket</artifactId> | ||
<version>2.2.0.RELEASE</version> | ||
</dependency> | ||
<!-- jackson --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.11.2</version> | ||
</dependency> | ||
<!-- MySQL 连接驱动依赖 --> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.19</version> | ||
</dependency> | ||
<!-- mysql数据库连接池 pool --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid-spring-boot-starter</artifactId> | ||
<version>1.1.23</version> | ||
</dependency> | ||
<!-- Spring Boot Mybatis 依赖 --> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>2.1.3</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>2.2.0.RELEASE</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.xdx97.socket; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class App { | ||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
xdxim1.0/java/src/main/java/com/xdx97/socket/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.xdx97.socket; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
import org.springframework.web.filter.CorsFilter; | ||
|
||
/** | ||
* 解决跨域请求的 | ||
*/ | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
private CorsConfiguration buildConfig() { | ||
CorsConfiguration corsConfiguration = new CorsConfiguration(); | ||
// 你需要跨域的地址 注意这里的 127.0.0.1 != localhost | ||
// * 表示对所有的地址都可以访问 | ||
corsConfiguration.addAllowedOrigin("*"); | ||
// 跨域的请求头 | ||
corsConfiguration.addAllowedHeader("*"); // 2 | ||
// 跨域的请求方法 | ||
corsConfiguration.addAllowedMethod("*"); // 3 | ||
//加上了这一句,大致意思是可以携带 cookie | ||
//最终的结果是可以 在跨域请求的时候获取同一个 session | ||
corsConfiguration.setAllowCredentials(true); | ||
return corsConfiguration; | ||
} | ||
@Bean | ||
public CorsFilter corsFilter() { | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
//配置 可以访问的地址 | ||
source.registerCorsConfiguration("/**", buildConfig()); // 4 | ||
return new CorsFilter(source); | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
xdxim1.0/java/src/main/java/com/xdx97/socket/bean/MsgInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package com.xdx97.socket.bean; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* 消息实体 | ||
* | ||
* @author 小道仙 | ||
*/ | ||
public class MsgInfo implements Serializable { | ||
/** | ||
* 消息id | ||
*/ | ||
private Integer id; | ||
|
||
/** | ||
* 消息发送者id | ||
*/ | ||
private Integer fromUserId; | ||
|
||
/** | ||
* 消息发送者名称 | ||
*/ | ||
private String fromUserName; | ||
|
||
/** | ||
* 消息接收者id | ||
*/ | ||
private Integer toUserId; | ||
|
||
/** | ||
* 消息接收者名称 | ||
*/ | ||
private String toUserName; | ||
|
||
/** | ||
* 消息内容 | ||
*/ | ||
private String content; | ||
|
||
/** | ||
* 消息发送时间 | ||
*/ | ||
private Date createTime; | ||
|
||
/** | ||
* 是否已读(1 已读) | ||
*/ | ||
private Integer unReadFlag; | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public Integer getFromUserId() { | ||
return fromUserId; | ||
} | ||
|
||
public void setFromUserId(Integer fromUserId) { | ||
this.fromUserId = fromUserId; | ||
} | ||
|
||
public String getFromUserName() { | ||
return fromUserName; | ||
} | ||
|
||
public void setFromUserName(String fromUserName) { | ||
this.fromUserName = fromUserName; | ||
} | ||
|
||
public Integer getToUserId() { | ||
return toUserId; | ||
} | ||
|
||
public void setToUserId(Integer toUserId) { | ||
this.toUserId = toUserId; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
|
||
public Date getCreateTime() { | ||
return createTime; | ||
} | ||
|
||
public void setCreateTime(Date createTime) { | ||
this.createTime = createTime; | ||
} | ||
|
||
public Integer getUnReadFlag() { | ||
return unReadFlag; | ||
} | ||
|
||
public void setUnReadFlag(Integer unReadFlag) { | ||
this.unReadFlag = unReadFlag; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object that) { | ||
if (this == that) { | ||
return true; | ||
} | ||
if (that == null) { | ||
return false; | ||
} | ||
if (getClass() != that.getClass()) { | ||
return false; | ||
} | ||
MsgInfo other = (MsgInfo) that; | ||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) | ||
&& (this.getFromUserId() == null ? other.getFromUserId() == null : this.getFromUserId().equals(other.getFromUserId())) | ||
&& (this.getFromUserName() == null ? other.getFromUserName() == null : this.getFromUserName().equals(other.getFromUserName())) | ||
&& (this.getToUserId() == null ? other.getToUserId() == null : this.getToUserId().equals(other.getToUserId())) | ||
&& (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent())) | ||
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) | ||
&& (this.getUnReadFlag() == null ? other.getUnReadFlag() == null : this.getUnReadFlag().equals(other.getUnReadFlag())); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); | ||
result = prime * result + ((getFromUserId() == null) ? 0 : getFromUserId().hashCode()); | ||
result = prime * result + ((getFromUserName() == null) ? 0 : getFromUserName().hashCode()); | ||
result = prime * result + ((getToUserId() == null) ? 0 : getToUserId().hashCode()); | ||
result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode()); | ||
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); | ||
result = prime * result + ((getUnReadFlag() == null) ? 0 : getUnReadFlag().hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(getClass().getSimpleName()); | ||
sb.append(" ["); | ||
sb.append("Hash = ").append(hashCode()); | ||
sb.append(", id=").append(id); | ||
sb.append(", fromUserId=").append(fromUserId); | ||
sb.append(", fromUserName=").append(fromUserName); | ||
sb.append(", toUserId=").append(toUserId); | ||
sb.append(", content=").append(content); | ||
sb.append(", createTime=").append(createTime); | ||
sb.append(", unReadFlag=").append(unReadFlag); | ||
sb.append(", serialVersionUID=").append(serialVersionUID); | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
|
||
public String getToUserName() { | ||
return toUserName; | ||
} | ||
|
||
public void setToUserName(String toUserName) { | ||
this.toUserName = toUserName; | ||
} | ||
} |
Oops, something went wrong.