├── .idea
├── artifacts
│ └── HYCWeiboSystem_war_exploded.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── libraries
│ ├── fastjson_1_2_58.xml
│ └── mysql_connector_java_8_0_15.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── HYCWeiboSystem.iml
├── LICENSE
├── README.md
├── lib
├── fastjson-1.2.58.jar
├── jsp-api.jar
├── log4j-1.2.17.jar
├── mysql-connector-java-8.0.15.jar
├── servlet-api.jar
├── tomcat-api.jar
├── tomcat-juli.jar
├── tomcat-util.jar
├── tomcat-websocket.jar
└── websocket-api.jar
├── src
├── com
│ └── hyc
│ │ └── www
│ │ ├── controller
│ │ ├── annotation
│ │ │ └── ControllerConfig.java
│ │ ├── constant
│ │ │ └── ControllerMessage.java
│ │ └── impl
│ │ │ ├── filter
│ │ │ ├── EncodingFilter.java
│ │ │ └── LoginFilter.java
│ │ │ ├── listener
│ │ │ └── ServletContextListener.java
│ │ │ └── servlet
│ │ │ └── MyServlet.java
│ │ ├── dao
│ │ ├── BaseDao.java
│ │ ├── ChatDao.java
│ │ ├── DataSource.java
│ │ ├── FriendDao.java
│ │ ├── MemberDao.java
│ │ ├── MessageDao.java
│ │ ├── NewsDao.java
│ │ ├── RecordDao.java
│ │ ├── RemarkDao.java
│ │ ├── ReplyDao.java
│ │ ├── ResultMapper.java
│ │ ├── SQLMapper.java
│ │ ├── SQLRunner.java
│ │ ├── TweetDao.java
│ │ ├── UserDao.java
│ │ ├── annotation
│ │ │ ├── Delete.java
│ │ │ ├── Field.java
│ │ │ ├── Insert.java
│ │ │ ├── Param.java
│ │ │ ├── Query.java
│ │ │ ├── Result.java
│ │ │ ├── ResultType.java
│ │ │ ├── Table.java
│ │ │ └── Update.java
│ │ └── impl
│ │ │ ├── DataSourceImpl.java
│ │ │ └── SQLRunnerImpl.java
│ │ ├── exception
│ │ ├── DaoException.java
│ │ └── ServiceException.java
│ │ ├── factory
│ │ ├── DaoProxyFactory.java
│ │ ├── ServiceProxyFactory.java
│ │ └── proxy
│ │ │ └── ConnectionProxy.java
│ │ ├── model
│ │ ├── builder
│ │ │ ├── MessageVOBuilder.java
│ │ │ └── TweetVOBuilder.java
│ │ ├── dto
│ │ │ └── ServiceResult.java
│ │ ├── po
│ │ │ ├── Chat.java
│ │ │ ├── Friend.java
│ │ │ ├── Member.java
│ │ │ ├── Message.java
│ │ │ ├── News.java
│ │ │ ├── Record.java
│ │ │ ├── Remark.java
│ │ │ ├── Reply.java
│ │ │ ├── Tweet.java
│ │ │ ├── User.java
│ │ │ └── abs
│ │ │ │ └── BaseEntity.java
│ │ └── vo
│ │ │ ├── MemberVO.java
│ │ │ ├── MessageVO.java
│ │ │ ├── RemarkVO.java
│ │ │ └── TweetVO.java
│ │ ├── provider
│ │ ├── BaseProvider.java
│ │ ├── ChatProvider.java
│ │ ├── FriendProvider.java
│ │ ├── MessageProvider.java
│ │ ├── RemarkProvider.java
│ │ ├── TweetProvider.java
│ │ ├── UploadProvider.java
│ │ ├── UserProvider.java
│ │ ├── annotation
│ │ │ ├── Action.java
│ │ │ └── ActionProvider.java
│ │ └── constant
│ │ │ ├── RequestMethod.java
│ │ │ └── WebPage.java
│ │ ├── server
│ │ └── ChatServer.java
│ │ ├── service
│ │ ├── ChatService.java
│ │ ├── FriendService.java
│ │ ├── MessageService.java
│ │ ├── RemarkService.java
│ │ ├── ReplyService.java
│ │ ├── TweetService.java
│ │ ├── UploadService.java
│ │ ├── UserService.java
│ │ ├── annotation
│ │ │ ├── Admin.java
│ │ │ └── Freeze.java
│ │ ├── constants
│ │ │ ├── ChatType.java
│ │ │ ├── MessageType.java
│ │ │ ├── ServiceMessage.java
│ │ │ ├── Status.java
│ │ │ └── UserType.java
│ │ └── impl
│ │ │ ├── ChatServiceImpl.java
│ │ │ ├── FriendServiceImpl.java
│ │ │ ├── MessageServiceImpl.java
│ │ │ ├── RemarkServiceImpl.java
│ │ │ ├── TweetServiceImpl.java
│ │ │ ├── UploadServiceImpl.java
│ │ │ └── UserServiceImpl.java
│ │ ├── test
│ │ ├── TestDao.java
│ │ ├── TestDataSource.java
│ │ ├── TestJson.java
│ │ ├── TestLog.java
│ │ └── TestService.java
│ │ └── util
│ │ ├── BeanUtils.java
│ │ ├── ControllerUtils.java
│ │ ├── JdbcUtils.java
│ │ ├── Md5Utils.java
│ │ ├── ReflectUtils.java
│ │ ├── StringUtils.java
│ │ ├── UUIDUtils.java
│ │ └── UploadUtils.java
├── data_source.properties
├── debug.log
├── info.log
├── log4j.properties
└── proxy_factory.properties
├── web
├── WEB-INF
│ ├── c-1_0-rt.tld
│ ├── c-1_0.tld
│ ├── c.tld
│ ├── fmt-1_0-rt.tld
│ ├── fmt-1_0.tld
│ ├── fmt.tld
│ ├── fn.tld
│ ├── lib
│ │ ├── jstl.jar
│ │ ├── mysql-connector-java-8.0.15.jar
│ │ └── standard.jar
│ ├── permittedTaglibs.tld
│ ├── scriptfree.tld
│ ├── sql-1_0-rt.tld
│ ├── sql-1_0.tld
│ ├── sql.tld
│ ├── web.xml
│ ├── x-1_0-rt.tld
│ ├── x-1_0.tld
│ └── x.tld
├── agreement.html
├── error.jsp
├── home.jsp
├── index.jsp
├── login.jsp
├── register.jsp
├── static
│ ├── css
│ │ └── index.css
│ ├── img
│ │ ├── icon.ico
│ │ ├── logo.png
│ │ └── sys.png
│ └── js
│ │ └── ajax.js
└── upload
│ └── photo
│ ├── chat.jpg
│ ├── chat.png
│ ├── default_head.jpg
│ ├── images.png
│ ├── moment.jpg
│ ├── system.jpg
│ ├── user_photo.jpg
│ ├── 微信.png
│ ├── 用户头像.png
│ ├── 系统.jpg
│ └── 聊天总群.png
├── weibo.sql
└── 微博项目需求分析.xmind
/.idea/artifacts/HYCWeiboSystem_war_exploded.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/HYCWeiboSystem_war_exploded
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/libraries/fastjson_1_2_58.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/mysql_connector_java_8_0_15.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HYCWeiboSystem.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HYCWeiboSystem
2 | #### this is 黄钰朝‘s WeiboSystem
3 | ------
4 | 欢迎使用本软件,HYCWeiboSystem是一个类似微博的社交软件系统,主要由微博功能,微博相册,在线聊天,账户管理,关注和粉丝,好友管理,聊天记录管理,聊天群组等功能模块所组成。程序使用java作为后台开发语言,tomcat服务器,以及mysql数据库,以jsp实现界面展示,使用websocket和ajax,以及json实现前后端数据传输
5 |
6 | ------
7 | # 开发者信息:
8 | > 开发者:黄钰朝
9 | > 联系邮箱:kobe524348@gmail.com
10 | > 项目启动时间:2019-05-20
11 | > 版本号:1.0
12 | > 发布时间:2019-05-30
13 | > 开源许可:Apache License 2.0
14 | > 开发环境:
15 | ###### Idea IntelliJ IDEA 2019.1.1 (Ultimate Edition)
16 | ###### Build #IU-191.6707.61, built on April 16, 2019
17 | ###### Licensed to wu anjun
18 | ###### Subscription is active until January 8, 2020
19 | ###### JRE: 1.8.0_202-release-1483-b44 amd64
20 | ###### JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
21 | ###### Windows 10 10.0
22 |
23 | ------
24 |
25 | # 目录
26 | > * 安装运行
27 | > * 功能介绍
28 | > * 亮点介绍
29 | > * 错误处理
30 | > * 版权声明
31 |
32 | ------
33 |
34 | # 安装环境说明
35 | ### 安装环境
36 | > Tomcat版本:9.0.17
37 | > Jdk 版本:1.8
38 | > MySQL版本:5.7
39 | ### 配置说明
40 | - 数据库配置文件路径:项目路径/src/data_source.properties
41 | - sql文件路径: 项目路径/weibo.sql
42 | - log4j配置文件路径: 项目路径/log4j.properties
43 | - 数据库配置:
44 | ##### 在运行sql文件之后需要在数据库group表添加一个id为0的记录,作为默认好友分组,并且把user表的email为“微博团队“的用户的id设置为0,否则程序无法正常运行
45 | - multiConfig配置说明
46 | ##### 项目路径\src\com\hyc\www\controller\impl\servlet\MyServlet.java,在这个类的额注解中配置multiConfig的路径为"项目部署路径\web\upload"文件夹在系统中的绝对路径
47 | - log4j配置说明
48 | ##### 配置中有两处配置了日志文件的路径,根据实际将其修改为日志文件在系统中的绝对路径
49 | - 服务器主机名配置
50 | ##### 如果运行环境的主机名不是localhost:8080,需要修改/web/views/index.jsp文件的第二行配置,将host的值改为对应的主机名
51 | - contextPath配置
52 | ##### 如果是在tomcat部署,在server.xml中将项目路径映射为/weibo,如果是在idea中部署,在tomcat的deployment设置中将Application context设置为/weibo
53 | - 如果参照以上配置仍然存在问题,请参照本文档错误处理部分
54 |
55 | ----------
56 |
57 | # 基本操作
58 | - 登陆进入主页面,左边是菜单,右边是窗口
59 | - 查看微博,右上角选择不同分类
60 | - 点击评论按钮进行评论
61 | - 点击微博内容进入微博详情
62 | - 点击用户头像查看主页
63 | - 在主页点击“我的关注”查看我关注的人
64 |
65 | > 测试账号:
66 | - 管理员:账号:微博团队 密码:test1234
67 | - 用户1: 账号:test1@qq.com 密码:test1234
68 | - 用户2: 账号:test2@qq.com 密码:test1234
69 |
70 | -------
71 |
72 | # 完成的功能
73 | ### 基本需求
74 | ###### 游客
75 | - 根据不同的标签(搞笑、社会、时尚、电影、美女、体育、动漫等)查看不同的帖子
76 | ###### 用户
77 | - 在游客的基础上
78 | - 登录、修改用户信息
79 | - 我的关注(关注的人等)、我的粉丝、我的微博
80 | - 对帖子的评论,点赞,转发
81 | ###### 系统管理员
82 | - 管理用户、冻结用户等操作
83 | ### 进阶需求
84 | - 分页:采取分页的手段分段抽取后台的数据
85 | - 搜索功能:搜索用户
86 | - 支持图片上传:在发布微博时可添加图片
87 | - 我的相册:可查看发过的微博中的所有图片
88 | ### 升华需求
89 | - 实时聊天(私信):用户之间可创建聊天窗口进行聊天
90 | ### 吊炸天需求
91 | - 日志功能:对用户、管理员的操作进行日志记录
92 |
93 | ------
94 |
95 | # 项目亮点
96 | ## 功能亮点
97 | - 发微博支持多张图片,支持多重转发,支持点赞,评论,浏览量,分页查看
98 | - 支持用户实时聊天
99 | - 聊天支持发文字,图片,文件,保存聊天记录,管理聊天记录,更换聊天背景
100 | - 支持用户创建,加入群聊,管理群聊
101 | ## 技术亮点
102 | - 使用注解+反射实现controller请求自动分发
103 | - 使用动态代理+注解+反射实现操作权限校验
104 | - 使用动态代理+注解+反射实现Dao层纯接口无实现类
105 | - 使用代理工厂实现面向接口编程,service层,provider层使用工厂注入
106 | - 使用过滤器+cookie实现会话中免登陆,自动登陆
107 | - 使用原生ajax技术实现接近前后端分离(仍然使用jsp)
108 | - 使用数据库连接池(原生手写)+线程池提高性能
109 | - 使用缓存技术+队列数据结构实现聊天功能消息低延迟转发
110 | - 使用枚举类维护常量提高代码可维护性
111 | - service层与前端使用DTO统一数据传输格式
112 | - 使用动态代理实现代理数据库连接
113 |
114 | ------
115 |
116 | # 错误处理
117 | ### 1.第一次启动tomcat服务器访问时提示MyServlet这个类ClassNotFound?
118 | ##### 这种情况下需要重新热部署一下项目即可(redeploy),我不知道这个问题的具体原因,我查看编译后的的文件目录中是有这个class的...
119 | ### 2.无法访问?
120 | ##### 可能原因:没有将项目路径映射为/weibo。
121 | ### 3.图片加载不出?
122 | ##### 检查一下upload文件夹有没有配置路径映射...
123 | ### 4.日志文件或控制台中文乱码?
124 | ##### 请尝试在idea的tomcat中配置VMoption为-Dfile.encoding=UTF-8
125 | ### 5.网页点击无响应?
126 | ##### 请刷新浏览器,因为前端使用了ajax技术,如果登陆失效,登陆过滤器会将请求转发到登陆界面,无法得到结果,刷新浏览器可以让登陆过滤器执行自动登陆
127 | ### 6.前端数据不同步?
128 | ##### 请刷新浏览器,因为部分前端页面不完善,需要手动刷新页面
129 | ### 7.登陆新的用户之后还是之前的账户在登陆?
130 | ##### 在session失效之前系统都会记住一个客户端的登陆,如需登陆新账号要退出登陆,或者关闭浏览器
131 |
132 | ------
133 | ## 版权声明
134 |
135 | 本软件仅供交流学习,不得用于商业用途
136 |
137 |
138 |
--------------------------------------------------------------------------------
/lib/fastjson-1.2.58.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/fastjson-1.2.58.jar
--------------------------------------------------------------------------------
/lib/jsp-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/jsp-api.jar
--------------------------------------------------------------------------------
/lib/log4j-1.2.17.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/log4j-1.2.17.jar
--------------------------------------------------------------------------------
/lib/mysql-connector-java-8.0.15.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/mysql-connector-java-8.0.15.jar
--------------------------------------------------------------------------------
/lib/servlet-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/servlet-api.jar
--------------------------------------------------------------------------------
/lib/tomcat-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/tomcat-api.jar
--------------------------------------------------------------------------------
/lib/tomcat-juli.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/tomcat-juli.jar
--------------------------------------------------------------------------------
/lib/tomcat-util.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/tomcat-util.jar
--------------------------------------------------------------------------------
/lib/tomcat-websocket.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/tomcat-websocket.jar
--------------------------------------------------------------------------------
/lib/websocket-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misterchaos/weibo/c4f6f1d7f67ba1a266c8d63fa9964860210262af/lib/websocket-api.jar
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/annotation/ControllerConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 用于注解ActionProvider的url路径
24 | * @date 2019-05-02 11:28
25 | */
26 | @Documented
27 | @Retention(value = RetentionPolicy.RUNTIME)
28 | @Target(value = ElementType.TYPE)
29 | public @interface ControllerConfig {
30 | String path() default "";
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/constant/ControllerMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.constant;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 用于枚举控制层的系统消息
22 | * @date 2019-05-03 13:11
23 | */
24 | public enum ControllerMessage {
25 |
26 | /**
27 | * 游客身份
28 | */
29 | YOU_ARE_VISITOR("您现在处于游客身份,该服务并未对游客开放,如需使用请先注册一个账号"),
30 |
31 | /*
32 | **************************************************************
33 | * 系统错误码
34 | **************************************************************
35 | */
36 | /**
37 | * 系统故障
38 | */
39 | SYSTEM_EXECEPTION("服务器发生了严重异常,无法提供服务"),
40 | /**
41 | * 请求参数错误
42 | */
43 | REQUEST_INVALID("您的请求参数不足或错误,系统无法处理您的请求");
44 | public String message;
45 |
46 | ControllerMessage(String message) {
47 | this.message = message;
48 | }
49 |
50 | public String getMessage() {
51 | return message;
52 | }
53 |
54 | private void setMessage(String message) {
55 | this.message = message;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/impl/filter/EncodingFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.impl.filter;
18 |
19 | import com.hyc.www.controller.constant.ControllerMessage;
20 | import com.hyc.www.provider.constant.WebPage;
21 | import org.apache.log4j.Logger;
22 |
23 | import javax.servlet.*;
24 | import javax.servlet.annotation.WebFilter;
25 | import javax.servlet.annotation.WebInitParam;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | import java.io.IOException;
29 |
30 | /**
31 | * @author 黄钰朝
32 | * @program www
33 | * @description 负责设置编码格式
34 | * @date 2019-05-02 22:56
35 | */
36 |
37 | @WebFilter(
38 | filterName = "EncodingFilter",
39 | urlPatterns = {"/*"}, servletNames = {"/*"},
40 | initParams = {
41 | @WebInitParam(name = "ENCODING", value = "UTF-8")
42 | }
43 | )
44 | public class EncodingFilter implements Filter {
45 |
46 | private String ENCODING = null;
47 |
48 | @Override
49 | public void init(FilterConfig config) {
50 | this.ENCODING = config.getInitParameter("ENCODING");
51 | }
52 |
53 | @Override
54 | public void destroy() {
55 |
56 | }
57 |
58 | @Override
59 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {
60 | HttpServletRequest req = (HttpServletRequest) servletRequest;
61 | HttpServletResponse resp = (HttpServletResponse) servletResponse;
62 | try {
63 | req.setCharacterEncoding(ENCODING);
64 | resp.setCharacterEncoding(ENCODING);
65 | resp.addHeader("Access-Control-Allow-Origin", "*");
66 | resp.addHeader("Access-Control-Allow-Headers",
67 | "origin, content-type, accept, x-requested-with, sid, mycustom, smuser");
68 | resp.addHeader("Access-Control-Allow-Methods", "*");
69 | resp.addHeader("Access-Control-Max-Age", "100");
70 | resp.addHeader("Access-Control-Allow-Credentials", "false");
71 |
72 | filterChain.doFilter(servletRequest, servletResponse);
73 | } catch (IOException | ServletException e) {
74 | e.printStackTrace();
75 | try {
76 | req.setAttribute("message", ControllerMessage.SYSTEM_EXECEPTION.message);
77 | req.getRequestDispatcher(WebPage.ERROR_JSP.toString()).forward(req, resp);
78 | } catch (ServletException | IOException ex) {
79 | ex.printStackTrace();
80 | }
81 | }
82 | Logger logger = Logger.getLogger(EncodingFilter.class);
83 | logger.debug("[请求url] : " + req.getRequestURI() + " [请求参数] :" + req.getQueryString());
84 | }
85 | }
86 |
87 |
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/impl/filter/LoginFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.impl.filter;
18 |
19 | import com.hyc.www.controller.constant.ControllerMessage;
20 | import com.hyc.www.provider.constant.RequestMethod;
21 | import com.hyc.www.provider.constant.WebPage;
22 | import com.hyc.www.model.dto.ServiceResult;
23 | import com.hyc.www.model.po.User;
24 | import com.hyc.www.provider.UserProvider;
25 | import com.hyc.www.service.constants.Status;
26 | import com.hyc.www.service.impl.UserServiceImpl;
27 |
28 | import javax.servlet.*;
29 | import javax.servlet.annotation.WebFilter;
30 | import javax.servlet.annotation.WebInitParam;
31 | import javax.servlet.http.HttpServletRequest;
32 | import javax.servlet.http.HttpServletResponse;
33 | import javax.servlet.http.HttpSession;
34 | import java.io.IOException;
35 |
36 | import static com.hyc.www.util.ControllerUtils.returnJsonObject;
37 |
38 | /**
39 | * @author 黄钰朝
40 | * @description 负责过滤需要登陆的页面的请求
41 | * @date 2019-05-09 15:41
42 | */
43 | @WebFilter(
44 | filterName = "LoginFilter",
45 | urlPatterns = {"/*"}, servletNames = {"/*"},
46 | initParams = {
47 | @WebInitParam(name = "ENCODING", value = "UTF-8")
48 | })
49 | public class LoginFilter implements Filter {
50 |
51 | private final UserProvider userProvider = new UserProvider();
52 |
53 | @Override
54 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
55 | HttpServletRequest req = (HttpServletRequest) servletRequest;
56 | HttpServletResponse resp = (HttpServletResponse) servletResponse;
57 | String method = req.getParameter("method");
58 | String uri = req.getRequestURI();
59 | String contextPath = req.getContextPath();
60 | String path = uri.substring(contextPath.length());
61 | HttpSession sess = req.getSession(false);
62 |
63 | //尝试自动登陆
64 | userProvider.autoLogin(req);
65 | sess=req.getSession();
66 | //放行登陆注册
67 | if (sess == null || sess.getAttribute("login") == null) {
68 | if (WebPage.LOGIN_JSP.toString().equalsIgnoreCase(path) ||
69 | (WebPage.REGISTER_JSP.toString()).equalsIgnoreCase(path) ||
70 | (RequestMethod.LOGIN_DO.toString()).equalsIgnoreCase(method) ||
71 | (RequestMethod.REGISTER_DO.toString()).equalsIgnoreCase(method) ||
72 | path.endsWith("logo.png") || path.endsWith(".js") ||
73 | path.endsWith("agreement.html")||path.endsWith("css")) {
74 | filterChain.doFilter(req, resp);
75 | return;
76 | } else {
77 | //检查session是否有'login'属性,没有则重定向到登陆界面
78 | if (sess == null || sess.getAttribute("login") == null) {
79 | req.getRequestDispatcher(WebPage.LOGIN_JSP.toString()).forward(req, resp);
80 | return;
81 | }
82 | }
83 | }else {
84 | //已登陆用户检查登陆身份
85 | if (path.startsWith("/weibo/moment") || path.startsWith("/weibo/friend")) {
86 | //检查登陆身份
87 | User user = (User) sess.getAttribute("login");
88 | if (user != null && UserServiceImpl.VISITOR_EMAIL.equals(user.getEmail())) {
89 | //游客不可使用
90 | returnJsonObject(resp, new ServiceResult(Status.ERROR, ControllerMessage.YOU_ARE_VISITOR.message, null));
91 | return;
92 | }
93 | }
94 | }
95 |
96 | filterChain.doFilter(req, resp);
97 | }
98 |
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/impl/listener/ServletContextListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.impl.listener;
18 |
19 | import com.hyc.www.provider.*;
20 |
21 | import javax.servlet.ServletContext;
22 | import javax.servlet.ServletContextEvent;
23 | import javax.servlet.annotation.WebListener;
24 | import java.util.concurrent.ConcurrentHashMap;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @program www
29 | * @description 负责监听servlet的初始化和销毁事件
30 | * @date 2019-05-01 08:44
31 | */
32 |
33 | @WebListener
34 | public class ServletContextListener implements javax.servlet.ServletContextListener {
35 |
36 | private static final ConcurrentHashMap providerMap = new ConcurrentHashMap<>();
37 |
38 | @Override
39 | public void contextInitialized(ServletContextEvent sce) {
40 | /**
41 | * 用来装载provider的容器
42 | */
43 | //注册服务
44 | providerMap.put("userProvider", new UserProvider());
45 | providerMap.put("chatProvider", new ChatProvider());
46 | providerMap.put("uploadProvider", new UploadProvider());
47 | providerMap.put("friendProvider", new FriendProvider());
48 | providerMap.put("momentProvider",new TweetProvider());
49 | providerMap.put("messageProvider",new MessageProvider());
50 | providerMap.put("remarkProvider",new RemarkProvider());
51 | //将controllerMap注入ServletContext
52 | ServletContext sc = sce.getServletContext();
53 | sc.setAttribute("providerMap", providerMap);
54 | }
55 |
56 | @Override
57 | public void contextDestroyed(ServletContextEvent sce) {
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/hyc/www/controller/impl/servlet/MyServlet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.controller.impl.servlet;
18 |
19 | import com.hyc.www.controller.constant.ControllerMessage;
20 | import com.hyc.www.provider.BaseProvider;
21 | import org.apache.log4j.Logger;
22 |
23 | import javax.servlet.annotation.MultipartConfig;
24 | import javax.servlet.annotation.WebServlet;
25 | import javax.servlet.http.HttpServlet;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | import java.io.IOException;
29 | import java.util.Map;
30 | import java.util.Set;
31 |
32 | import static com.hyc.www.provider.BaseProvider.toErrorPage;
33 |
34 | /**
35 | * @author 黄钰朝
36 | * @program www
37 | * @description 接收客户端请求,将其转发到controller
38 | * @date 2019-05-02 03:28
39 | */
40 | //@MultipartConfig(location = "/home/pan/tomcat/webapps/weibo/upload")
41 | @MultipartConfig(location = "C:\\Users\\Misterchaos\\Documents\\Java Develop Workplaces\\IDEA workspace\\HYCWeiboSystem\\out\\artifacts\\HYCWeiboSystem_war_exploded\\upload")
42 | @WebServlet("/weibo/*")
43 | public class MyServlet extends HttpServlet {
44 |
45 | @Override
46 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
47 | this.doPost(req, resp);
48 | }
49 |
50 | /**
51 | * 负责将请求转发到url对应的Provider
52 | *
53 | * @param req 请求
54 | * @param resp 响应
55 | * @name doPost
56 | * @notice none
57 | * @author 黄钰朝
58 | * @date 2019/5/2
59 | */
60 | @Override
61 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
62 | MapproviderMap = (Map) getServletContext().getAttribute("providerMap");
63 | String url = req.getRequestURI();
64 | Set keys = providerMap.keySet();
65 | Logger logger = Logger.getLogger(MyServlet.class);
66 | logger.debug("[请求url:]"+url+"[匹配provider]:"+url.substring(12));
67 | boolean isMatch=false;
68 | for (String key : keys) {
69 | //解析注解中的path信息,匹配ActionProvider
70 | String path =providerMap.get(key).getPath();
71 | if (url.substring(12).equalsIgnoreCase(path)) {
72 | providerMap.get(key).doAction(req, resp);
73 | logger.debug("provider 分发完毕");
74 | isMatch=true;
75 | }
76 | }
77 | if(!isMatch){
78 | toErrorPage(ControllerMessage.REQUEST_INVALID.message,req,resp);
79 | logger.debug("该请求没有匹配provider :"+url.substring(14));
80 | return;
81 | }
82 | }
83 |
84 |
85 | }
86 |
87 |
88 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/BaseDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @program www
24 | * @description 提供Dao的基础方法接口
25 | * @date 2019-05-01 17:11
26 | */
27 | public interface BaseDao {
28 |
29 | String BASE_FIELD = "id,status,gmt_create,gmt_modified";
30 |
31 | /*
32 | **************************************************************
33 | * 负责数据库insert,update,delete等功能
34 | **************************************************************
35 | */
36 |
37 |
38 | /**
39 | * 把一个对象插入一张表
40 | *
41 | * @param obj 要插入的对象
42 | * @name insert
43 | * @notice none
44 | * @author 黄钰朝
45 | * @date 2019/5/1
46 | */
47 | @Insert()
48 | int insert(Object obj);
49 |
50 |
51 |
52 | /**
53 | * 根据传入的表名和id,从该表中更新一条记录
54 | *
55 | * @param obj 要更新的记录对应的实体类对象
56 | * @name update
57 | * @notice 请注意此方法默认更新该对象中所有不为null的属性到数据库
58 | * 如果不希望更新某些字段,请将其设置为null
59 | * @author 黄钰朝
60 | * @date 2019/5/1
61 | */
62 | @Update()
63 | int update(Object obj);
64 |
65 | /**
66 | * 将一个对象从表中删除
67 | *
68 | * @param obj 要删除的对象
69 | * @name delete
70 | * @notice none
71 | * @author 黄钰朝
72 | * @date 2019/5/1
73 | */
74 | @Delete()
75 | int delete(Object obj);
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/ChatDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.Chat;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @description 负责聊天表的CRUD
29 | * @date 2019-05-03 02:18
30 | */
31 | public interface ChatDao extends BaseDao {
32 |
33 | String TABLE = "chat";
34 | String ALL_FIELD = "number,owner_id,type,name,member,photo," + BASE_FIELD;
35 |
36 | /**
37 | * 通过聊天id查询一个聊天
38 | *
39 | * @param id 聊天id
40 | * @return 聊天对象
41 | * @name getChatById
42 | * @notice none
43 | * @author 黄钰朝
44 | * @date 2019/5/2
45 | */
46 | @Result(entity = Chat.class, returns = ResultType.OBJECT)
47 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
48 | Chat getChatById(Object id);
49 |
50 | /**
51 | * 通过用户id查询该用户所处的所有聊天
52 | *
53 | * @param userId 用户id
54 | * @return 该用户加入的聊天集合
55 | * @name listByUserId
56 | * @notice none
57 | * @author 黄钰朝
58 | * @date 2019/5/3
59 | */
60 | @Result(entity = Chat.class, returns = ResultType.LIST)
61 | @Query(value = "select c.id,c.number,c.owner_id,c.name,c.type,c.member,c.photo,c.status,c.gmt_create,c.gmt_modified " +
62 | "from " + TABLE + " as c,member as m where c.id = m.chat_id and m.user_id = ?")
63 | List listByUserId(Object userId);
64 |
65 |
66 | /**
67 | * 将对方的头像作为聊天头像,将对方的昵称作为聊天名称
68 | * 查询一个聊天信息
69 | *
70 | * @param chatId 聊天id
71 | * @param userId 用户id
72 | * @return
73 | * @name toFriendChat
74 | * @notice none
75 | * @author 黄钰朝
76 | * @date 2019/5/5
77 | */
78 | @Result(entity = Chat.class, returns = ResultType.OBJECT)
79 | @Query(value = "select c.id,c.number,c.owner_id,u.name as name,c.member,u.photo as photo,c.type,c.status,c.gmt_create,c.gmt_modified " +
80 | "from " + TABLE + " as c,member as m,user as u where c.id = ? and m.chat_id = c.id and u.id = m.user_id and u.id <> ?")
81 | Chat toFriendChat(Object chatId, Object userId);
82 |
83 |
84 | /**
85 | * 通过聊天编号查询一个聊天
86 | *
87 | * @param number 聊天编号
88 | * @return
89 | * @name getByChatNumber
90 | * @notice none
91 | * @author 黄钰朝
92 | * @date 2019/5/6
93 | */
94 | @Result(entity = Chat.class,returns = ResultType.OBJECT)
95 | @Query(value = "select "+ALL_FIELD+" from "+TABLE+" where number = ? ")
96 | Chat getByChatNumber(Object number);
97 | }
98 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/DataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.exception.DaoException;
20 |
21 | import java.sql.Connection;
22 |
23 | /**
24 | * @author 黄钰朝
25 | * @program www
26 | * @description 负责向Dao层提供数据库连接
27 | * @date 2019-05-01 16:33
28 | */
29 | public interface DataSource {
30 | /**
31 | * 负责从数据库连接池中获取数据库连接
32 | *
33 | * @return java.sql.Connection
34 | * @throws DaoException 如果数据库连接已经达到最大值时仍然调用此方法,则抛出此异常
35 | * @name getConnection
36 | * @notice 数据库连接的数量受到配置文件中最大值的限制
37 | * @author 黄钰朝
38 | * @date 2019/5/1
39 | */
40 | Connection getConnection() throws DaoException;
41 |
42 |
43 | /**
44 | * 用于将数据库连接放回连接池中
45 | *
46 | * @param conn 数据库连接
47 | * @name freeConnection
48 | * @author 黄钰朝
49 | * @date 2019/5/1
50 | */
51 | void freeConnection(Connection conn);
52 |
53 | /**
54 | * 关闭数据库连接
55 | *
56 | * @param conn 数据库连接
57 | * @return java.sql.Connection
58 | * @name createConnection
59 | * @author 黄钰朝
60 | * @date 2019/5/1
61 | */
62 | void destroyConnection(Connection conn);
63 |
64 |
65 | /**
66 | * 负责返回当前已经创建的连接数
67 | *
68 | * @return int 当前已经创建的连接数
69 | * @name getCurrentCount
70 | * @author 黄钰朝
71 | * @date 2019/5/1
72 | */
73 | int getCurrentCount();
74 |
75 | /**
76 | * 负责返回当前池中剩余的空闲连接数
77 | *
78 | * @return int 当前空闲连接数
79 | * @name getfreeCount
80 | * @author 黄钰朝
81 | * @date 2019/5/1
82 | */
83 | int getfreeCount();
84 | }
85 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/FriendDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.Friend;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @program www
29 | * @description 负责朋友表CRUD
30 | * @date 2019-05-02 01:59
31 | */
32 | public interface FriendDao extends BaseDao {
33 |
34 | String ALL_FIELD = "user_id,friend_id,chat_id,group_id,photo,alias,description," + BASE_FIELD;
35 | String TABLE = "friend";
36 |
37 | /**
38 | * 通过用户id和朋友id获取一条好友记录
39 | *
40 | * @param userId 用户id
41 | * @param friendId 朋友id
42 | * @return
43 | * @name getFriendByUIDAndFriendId
44 | * @notice none
45 | * @author 黄钰朝
46 | * @date 2019/5/6
47 | */
48 | @Result(entity = Friend.class, returns = ResultType.OBJECT)
49 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where user_id = ? and friend_id = ? ")
50 | Friend getFriendByUIDAndFriendId(Object userId, Object friendId);
51 |
52 |
53 | /**
54 | * 通过用户id查询好友列表
55 | *
56 | * @param userId 用户id
57 | * @return
58 | * @name listByUserId
59 | * @notice none
60 | * @author 黄钰朝
61 | * @date 2019/5/6
62 | */
63 | @Result(entity = Friend.class, returns = ResultType.LIST)
64 | @Query(value = "select f.id,f.user_id,f.friend_id,f.chat_id,f.group_id,f.alias,f.description,u.photo as photo,f.status,f.gmt_create,f.gmt_modified " +
65 | "from " + TABLE + " as f,user as u where f.user_id = ? and u.id = f.friend_id ")
66 | List listByUserId(Object userId);
67 |
68 | /**
69 | * 通过用户id查询粉丝
70 | *
71 | * @param userId 用户id
72 | * @return
73 | * @name listFansByUserId
74 | * @notice none
75 | * @author 黄钰朝
76 | * @date 2019/5/6
77 | */
78 | @Result(entity = Friend.class, returns = ResultType.LIST)
79 | @Query(value = "select f.id,f.user_id,f.friend_id,f.chat_id,f.group_id,f.alias,f.description,u.photo as photo,f.status,f.gmt_create,f.gmt_modified " +
80 | "from " + TABLE + " as f,user as u where f.friend_id = ? and u.id = f.user_id ")
81 | List listFansByUserId(Object userId);
82 |
83 | /**
84 | * 通过朋友关系id查询一个朋友关系
85 | *
86 | * @param id 朋友id
87 | * @name getFriendById
88 | * @notice none
89 | * @author 黄钰朝
90 | * @date 2019/5/7
91 | */
92 | @Result(entity = Friend.class, returns = ResultType.OBJECT)
93 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
94 | Friend getFriendById(Object id);
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/MemberDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.Member;
23 |
24 | import java.math.BigInteger;
25 | import java.util.List;
26 |
27 | /**
28 | * @author 黄钰朝
29 | * @description 用于user_chat表的CRUD
30 | * @date 2019-05-03 13:05
31 | */
32 | public interface MemberDao extends BaseDao {
33 | String TABLE = "member";
34 | String ALL_FIELD = "user_id,chat_id,group_alias,apply,background,level," + BASE_FIELD;
35 |
36 | /**
37 | * 通过成员id查询一个成员
38 | *
39 | * @param id 成员id
40 | * @return 成员对象
41 | * @name getMemberById
42 | * @notice none
43 | * @author 黄钰朝
44 | * @date 2019/5/2
45 | */
46 | @Result(entity = Member.class, returns = ResultType.OBJECT)
47 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
48 | Member getMemberById(Object id);
49 |
50 | /**
51 | * 通过用户id和聊天id查询一个成员
52 | *
53 | * @param userId 用户id
54 | * @param chatId 聊天id
55 | * @return 成员对象
56 | * @name getMemberByUIdAndChatId
57 | * @notice none
58 | * @author 黄钰朝
59 | * @date 2019/5/2
60 | */
61 | @Result(entity = Member.class, returns = ResultType.OBJECT)
62 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where user_id = ? and chat_id = ? ")
63 | Member getMemberByUIdAndChatId(BigInteger userId, BigInteger chatId);
64 |
65 |
66 | /**
67 | * 返回一个聊天中的所有成员
68 | * @name listMemberByChatId
69 | * @param chatId 聊天id
70 | * @return
71 | * @notice none
72 | * @author 黄钰朝
73 | * @date 2019/5/5
74 | */
75 | @Result(entity = Member.class, returns = ResultType.LIST)
76 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where chat_id = ? ")
77 | List listMemberByChatId(Object chatId);
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/NewsDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.News;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @description 负责动态表的CRUD
29 | * @date 2019-05-07 18:47
30 | */
31 | public interface NewsDao extends BaseDao {
32 | String TABLE = "news";
33 | String ALL_FIELD = "user_id,tweet_id,loved,shared,viewed,collected," + BASE_FIELD;
34 |
35 | /**
36 | * 通过用户id查询所有自己可见的所有微博动态
37 | *
38 | * @param userId 用户id
39 | * @param limit 每页查询记录数
40 | * @param offset 起始记录数
41 | * @name listNewsByUserId
42 | * @notice none
43 | * @author 黄钰朝
44 | * @date 2019/5/7
45 | */
46 | @Result(entity = News.class, returns = ResultType.LIST)
47 | @Query("select " + ALL_FIELD + " from " + TABLE + " where user_id = ? order by gmt_create desc limit ? offset ? ")
48 | List listNewsByUserId(Object userId, int limit, int offset);
49 |
50 |
51 | /**
52 | * 通过微博id和用户id查询一个微博动态
53 | *
54 | * @param tweetId 微博id
55 | * @param userId 用户id
56 | * @name getNewsByTweetId
57 | * @notice none
58 | * @author 黄钰朝
59 | * @date 2019/5/7
60 | */
61 | @Result(entity = News.class, returns = ResultType.OBJECT)
62 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where tweet_id = ? and user_id = ? ")
63 | News getNewsByTweetIdAndUserId(Object tweetId,Object userId);
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/RecordDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Update;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 负责消息记录CRUD
24 | * @date 2019-05-06 21:41
25 | */
26 | public interface RecordDao extends BaseDao {
27 | String TABLE = "record";
28 | String ALL_FIELD = "user_id,message_id," + BASE_FIELD;
29 |
30 |
31 | /**
32 | * 一次性更新一个用户在一个聊天中所有记录的状态
33 | *
34 | * @param status 记录状态
35 | * @param userId 用户id
36 | * @param chatId 聊天id
37 | * @name updateStatusInChat
38 | * @notice none
39 | * @author 黄钰朝
40 | * @date 2019/5/7
41 | */
42 | @Update("update " + TABLE + " as r inner join message as m set r.status = ? where r.user_id = ? and r.message_id = m.id and m.chat_id = ?")
43 | void updateStatusInChat(Object status, Object userId ,Object chatId);
44 |
45 |
46 | /**
47 | * 一次性删除一个用户在一个聊天中所有记录的状态
48 | *
49 | * @param userId 用户id
50 | * @param chatId 聊天id
51 | * @name deleteAllRecordInChat
52 | * @notice none
53 | * @author 黄钰朝
54 | * @date 2019/5/10
55 | */
56 | @Update("delete r from " + TABLE + " r inner join message m on r.message_id = m.id where r.user_id = ? and m.chat_id = ? " )
57 | void deleteAllRecordInChat(Object userId , Object chatId);
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/RemarkDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.Remark;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @description
29 | * @date 2019-05-14 01:12
30 | */
31 | public interface RemarkDao extends BaseDao{
32 | String TABLE = "remark";
33 | String ALL_FIELD = "user_id,tweet_id,content,time,love,collect,reply," + BASE_FIELD;
34 |
35 | /**
36 | * 通过用户id逆序查询一条微博下面的评论
37 | *
38 | * @param tweetId 微博id
39 | * @param limit 每页查询记录数
40 | * @param offset 起始记录数
41 | * @name listRemarkDesc
42 | * @notice none
43 | * @author 黄钰朝
44 | * @date 2019/5/14
45 | */
46 | @Result(entity = Remark.class, returns = ResultType.LIST)
47 | @Query("select " + ALL_FIELD + " from " + TABLE + " where tweet_id = ? order by time limit ? offset ? ")
48 | List listRemarkDesc(Object tweetId, int limit, int offset);
49 |
50 | /**
51 | * 通过评论id查询一个评论
52 | *
53 | * @param id 评论id
54 | * @name geRemarkById
55 | * @notice none
56 | * @author 黄钰朝
57 | * @date 2019/5/14
58 | */
59 | @Result(entity = Remark.class, returns = ResultType.OBJECT)
60 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
61 | Remark getRemarkById(Object id);
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/ReplyDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description
22 | * @date 2019-05-14 01:12
23 | */
24 | public interface ReplyDao extends BaseDao {
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/ResultMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 |
20 | import java.sql.ResultSet;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @program XHotel
25 | * @description 用于处理执行查询语句之后返回的结果集,将结果集映射为对象
26 | * @date 2019-04-09 15:06
27 | */
28 | public interface ResultMapper {
29 | /**
30 | * 负责提供一个映射数据库查询结果集的方法
31 | * @name doMap
32 | * @param rs 需要映射的结果集
33 | * @return java.lang.Object
34 | * @notice none
35 | * @author 黄钰朝
36 | * @date 2019/4/10
37 | */
38 | Object doMap(ResultSet rs);
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/SQLMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @program XHotel
22 | * @description 用于将属性映射成sql预编译语句
23 | * @date 2019-04-11 17:55
24 | */
25 | public interface SQLMapper {
26 |
27 |
28 | /**
29 | * 用于将一个或多个参数映射成预编译sql语句
30 | *
31 | * @param params 可变参数,允许传递多个映射sql语句所需的源数据
32 | * @return 返回映射之后的预编译sql语句
33 | * @name doMap
34 | * @notice none
35 | * @author 黄钰朝
36 | * @date 2019/4/12
37 | */
38 | String doMap(Object... params);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/TweetDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.Tweet;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @description 负责微博的CRUD
29 | * @date 2019-05-07 11:55
30 | */
31 | public interface TweetDao extends BaseDao {
32 | String TABLE = "tweet";
33 | String ALL_FIELD = "owner_id,content,origin_id,sort,time,love,remark,share,view," + BASE_FIELD;
34 |
35 | /**
36 | * 通过微博id查询一个微博
37 | *
38 | * @param id 微博id
39 | * @name geTweetById
40 | * @notice none
41 | * @author 黄钰朝
42 | * @date 2019/5/2
43 | */
44 | @Result(entity = Tweet.class, returns = ResultType.OBJECT)
45 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
46 | Tweet getTweetById(Object id);
47 |
48 | /**
49 | * 通过用户id和状态查询一个微博
50 | *
51 | * @param ownerId 用户id
52 | * @param stauts 状态
53 | * @notice none
54 | * @author 黄钰朝
55 | * @date 2019/5/8
56 | */
57 | @Result(entity = Tweet.class, returns = ResultType.OBJECT)
58 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? and status = ? ")
59 | Tweet getTweetByOwnerIdAndStatus(Object ownerId, Object stauts);
60 |
61 |
62 | /**
63 | * 通过用户id逆序查询所有自己发布的微博
64 | *
65 | * @param ownerId 用户id
66 | * @param limit 每页查询记录数
67 | * @param offset 起始记录数
68 | * @name listMyTweetByOwnerIdDesc
69 | * @notice none
70 | * @author 黄钰朝
71 | * @date 2019/5/7
72 | */
73 | @Result(entity = Tweet.class, returns = ResultType.LIST)
74 | @Query("select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? order by time desc limit ? offset ? ")
75 | List listMyTweetByOwnerIdDesc(Object ownerId, int limit, int offset);
76 |
77 |
78 |
79 |
80 |
81 | /**
82 | * 通过用户id查询所有自己发布的微博
83 | *
84 | * @param ownerId 用户id
85 | * @param limit 每页查询记录数
86 | * @param offset 起始记录数
87 | * @name listMyTweetByOwnerId
88 | * @notice none
89 | * @author 黄钰朝
90 | * @date 2019/5/7
91 | */
92 | @Result(entity = Tweet.class, returns = ResultType.LIST)
93 | @Query("select " + ALL_FIELD + " from " + TABLE + " where owner_id = ? order by time limit ? offset ? ")
94 | List listMyTweetByOwnerId(Object ownerId, int limit, int offset);
95 |
96 |
97 |
98 | /**
99 | * 通过分类逆序查询某个分类的微博
100 | *
101 | * @param sort 分类
102 | * @param limit 每页查询记录数
103 | * @param offset 起始记录数
104 | * @name listTweetBySortDesc
105 | * @notice none
106 | * @author 黄钰朝
107 | * @date 2019/5/7
108 | */
109 | @Result(entity = Tweet.class, returns = ResultType.LIST)
110 | @Query("select " + ALL_FIELD + " from " + TABLE + " where sort = ? order by time desc limit ? offset ? ")
111 | List listTweetBySortDesc(Object sort, int limit, int offset);
112 |
113 |
114 | /**
115 | * 查询全部微博
116 | *
117 | * @param limit 每页查询记录数
118 | * @param offset 起始记录数
119 | * @name listTweetDesc
120 | * @notice none
121 | * @author 黄钰朝
122 | * @date 2019/5/7
123 | */
124 | @Result(entity = Tweet.class, returns = ResultType.LIST)
125 | @Query("select " + ALL_FIELD + " from " + TABLE + " order by time desc limit ? offset ? ")
126 | List listTweetDesc(int limit, int offset);
127 |
128 | /**
129 | * 通过用户id查询所有自己发布的微博中的图片
130 | *
131 | * @param ownerId 用户id
132 | * @param limit 每页查询记录数
133 | * @param offset 起始记录数
134 | * @name loadPhoto
135 | * @notice none
136 | * @author 黄钰朝
137 | * @date 2019/5/10
138 | */
139 | @Result(entity = Tweet.class, returns = ResultType.LIST)
140 | @Query("select photo from " + TABLE + " where owner_id = ? order by time desc limit ? offset ? ")
141 | List listPhoto(Object ownerId, int limit, int offset);
142 | }
143 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao;
18 |
19 | import com.hyc.www.dao.annotation.Query;
20 | import com.hyc.www.dao.annotation.Result;
21 | import com.hyc.www.dao.annotation.ResultType;
22 | import com.hyc.www.model.po.User;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @program www
29 | * @description 负责User类CRUD
30 | * @date 2019-05-01 23:39
31 | */
32 | public interface UserDao extends BaseDao {
33 | String TABLE = "user";
34 | String ALL_FIELD = "email,weibo_id,phone,password,gender,signature,name,photo"
35 | + ",chat_background,location,online_status,type," + BASE_FIELD;
36 |
37 |
38 | /**
39 | * 通过id查询一个用户
40 | *
41 | * @param id
42 | * @return 用户对象
43 | * @name getUserById
44 | * @notice none
45 | * @author 黄钰朝
46 | * @date 2019/5/2
47 | */
48 | @Result(entity = User.class, returns = ResultType.OBJECT)
49 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where id = ? ")
50 | User getUserById(Object id);
51 |
52 |
53 | /**
54 | * 通过邮箱查询一个用户
55 | *
56 | * @param email 账户邮箱
57 | * @return 用户对象
58 | * @name getUserByEmail
59 | * @notice none
60 | * @author 黄钰朝
61 | * @date 2019/5/2
62 | */
63 | @Result(entity = User.class, returns = ResultType.OBJECT)
64 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where email = ? ")
65 | User getUserByEmail(String email);
66 |
67 |
68 | /**
69 | * 通过用户名查询一个用户
70 | *
71 | * @param weiboId 微信号
72 | * @return 用户对象
73 | * @name getUserByWeiboId
74 | * @notice none
75 | * @author 黄钰朝
76 | * @date 2019/5/2
77 | */
78 | @Result(entity = User.class, returns = ResultType.OBJECT)
79 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where weibo_id = ? ")
80 | User getUserByWeiboId(String weiboId);
81 |
82 | /**
83 | * @param name 用户昵称
84 | * @return
85 | * @name listByName
86 | * @notice none
87 | * @author 黄钰朝
88 | * @date 2019/5/5
89 | */
90 | @Result(entity = User.class, returns = ResultType.LIST)
91 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where name = ?")
92 | List listByName(String name);
93 |
94 |
95 | /**
96 | * 通过关键词模糊查询用户昵称相近的用户
97 | *
98 | * @param keyWord 关键词
99 | * @return
100 | * @name listLike
101 | * @notice 注意本方法本身不带有模糊查询功能,必须在传入参数中带有模糊条件
102 | * @author 黄钰朝
103 | * @date 2019/5/6
104 | */
105 | @Result(entity = User.class, returns = ResultType.LIST)
106 | @Query(value = "select " + ALL_FIELD + " from " + TABLE + " where name like ? ")
107 | List listLikeName(String keyWord);
108 |
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Delete.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @program www
24 | * @description 用于注解删除语句
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.METHOD)
30 | public @interface Delete {
31 | String value()default "";
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Field.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 用于注解SQL语句的返回结果类型
24 | * @program www
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.FIELD)
30 | public @interface Field {
31 | String name ();
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Insert.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @program www
24 | * @description 用于注解插入语句
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.METHOD)
30 | public @interface Insert {
31 | String value()default "";
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Param.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 用于注解SQL语句的返回结果类型
24 | * @program www
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.PARAMETER)
30 | public @interface Param {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @program www
24 | * @description 用于注解查询语句
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.METHOD)
30 | public @interface Query {
31 | String value()default "";
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Result.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import com.hyc.www.model.po.abs.BaseEntity;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * @author 黄钰朝
25 | * @description 用于注解SQL语句的返回结果类型
26 | * @program www
27 | * @date 2019-05-01 13:32
28 | */
29 | @Documented
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Target(ElementType.METHOD)
32 | public @interface Result {
33 | Class extends BaseEntity> entity();
34 | ResultType returns ()default ResultType.OBJECT;
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/ResultType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @program www
22 | * @description 用于枚举SQL语句返回值类型
23 | * @date 2019-05-01 21:21
24 | */
25 | public enum ResultType{
26 | /**
27 | * 返回值为对象类型
28 | */
29 | OBJECT,
30 | /**
31 | * 返回值为链表类型
32 | */
33 | LIST,
34 | /**
35 | * 返回值为值类型
36 | */
37 | VALUE;
38 | }
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Table.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @program www
25 | * @description 用于注解表名
26 | * @date 2019-05-01 00:19
27 | */
28 | @Documented
29 | @Retention(value = RetentionPolicy.RUNTIME)
30 | @Target(value = ElementType.TYPE)
31 | public @interface Table {
32 | String name() ;
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/hyc/www/dao/annotation/Update.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.dao.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 用于注解更新语句
24 | * @program www
25 | * @date 2019-05-01 13:32
26 | */
27 | @Documented
28 | @Retention(RetentionPolicy.RUNTIME)
29 | @Target(ElementType.METHOD)
30 | public @interface Update {
31 | String value()default "";
32 | }
33 |
--------------------------------------------------------------------------------
/src/com/hyc/www/exception/DaoException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.exception;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 用于包装Dao层的异常
22 | * @date 2019-05-01 16:36
23 | */
24 | public class DaoException extends RuntimeException{
25 | public DaoException() {
26 | super();
27 | }
28 |
29 | public DaoException(String message) {
30 | super(message);
31 | }
32 |
33 | public DaoException(String message, Throwable cause) {
34 | super(message, cause);
35 | }
36 |
37 | public DaoException(Throwable cause) {
38 | super(cause);
39 | }
40 |
41 | protected DaoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
42 | super(message, cause, enableSuppression, writableStackTrace);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/hyc/www/exception/ServiceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.exception;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description service层异常类
22 | * @date 2019-05-01 17:41
23 | */
24 | public class ServiceException extends RuntimeException{
25 | public ServiceException() {
26 | super();
27 | }
28 |
29 | public ServiceException(String message) {
30 | super(message);
31 | }
32 |
33 | public ServiceException(String message, Throwable cause) {
34 | super(message, cause);
35 | }
36 |
37 | public ServiceException(Throwable cause) {
38 | super(cause);
39 | }
40 |
41 | protected ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
42 | super(message, cause, enableSuppression, writableStackTrace);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/hyc/www/factory/DaoProxyFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.factory;
18 |
19 | import com.hyc.www.dao.SQLRunner;
20 | import com.hyc.www.dao.annotation.*;
21 | import com.hyc.www.dao.impl.SQLRunnerImpl;
22 |
23 | import java.lang.reflect.InvocationHandler;
24 | import java.lang.reflect.Method;
25 | import java.lang.reflect.Proxy;
26 |
27 | /**
28 | * @author 黄钰朝
29 | * @description 用于解析Dao接口中的sql语句,并执行
30 | * @date 2019-05-01 11:01
31 | */
32 | public class DaoProxyFactory implements InvocationHandler {
33 |
34 | private static SQLRunner executor = new SQLRunnerImpl();
35 | private static DaoProxyFactory instance= new DaoProxyFactory();
36 |
37 | public Object getProxyInstance(Class interfaces) {
38 | return Proxy.newProxyInstance(interfaces.getClassLoader(), new Class[]{interfaces}, this);
39 | }
40 |
41 | private DaoProxyFactory() {
42 |
43 | }
44 |
45 | public static DaoProxyFactory getInstance(){
46 | return instance;
47 | }
48 |
49 | @Override
50 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
51 | if (method.getAnnotation(Insert.class) != null) {
52 | //默认没有sql语句,使用直接插入对象的方法
53 | if ("".equalsIgnoreCase(method.getAnnotation(Insert.class).value())) {
54 | Object obj = args[0];
55 | return executor.insert(obj, obj.getClass().getAnnotation(Table.class).name());
56 | } else {
57 | return executor.executeUpdate(method.getDeclaredAnnotation(Insert.class).value(), args);
58 | }
59 | }
60 | if (method.getAnnotation(Update.class) != null) {
61 | //默认没有sql语句,使用直接更新对象的方法
62 | if ("".equalsIgnoreCase(method.getAnnotation(Update.class).value())) {
63 | Object obj = args[0];
64 | return executor.update(obj, obj.getClass().getAnnotation(Table.class).name());
65 | } else {
66 | return executor.executeUpdate(method.getDeclaredAnnotation(Update.class).value(), args);
67 | }
68 | }
69 | if (method.getAnnotation(Delete.class) != null) {
70 | //默认没有sql语句,使用直接删除对象的方法
71 | if ("".equalsIgnoreCase(method.getAnnotation(Delete.class).value())) {
72 | Object obj = args[0];
73 | return executor.delete(obj, obj.getClass().getAnnotation(Table.class).name());
74 | } else {
75 | return executor.executeUpdate(method.getDeclaredAnnotation(Delete.class).value(), args);
76 | }
77 | }
78 | if (method.getAnnotation(Query.class) != null) {
79 | ResultType type = method.getAnnotation(Result.class).returns();
80 | switch (type) {
81 | case OBJECT:
82 | return executor.queryObject(method.getAnnotation(Query.class).value(), args, method.getAnnotation(Result.class).entity());
83 | case LIST:
84 | return executor.queryList(method.getAnnotation(Query.class).value(), args, method.getAnnotation(Result.class).entity());
85 | case VALUE:
86 | return executor.queryValue(method.getAnnotation(Query.class).value(), args);
87 | default:
88 | }
89 | }
90 | return method.invoke(proxy, args);
91 | }
92 |
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/com/hyc/www/factory/ServiceProxyFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.factory;
18 |
19 | import com.hyc.www.dao.UserDao;
20 | import com.hyc.www.model.dto.ServiceResult;
21 | import com.hyc.www.model.po.User;
22 | import com.hyc.www.service.annotation.Admin;
23 | import com.hyc.www.service.annotation.Freeze;
24 | import com.hyc.www.service.constants.ServiceMessage;
25 | import com.hyc.www.service.constants.Status;
26 | import com.hyc.www.service.constants.UserType;
27 | import org.apache.log4j.Logger;
28 |
29 | import java.lang.annotation.Annotation;
30 | import java.lang.reflect.InvocationHandler;
31 | import java.lang.reflect.Method;
32 | import java.lang.reflect.Proxy;
33 |
34 |
35 | /**
36 | * @author 黄钰朝
37 | * @description 生产服务代理
38 | * @date 2019-05-01 11:01
39 | */
40 | public class ServiceProxyFactory implements InvocationHandler {
41 |
42 | private Object target;
43 |
44 | private final UserDao userDao = (UserDao) DaoProxyFactory.getInstance().getProxyInstance(UserDao.class);
45 |
46 | public Object getProxyInstance(Object target) {
47 | this.target =target;
48 | return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
49 | }
50 |
51 |
52 | @Override
53 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
54 | Annotation freeze = method.getAnnotation(Freeze.class);
55 | if(freeze!=null){
56 | //获取用户
57 | User user = userDao.getUserById(args[0]);
58 | if(user.getStatus()==1){
59 | return new ServiceResult(Status.ERROR, ServiceMessage.HAVE_BEEN_FROST.message,null);
60 | }
61 | }
62 | Annotation admin = method.getAnnotation(Admin.class);
63 | if(admin!=null){
64 | //获取用户
65 | User user = userDao.getUserById(args[0]);
66 | if(!user.getType().equalsIgnoreCase(UserType.ADMIN.toString())){
67 | return new ServiceResult(Status.ERROR, ServiceMessage.NOT_ADMIN.message,null);
68 | }
69 | //打印日志
70 | Logger logger = Logger.getLogger(method.getClass());
71 | logger.info("管理员["+user.getName()+"][id:"+user.getId()+"]进行了["+method.getName()+"]操作");
72 | }
73 | return method.invoke(target, args);
74 | }
75 |
76 | public Object getTarget() {
77 | return target;
78 | }
79 |
80 | public void setTarget(Object target) {
81 | this.target = target;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/com/hyc/www/factory/proxy/ConnectionProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.factory.proxy;
18 |
19 | import com.hyc.www.dao.DataSource;
20 | import com.hyc.www.exception.DaoException;
21 |
22 | import java.lang.reflect.InvocationHandler;
23 | import java.lang.reflect.InvocationTargetException;
24 | import java.lang.reflect.Method;
25 | import java.lang.reflect.Proxy;
26 | import java.sql.Connection;
27 |
28 | /**
29 | * @author 黄钰朝
30 | * @description 用于代理数据库连接对象
31 | * @date 2019-05-01 17:52
32 | */
33 | public class ConnectionProxy implements InvocationHandler {
34 |
35 | private Connection target;
36 | private DataSource dataSource;
37 |
38 | public Connection getProxyInstance(Connection target){
39 | this.target= target;
40 | return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),new Class[]{Connection.class},this);
41 | }
42 |
43 | public ConnectionProxy(DataSource dataSource) {
44 | this.dataSource = dataSource;
45 | }
46 |
47 | @Override
48 | public Object invoke(Object proxy, Method method, Object[] args) {
49 | if ("close".equals(method.getName())) {
50 | //调用代理对象的close方法时,将目标对象放回数据库连接池
51 | dataSource.freeConnection(target);
52 | return null;
53 | }
54 | try {
55 | return method.invoke(target, args);
56 | } catch (IllegalAccessException | InvocationTargetException e) {
57 | throw new DaoException("无法调用目标对象的方法", e);
58 | }
59 | }
60 |
61 | public Connection getTarget() {
62 | return target;
63 | }
64 |
65 | public void setTarget(Connection target) {
66 | this.target = target;
67 | }
68 |
69 | public DataSource getDataSource() {
70 | return dataSource;
71 | }
72 |
73 | public void setDataSource(DataSource dataSource) {
74 | this.dataSource = dataSource;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/builder/MessageVOBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.builder;
18 |
19 | import com.hyc.www.model.vo.MessageVO;
20 |
21 | import java.math.BigInteger;
22 | import java.sql.Timestamp;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @description 负责MessageVO的建造
27 | * @date 2019-05-07 14:58
28 | */
29 | public class MessageVOBuilder {
30 | private MessageVO messageVo;
31 |
32 | public MessageVOBuilder() {
33 | this.messageVo = new MessageVO();
34 | }
35 |
36 | public MessageVO build(){
37 | return this.messageVo;
38 | }
39 |
40 | public MessageVOBuilder setSenderName(String senderName) {
41 | this.messageVo.setSenderName(senderName);
42 | return this;
43 | }
44 | public MessageVOBuilder setSenderId(BigInteger senderId){
45 | this.messageVo.setSenderId(senderId);
46 | return this;
47 | }
48 | public MessageVOBuilder setSenderPhoto(String senderPhoto){
49 | this.messageVo.setSenderPhoto(senderPhoto);
50 | return this;
51 | }
52 | public MessageVOBuilder setChatId(BigInteger chatId){
53 | this.messageVo.setChatId(chatId);
54 | return this;
55 | }
56 | public MessageVOBuilder setContent(String content){
57 | this.messageVo.setContent(content);
58 | return this;
59 | }
60 | public MessageVOBuilder setTime(Timestamp time){
61 | this.messageVo.setTime(time);
62 | return this;
63 | }
64 | public MessageVOBuilder setType(String type){
65 | this.messageVo.setType(type);
66 | return this;
67 | }
68 | public MessageVOBuilder setId(BigInteger id){
69 | this.messageVo.setId(id);
70 | return this;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/builder/TweetVOBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.builder;
18 |
19 | import com.hyc.www.model.vo.TweetVO;
20 |
21 | import java.math.BigInteger;
22 | import java.sql.Timestamp;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @description 负责朋友圈视图层对象的建造
27 | * @date 2019-05-07 20:32
28 | */
29 | public class TweetVOBuilder {
30 | private TweetVO tweetVO;
31 |
32 | public TweetVOBuilder() {
33 | this.tweetVO = new TweetVO();
34 | }
35 |
36 | public TweetVO build() {
37 | return this.tweetVO;
38 | }
39 |
40 |
41 | public TweetVOBuilder setTime(Timestamp time){
42 | this.tweetVO.setTime(time);
43 | return this;
44 | }
45 |
46 | public TweetVOBuilder setUserPhoto(String userPhoto){
47 | this.tweetVO.setUserPhoto(userPhoto);
48 | return this;
49 | }
50 |
51 |
52 |
53 | public TweetVOBuilder setUserName(String userName){
54 | this.tweetVO.setUserName(userName);
55 | return this;
56 | }
57 |
58 | public TweetVOBuilder setId(BigInteger id) {
59 | this.tweetVO.setId(id);
60 | return this;
61 | }
62 |
63 | public TweetVOBuilder setUserId(BigInteger userId) {
64 | this.tweetVO.setOwnerId(userId);
65 | return this;
66 | }
67 |
68 | public TweetVOBuilder setContent(String content) {
69 | this.tweetVO.setContent(content);
70 | return this;
71 | }
72 |
73 | public TweetVOBuilder setShare(Long share) {
74 | this.tweetVO.setShare(share);
75 | return this;
76 | }
77 |
78 | public TweetVOBuilder setLove(Long love) {
79 | this.tweetVO.setLove(love);
80 | return this;
81 | }
82 | public TweetVOBuilder setRemark(Long remark) {
83 | this.tweetVO.setRemark(remark);
84 | return this;
85 | }
86 |
87 | public TweetVOBuilder setView(Long view) {
88 | this.tweetVO.setView(view);
89 | return this;
90 | }
91 |
92 | public TweetVOBuilder setSort(String sort){
93 | this.tweetVO.setSort(sort);
94 | return this;
95 | }
96 |
97 |
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/dto/ServiceResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.dto;
18 |
19 | import com.hyc.www.service.constants.Status;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @program www
24 | * @description 用于service层返回处理结果
25 | * @date 2019-05-02 03:01
26 | */
27 | public class ServiceResult {
28 | /**
29 | * 状态码
30 | */
31 | private Status status;
32 | /**
33 | * 响应消息
34 | */
35 | private String message;
36 | /**
37 | * 响应数据
38 | */
39 | private Object data;
40 |
41 | public ServiceResult() {
42 | }
43 |
44 | public ServiceResult(Status status, String message, Object data) {
45 | this.status = status;
46 | this.message = message;
47 | this.data = data;
48 | }
49 |
50 | public Status getStatus() {
51 | return status;
52 | }
53 |
54 | public void setStatus(Status status) {
55 | this.status = status;
56 | }
57 |
58 | public String getMessage() {
59 | return message;
60 | }
61 |
62 | public void setMessage(String message) {
63 | this.message = message;
64 | }
65 |
66 | public Object getData() {
67 | return data;
68 | }
69 |
70 | public void setData(Object data) {
71 | this.data = data;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Chat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 对应数据库chat表
28 | * @date 2019-05-03 01:38
29 | */
30 | @Table(name = "chat")
31 | public class Chat extends BaseEntity {
32 | private String number;
33 | @JSONField(name = "owner_id")
34 | private BigInteger ownerId;
35 | private String type;
36 | private String name;
37 | private Integer member;
38 | private String photo;
39 |
40 | public String getType() {
41 | return type;
42 | }
43 |
44 | public void setType(String type) {
45 | this.type = type;
46 | }
47 |
48 | public String getNumber() {
49 | return number;
50 | }
51 |
52 | public void setNumber(String number) {
53 | this.number = number;
54 | }
55 |
56 | public String getPhoto() {
57 | return photo;
58 | }
59 |
60 | public void setPhoto(String photo) {
61 | this.photo = photo;
62 | }
63 |
64 | public BigInteger getOwnerId() {
65 | return ownerId;
66 | }
67 |
68 | public void setOwnerId(BigInteger ownerId) {
69 | this.ownerId = ownerId;
70 | }
71 |
72 | public String getName() {
73 | return name;
74 | }
75 |
76 | public void setName(String name) {
77 | this.name = name;
78 | }
79 |
80 | public Integer getMember() {
81 | return member;
82 | }
83 |
84 | public void setMember(Integer member) {
85 | this.member = member;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Friend.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @program www
28 | * @description 朋友表
29 | * @date 2019-05-02 01:56
30 | */
31 | @Table(name = "friend")
32 | public class Friend extends BaseEntity {
33 | @JSONField(name = "user_id")
34 | private BigInteger userId;
35 | @JSONField(name = "friend_id")
36 | private BigInteger friendId;
37 | @JSONField(name = "chat_id")
38 | private BigInteger chatId;
39 | private String photo;
40 | @JSONField(name = "group_id")
41 | private BigInteger groupId;
42 | private String alias;
43 | private String description;
44 |
45 | public BigInteger getChatId() {
46 | return chatId;
47 | }
48 |
49 | public void setChatId(BigInteger chatId) {
50 | this.chatId = chatId;
51 | }
52 |
53 | public String getPhoto() {
54 | return photo;
55 | }
56 |
57 | public void setPhoto(String photo) {
58 | this.photo = photo;
59 | }
60 |
61 | public BigInteger getUserId() {
62 | return userId;
63 | }
64 |
65 | public void setUserId(BigInteger userId) {
66 | this.userId = userId;
67 | }
68 |
69 | public BigInteger getFriendId() {
70 | return friendId;
71 | }
72 |
73 | public void setFriendId(BigInteger friendId) {
74 | this.friendId = friendId;
75 | }
76 |
77 | public BigInteger getGroupId() {
78 | return groupId;
79 | }
80 |
81 | public void setGroupId(BigInteger groupId) {
82 | this.groupId = groupId;
83 | }
84 |
85 | public String getAlias() {
86 | return alias;
87 | }
88 |
89 | public void setAlias(String alias) {
90 | this.alias = alias;
91 | }
92 |
93 | public String getDescription() {
94 | return description;
95 | }
96 |
97 | public void setDescription(String description) {
98 | this.description = description;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Member.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 用户和群聊的中间表
28 | * @date 2019-05-03 12:58
29 | */
30 | @Table(name = "member")
31 | public class Member extends BaseEntity {
32 | @JSONField(name = "user_id")
33 | private BigInteger userId;
34 | @JSONField(name = "chat_id")
35 | private BigInteger chatId;
36 | @JSONField(name = "group_alias")
37 | private String groupAlias;
38 | private String apply;
39 | private String background;
40 | private Integer level;
41 |
42 | public String getApply() {
43 | return apply;
44 | }
45 |
46 | public void setApply(String apply) {
47 | this.apply = apply;
48 | }
49 |
50 | public Integer getLevel() {
51 | return level;
52 | }
53 |
54 | public void setLevel(Integer level) {
55 | this.level = level;
56 | }
57 |
58 | public BigInteger getUserId() {
59 | return userId;
60 | }
61 |
62 | public void setUserId(BigInteger userId) {
63 | this.userId = userId;
64 | }
65 |
66 | public BigInteger getChatId() {
67 | return chatId;
68 | }
69 |
70 | public void setChatId(BigInteger chatId) {
71 | this.chatId = chatId;
72 | }
73 |
74 | public String getGroupAlias() {
75 | return groupAlias;
76 | }
77 |
78 | public void setGroupAlias(String groupAlias) {
79 | this.groupAlias = groupAlias;
80 | }
81 |
82 | public String getBackground() {
83 | return background;
84 | }
85 |
86 | public void setBackground(String background) {
87 | this.background = background;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 | import java.sql.Timestamp;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @description 用于存储消息数据
29 | * @date 2019-05-03 13:01
30 | */
31 | @Table(name = "message")
32 | public class Message extends BaseEntity {
33 | @JSONField(name = "sender_id")
34 | private BigInteger senderId;
35 | @JSONField(name ="chat_id")
36 | private BigInteger chatId;
37 | private String content;
38 | private String type;
39 | private Timestamp time;
40 |
41 |
42 | public String getType() {
43 | return type;
44 | }
45 |
46 | public void setType(String type) {
47 | this.type = type;
48 | }
49 |
50 | public Timestamp getTime() {
51 | return time;
52 | }
53 |
54 | public void setTime(Timestamp time) {
55 | this.time = time;
56 | }
57 |
58 | public BigInteger getSenderId() {
59 | return senderId;
60 | }
61 |
62 | public void setSenderId(BigInteger senderId) {
63 | this.senderId = senderId;
64 | }
65 |
66 | public BigInteger getChatId() {
67 | return chatId;
68 | }
69 |
70 | public void setChatId(BigInteger chatId) {
71 | this.chatId = chatId;
72 | }
73 |
74 | public String getContent() {
75 | return content;
76 | }
77 |
78 | public void setContent(String content) {
79 | this.content = content;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/News.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 动态表的实体类
28 | * @date 2019-05-07 18:44
29 | */
30 | @Table(name = "news")
31 | public class News extends BaseEntity {
32 | @JSONField(name = "user_id")
33 | private BigInteger userId;
34 | @JSONField(name = "tweet_Id")
35 | private BigInteger tweetId;
36 | private Boolean loved;
37 | private Boolean shared;
38 | private Boolean viewed;
39 | private Boolean collected;
40 |
41 | public BigInteger getUserId() {
42 | return userId;
43 | }
44 |
45 | public void setUserId(BigInteger userId) {
46 | this.userId = userId;
47 | }
48 |
49 | public BigInteger getTweetId() {
50 | return tweetId;
51 | }
52 |
53 | public void setTweetId(BigInteger tweetId) {
54 | this.tweetId = tweetId;
55 | }
56 |
57 | public Boolean getLoved() {
58 | return loved;
59 | }
60 |
61 | public void setLoved(Boolean loved) {
62 | this.loved = loved;
63 | }
64 |
65 | public Boolean getShared() {
66 | return shared;
67 | }
68 |
69 | public void setShared(Boolean shared) {
70 | this.shared = shared;
71 | }
72 |
73 | public Boolean getViewed() {
74 | return viewed;
75 | }
76 |
77 | public void setViewed(Boolean viewed) {
78 | this.viewed = viewed;
79 | }
80 |
81 | public Boolean getCollected() {
82 | return collected;
83 | }
84 |
85 | public void setCollected(Boolean collected) {
86 | this.collected = collected;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Record.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.hyc.www.dao.annotation.Table;
20 | import com.hyc.www.model.po.abs.BaseEntity;
21 |
22 | import java.math.BigInteger;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @description 负责记录消息记录
27 | * @date 2019-05-06 21:29
28 | */
29 | @Table(name = "record")
30 | public class Record extends BaseEntity {
31 | private BigInteger userId;
32 | private BigInteger messageId;
33 |
34 | public BigInteger getUserId() {
35 | return userId;
36 | }
37 |
38 | public void setUserId(BigInteger userId) {
39 | this.userId = userId;
40 | }
41 |
42 | public BigInteger getMessageId() {
43 | return messageId;
44 | }
45 |
46 | public void setMessageId(BigInteger messageId) {
47 | this.messageId = messageId;
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Remark.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 | import java.sql.Timestamp;
25 |
26 | @Table(name = "remark")
27 | public class Remark extends BaseEntity {
28 |
29 | @JSONField(name = "user_id")
30 | private BigInteger userId;
31 | @JSONField(name = "tweet_id")
32 | private BigInteger tweetId;
33 | private String content;
34 | private Timestamp time ;
35 | private Long love;
36 | private Long collect;
37 | private Long reply;
38 |
39 | public Timestamp getTime() {
40 | return time;
41 | }
42 |
43 | public void setTime(Timestamp time) {
44 | this.time = time;
45 | }
46 |
47 | public BigInteger getUserId() {
48 | return userId;
49 | }
50 |
51 | public void setUserId(BigInteger userId) {
52 | this.userId = userId;
53 | }
54 |
55 |
56 | public BigInteger getTweetId() {
57 | return tweetId;
58 | }
59 |
60 | public void setTweetId(BigInteger tweetId) {
61 | this.tweetId = tweetId;
62 | }
63 |
64 |
65 | public String getContent() {
66 | return content;
67 | }
68 |
69 | public void setContent(String content) {
70 | this.content = content;
71 | }
72 |
73 |
74 | public Long getLove() {
75 | return love;
76 | }
77 |
78 | public void setLove(Long love) {
79 | this.love = love;
80 | }
81 |
82 | public Long getCollect() {
83 | return collect;
84 | }
85 |
86 | public void setCollect(Long collect) {
87 | this.collect = collect;
88 | }
89 |
90 | public Long getReply() {
91 | return reply;
92 | }
93 |
94 | public void setReply(Long reply) {
95 | this.reply = reply;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Reply.java:
--------------------------------------------------------------------------------
1 | package com.hyc.www.model.po;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 | import com.hyc.www.dao.annotation.Table;
5 | import com.hyc.www.model.po.abs.BaseEntity;
6 |
7 | import java.math.BigInteger;
8 | import java.sql.Timestamp;
9 |
10 | @Table(name = "reply")
11 | public class Reply extends BaseEntity {
12 |
13 |
14 | @JSONField(name = "user_id")
15 | private BigInteger userId;
16 | @JSONField(name = "to_uid")
17 | private BigInteger toUid;
18 | @JSONField(name = "remark_id")
19 | private BigInteger remarkId;
20 | private Timestamp time;
21 | private String content;
22 | private long love;
23 |
24 | public Timestamp getTime() {
25 | return time;
26 | }
27 |
28 | public void setTime(Timestamp time) {
29 | this.time = time;
30 | }
31 |
32 | public BigInteger getUserId() {
33 | return userId;
34 | }
35 |
36 | public void setUserId(BigInteger userId) {
37 | this.userId = userId;
38 | }
39 |
40 |
41 | public BigInteger getToUid() {
42 | return toUid;
43 | }
44 |
45 | public void setToUid(BigInteger toUid) {
46 | this.toUid = toUid;
47 | }
48 |
49 |
50 | public BigInteger getRemarkId() {
51 | return remarkId;
52 | }
53 |
54 | public void setRemarkId(BigInteger remarkId) {
55 | this.remarkId = remarkId;
56 | }
57 |
58 |
59 | public String getContent() {
60 | return content;
61 | }
62 |
63 | public void setContent(String content) {
64 | this.content = content;
65 | }
66 |
67 |
68 | public long getLove() {
69 | return love;
70 | }
71 |
72 | public void setLove(long love) {
73 | this.love = love;
74 | }
75 |
76 |
77 |
78 |
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/Tweet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | import java.math.BigInteger;
24 | import java.sql.Timestamp;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @date 2019-05-07 11:36
29 | */
30 | @Table(name = "tweet")
31 | public class Tweet extends BaseEntity {
32 | @JSONField(name = "owner_id")
33 | private BigInteger ownerId;
34 | private String content;
35 | @JSONField(name = "origin_id")
36 | private BigInteger originId;
37 | private String sort;
38 | private Timestamp time;
39 | private Long love;
40 | private Long remark;
41 | private Long share;
42 | private Long view;
43 |
44 | public BigInteger getOriginId() {
45 | return originId;
46 | }
47 |
48 | public void setOriginId(BigInteger originId) {
49 | this.originId = originId;
50 | }
51 |
52 | public Timestamp getTime() {
53 | return time;
54 | }
55 |
56 | public void setTime(Timestamp time) {
57 | this.time = time;
58 | }
59 |
60 | public String getSort() {
61 | return sort;
62 | }
63 |
64 | public void setSort(String sort) {
65 | this.sort = sort;
66 | }
67 |
68 | public BigInteger getOwnerId() {
69 | return ownerId;
70 | }
71 |
72 | public void setOwnerId(BigInteger ownerId) {
73 | this.ownerId = ownerId;
74 | }
75 |
76 | public String getContent() {
77 | return content;
78 | }
79 |
80 | public void setContent(String content) {
81 | this.content = content;
82 | }
83 |
84 | public Long getLove() {
85 | return love;
86 | }
87 |
88 | public void setLove(Long love) {
89 | this.love = love;
90 | }
91 |
92 | public Long getRemark() {
93 | return remark;
94 | }
95 |
96 | public void setRemark(Long remark) {
97 | this.remark = remark;
98 | }
99 |
100 | public Long getShare() {
101 | return share;
102 | }
103 |
104 | public void setShare(Long share) {
105 | this.share = share;
106 | }
107 |
108 | public Long getView() {
109 | return view;
110 | }
111 |
112 | public void setView(Long view) {
113 | this.view = view;
114 | }
115 |
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/User.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po;
18 |
19 | import com.hyc.www.dao.annotation.Field;
20 | import com.hyc.www.dao.annotation.Table;
21 | import com.hyc.www.model.po.abs.BaseEntity;
22 |
23 | /**
24 | * @author 黄钰朝
25 | * @program www
26 | * @description 用户实体类
27 | * @date 2019-05-01 23:27
28 | */
29 | @Table(name = "user")
30 | public class User extends BaseEntity {
31 | @Field(name = "email")
32 | private String email;
33 | @Field(name = "weibo_id")
34 | private String weiboId;
35 | @Field(name = "phone")
36 | private String phone;
37 | @Field(name = "password")
38 | private String password;
39 | @Field(name = "gender")
40 | private String gender;
41 | @Field(name = "signature")
42 | private String signature;
43 | @Field(name = "name")
44 | private String name;
45 | @Field(name = "photo")
46 | private String photo;
47 | @Field(name = "chat_background")
48 | private String chatBackground;
49 | @Field(name = "location")
50 | private String location;
51 | @Field(name = "online_status")
52 | private String onlineStatus;
53 | private String type;
54 |
55 | public String getType() {
56 | return type;
57 | }
58 |
59 | public void setType(String type) {
60 | this.type = type;
61 | }
62 |
63 | public String getEmail() {
64 | return email;
65 | }
66 |
67 | public void setEmail(String email) {
68 | this.email = email;
69 | }
70 |
71 | public String getWeiboId() {
72 | return weiboId;
73 | }
74 |
75 | public void setWeiboId(String weiboId) {
76 | this.weiboId = weiboId;
77 | }
78 |
79 | public String getPhone() {
80 | return phone;
81 | }
82 |
83 | public void setPhone(String phone) {
84 | this.phone = phone;
85 | }
86 |
87 | public String getPassword() {
88 | return password;
89 | }
90 |
91 | public void setPassword(String password) {
92 | this.password = password;
93 | }
94 |
95 | public String getGender() {
96 | return gender;
97 | }
98 |
99 | public void setGender(String gender) {
100 | this.gender = gender;
101 | }
102 |
103 | public String getSignature() {
104 | return signature;
105 | }
106 |
107 | public void setSignature(String signature) {
108 | this.signature = signature;
109 | }
110 |
111 | public String getName() {
112 | return name;
113 | }
114 |
115 | public void setName(String name) {
116 | this.name = name;
117 | }
118 |
119 | public String getPhoto() {
120 | return photo;
121 | }
122 |
123 | public void setPhoto(String photo) {
124 | this.photo = photo;
125 | }
126 |
127 | public String getChatBackground() {
128 | return chatBackground;
129 | }
130 |
131 | public void setChatBackground(String chatBackground) {
132 | this.chatBackground = chatBackground;
133 | }
134 |
135 | public String getLocation() {
136 | return location;
137 | }
138 |
139 | public void setLocation(String location) {
140 | this.location = location;
141 | }
142 |
143 | public String getOnlineStatus() {
144 | return onlineStatus;
145 | }
146 |
147 | public void setOnlineStatus(String onlineStatus) {
148 | this.onlineStatus = onlineStatus;
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/po/abs/BaseEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.po.abs;
18 |
19 | import com.alibaba.fastjson.JSONObject;
20 | import com.hyc.www.dao.annotation.Field;
21 |
22 | import java.math.BigInteger;
23 | import java.util.Date;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @program www
28 | * @description 所有数据库记录的父类
29 | * @date 2019-05-01 23:19
30 | */
31 | public abstract class BaseEntity {
32 |
33 | @Field(name = "id")
34 | private BigInteger id;
35 | @Field(name = "status")
36 | private Integer status;
37 | @Field(name = "gmt_create")
38 | private Date gmtCreate;
39 | @Field(name = "gmt_modified")
40 | private Date gmtModified;
41 |
42 | public BigInteger getId() {
43 | return id;
44 | }
45 |
46 | public void setId(BigInteger id) {
47 | this.id = id;
48 | }
49 |
50 | public Integer getStatus() {
51 | return status;
52 | }
53 |
54 | public void setStatus(Integer status) {
55 | this.status = status;
56 | }
57 |
58 | public Date getGmtCreate() {
59 | return gmtCreate;
60 | }
61 |
62 | public void setGmtCreate(Date gmtCreate) {
63 | this.gmtCreate = gmtCreate;
64 | }
65 |
66 | public Date getGmtModified() {
67 | return gmtModified;
68 | }
69 |
70 | public void setGmtModified(Date gmtModified) {
71 | this.gmtModified = gmtModified;
72 | }
73 |
74 | /**
75 | * 所有的po层实体类都继承此类,在这里一次性重写toString方法,使用json格式输出
76 | *
77 | * @return
78 | * @name toString
79 | * @notice none
80 | * @author 黄钰朝
81 | * @date 2019/5/7
82 | */
83 | @Override
84 | public String toString() {
85 | return JSONObject.toJSONString(this);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/vo/MemberVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.vo;
18 |
19 | import com.hyc.www.model.po.Member;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 群成员的视图层实体类
24 | * @date 2019-05-10 05:22
25 | */
26 | public class MemberVO extends Member {
27 | private String name;
28 | private String signature;
29 | private String photo;
30 | public String getSignature() {
31 | return signature;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public void setSignature(String signature) {
43 | this.signature = signature;
44 | }
45 |
46 | public String getPhoto() {
47 | return photo;
48 | }
49 |
50 | public void setPhoto(String photo) {
51 | this.photo = photo;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/vo/MessageVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.vo;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.model.po.Message;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @description 用于传输用户发送的消息
25 | * @date 2019-05-07 01:53
26 | */
27 | public class MessageVO extends Message {
28 | @JSONField(name = "sender_name")
29 | private String senderName;
30 | @JSONField(name = "sender_photo")
31 | private String senderPhoto;
32 |
33 |
34 |
35 | public String getSenderName() {
36 | return senderName;
37 | }
38 |
39 | public void setSenderName(String senderName) {
40 | this.senderName = senderName;
41 | }
42 |
43 | public String getSenderPhoto() {
44 | return senderPhoto;
45 | }
46 |
47 | public void setSenderPhoto(String senderPhoto) {
48 | this.senderPhoto = senderPhoto;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/vo/RemarkVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.vo;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.model.po.Remark;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @description
25 | * @date 2019-05-14 02:09
26 | */
27 | public class RemarkVO extends Remark {
28 |
29 | @JSONField(name = "user_name")
30 | private String userName;
31 | @JSONField(name = "user_photo")
32 | private String userPhoto;
33 |
34 | public String getUserName() {
35 | return userName;
36 | }
37 |
38 | public void setUserName(String userName) {
39 | this.userName = userName;
40 | }
41 |
42 | public String getUserPhoto() {
43 | return userPhoto;
44 | }
45 |
46 | public void setUserPhoto(String userPhoto) {
47 | this.userPhoto = userPhoto;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/hyc/www/model/vo/TweetVO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.model.vo;
18 |
19 | import com.alibaba.fastjson.annotation.JSONField;
20 | import com.hyc.www.model.po.Tweet;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @description 朋友圈的视图层对象
25 | * @date 2019-05-07 20:12
26 | */
27 | public class TweetVO extends Tweet {
28 |
29 | @JSONField(name = "user_name")
30 | private String userName;
31 |
32 | @JSONField(name = "user_photo")
33 | private String userPhoto;
34 |
35 | public String getUserPhoto() {
36 | return userPhoto;
37 | }
38 |
39 | public void setUserPhoto(String userPhoto) {
40 | this.userPhoto = userPhoto;
41 | }
42 |
43 | public String getUserName() {
44 | return userName;
45 | }
46 |
47 | public void setUserName(String userName) {
48 | this.userName = userName;
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/RemarkProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider;
18 |
19 | import com.hyc.www.model.po.User;
20 | import com.hyc.www.provider.constant.RequestMethod;
21 | import com.hyc.www.factory.ServiceProxyFactory;
22 | import com.hyc.www.model.dto.ServiceResult;
23 | import com.hyc.www.model.po.Remark;
24 | import com.hyc.www.provider.annotation.Action;
25 | import com.hyc.www.provider.annotation.ActionProvider;
26 | import com.hyc.www.service.RemarkService;
27 | import com.hyc.www.service.impl.RemarkServiceImpl;
28 |
29 | import javax.servlet.http.HttpServletRequest;
30 | import javax.servlet.http.HttpServletResponse;
31 | import java.io.IOException;
32 | import java.math.BigInteger;
33 |
34 | import static com.hyc.www.util.BeanUtils.jsonToJavaObject;
35 | import static com.hyc.www.util.ControllerUtils.returnJsonObject;
36 |
37 | /**
38 | * @author 黄钰朝
39 | * @description 负责评论的业务流程
40 | * @date 2019-05-14 01:38
41 | */
42 | @ActionProvider(path = "/remark")
43 | public class RemarkProvider extends BaseProvider {
44 |
45 | private final RemarkService remarkService = (RemarkService) new ServiceProxyFactory().getProxyInstance(new RemarkServiceImpl());
46 | /**
47 | * 提供发布评论的业务流程
48 | *
49 | * @name postRemark
50 | * @notice none
51 | * @author 黄钰朝
52 | * @date 2019/5/14
53 | */
54 | @Action(method = RequestMethod.ADD_DO)
55 | public void postRemark(HttpServletRequest req, HttpServletResponse resp) throws IOException {
56 | Remark remark = (Remark) jsonToJavaObject(req.getInputStream(), Remark.class);
57 | ServiceResult result;
58 | User user = (User) req.getSession().getAttribute("login");
59 | result = remarkService.addRemark(user.getId(),remark);
60 | returnJsonObject(resp, result);
61 | }
62 |
63 | /**
64 | * 提供获取评论的业务流程
65 | *
66 | * @name listRemark
67 | * @notice none
68 | * @author 黄钰朝
69 | * @date 2019/5/14
70 | */
71 | @Action(method = RequestMethod.LIST_DO)
72 | public void listRemark(HttpServletRequest req, HttpServletResponse resp) throws IOException {
73 | String momentId = req.getParameter("tweet_id");
74 | String page = req.getParameter("page");
75 | ServiceResult result;
76 | result = remarkService.listRemark(new BigInteger(momentId), Integer.parseInt(page));
77 | returnJsonObject(resp, result);
78 | }
79 |
80 | /**
81 | * 提供删除评论的业务流程
82 | *
83 | * @name deleteRemark
84 | * @notice none
85 | * @author 黄钰朝
86 | * @date 2019/5/14
87 | */
88 | @Action(method = RequestMethod.DELETE_DO)
89 | public void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
90 | String remarkId = req.getParameter("remark_id");
91 | ServiceResult result;
92 | result = remarkService.removeRemark(new BigInteger(remarkId));
93 | returnJsonObject(resp, result);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/UploadProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider;
18 |
19 | import com.hyc.www.provider.constant.RequestMethod;
20 | import com.hyc.www.factory.ServiceProxyFactory;
21 | import com.hyc.www.model.dto.ServiceResult;
22 | import com.hyc.www.provider.annotation.Action;
23 | import com.hyc.www.provider.annotation.ActionProvider;
24 | import com.hyc.www.service.UploadService;
25 | import com.hyc.www.service.impl.UploadServiceImpl;
26 |
27 | import javax.servlet.ServletException;
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 | import javax.servlet.http.Part;
31 | import java.io.IOException;
32 |
33 | import static com.hyc.www.util.ControllerUtils.returnJsonObject;
34 |
35 | /**
36 | * @author 黄钰朝
37 | * @description 负责上传文件流程
38 | * @date 2019-05-06 02:38
39 | */
40 | @ActionProvider(path = "/upload")
41 | public class UploadProvider extends BaseProvider {
42 | private final UploadService uploadService = (UploadService) new ServiceProxyFactory().getProxyInstance(new UploadServiceImpl());
43 |
44 | @Action(method = RequestMethod.UPLOADPHOTO_DO)
45 | public void uploadPhoto(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
46 | Part part = req.getPart("file");
47 | Object id = req.getParameter("id");
48 | String tableName = req.getParameter("table");
49 | ServiceResult result;
50 | result = uploadService.uploadPhoto(part, id, tableName);
51 | returnJsonObject(resp, result);
52 | }
53 |
54 | @Action(method = RequestMethod.BACKGROUND_DO)
55 | public void uploadBackground(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
56 | Part part = req.getPart("file");
57 | Object id = req.getParameter("id");
58 | ServiceResult result;
59 | result = uploadService.uploadBackground(part, id);
60 | returnJsonObject(resp, result);
61 | }
62 |
63 |
64 | @Action(method = RequestMethod.UPLOADFILE_DO)
65 | public void uploadfile(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
66 | Part part = req.getPart("file");
67 | ServiceResult result;
68 | result = uploadService.uploadFile(part);
69 | returnJsonObject(resp, result);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/annotation/Action.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider.annotation;
18 |
19 |
20 | import com.hyc.www.provider.constant.RequestMethod;
21 |
22 | import java.lang.annotation.*;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @description 用于注解服务流程
27 | * @date 2019-05-02 09:42
28 | */
29 | @Documented
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Target(ElementType.METHOD)
32 | public @interface Action {
33 | String path()default "";
34 | RequestMethod method();
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/annotation/ActionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider.annotation;
18 |
19 | import java.lang.annotation.*;
20 |
21 | /**
22 | * @author 黄钰朝
23 | * @description 用于注解ActionProvider的url路径
24 | * @date 2019-05-02 11:28
25 | */
26 | @Documented
27 | @Retention(value = RetentionPolicy.RUNTIME)
28 | @Target(value = ElementType.TYPE)
29 | public @interface ActionProvider {
30 | String path () default "";
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/constant/RequestMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider.constant;
18 |
19 | /**
20 | * request中method的枚举常量
21 | *
22 | * @author 黄钰朝
23 | * @description
24 | * @date 2019-04-18 12:45
25 | */
26 |
27 | public enum RequestMethod {
28 |
29 | /**
30 | * 显示主页
31 | */
32 | INDEX_VIEW,
33 |
34 | /**
35 | * 无效请求
36 | */
37 |
38 | INVALID_REQUEST,
39 | /*
40 | **************************************************************
41 | * 用户功能模块
42 | **************************************************************
43 | */
44 | /**
45 | * 执行登陆方法
46 | */
47 | LOGIN_DO,
48 | /**
49 | * 执行注册方法
50 | */
51 | REGISTER_DO,
52 | /**
53 | * 执行退出登陆方法
54 | */
55 | LOGOUT_DO,
56 | /**
57 | * 更新密码
58 | */
59 | UPDATEPASSWORD_DO,
60 | /**
61 | * 个人主页
62 | */
63 | HOME_DO,
64 | /**
65 | * 获取关注列表
66 | */
67 | FOLLOW_DO,
68 | /**
69 | * 获取粉丝列表
70 | */
71 | FANS_DO,
72 | /**
73 | * 冻结用户
74 | */
75 | FREEZE_DO,
76 | /*
77 | **************************************************************
78 | * 聊天功能模块
79 | **************************************************************
80 | */
81 | /**
82 | * 加入聊天
83 | */
84 | JOIN_DO,
85 | /**
86 | * 退出聊天
87 | */
88 | QUIT_DO,
89 | /**
90 | * 查找群成员
91 | *
92 | */
93 | MEMBER_DO,
94 |
95 |
96 |
97 | /*
98 | **************************************************************
99 | * 好友功能模块
100 | **************************************************************
101 | */
102 |
103 | /*
104 | **************************************************************
105 | * 聊天记录功能模块
106 | **************************************************************
107 | */
108 | /**
109 | * 获取未读消息
110 | */
111 | UNREAD_DO,
112 | /**
113 | * 将消息设置为已读
114 | */
115 | READ_DO,
116 | /**
117 | * 删除一个聊天中所有聊天记录
118 | */
119 | CLEAR_DO,
120 | /**
121 | * 导出聊天记录
122 | */
123 | EXPORT_DO,
124 | /**
125 | * 移除群成员
126 | */
127 | REMOVE_DO,
128 |
129 | /*
130 | *************************T*************************************
131 | * 微博功能模块
132 | **************************************************************
133 | */
134 | /**
135 | * 获取用户自己发的微博
136 | */
137 | TWEET_DO,
138 | /**
139 | * 获取用户微博中的动态,包括自己的和朋友的
140 | */
141 | NEWS_DO,
142 | /**
143 | * 点赞和取消点赞
144 | */
145 | LOVE_DO,
146 | /**
147 | * 微博照片
148 | */
149 | PHOTO_DO,
150 |
151 |
152 | /*
153 | **************************************************************
154 | * 通用操作方法
155 | **************************************************************
156 | */
157 | /**
158 | * 上传
159 | */
160 | UPLOADPHOTO_DO,
161 | /**
162 | * 上传文件
163 | */
164 | UPLOADFILE_DO,
165 | /**
166 | * 更新聊天背景
167 | */
168 | BACKGROUND_DO,
169 |
170 | /**
171 | * 添加
172 | */
173 | ADD_DO,
174 | /**
175 | * 删除
176 | */
177 | DELETE_DO,
178 | /**
179 | * 更新
180 | */
181 | UPDATE_DO,
182 |
183 | /**
184 | * 查找一个对象
185 | */
186 | GET_DO,
187 | /**
188 | * 查找对象集合
189 | *
190 | */
191 | LIST_DO;
192 |
193 | @Override
194 | public String toString() {
195 | return super.toString().toLowerCase().replaceAll("_", ".");
196 | }
197 |
198 |
199 | }
200 |
201 |
--------------------------------------------------------------------------------
/src/com/hyc/www/provider/constant/WebPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.provider.constant;
18 |
19 | /**
20 | * 界面的地址常量
21 | *
22 | * @author 黄钰朝
23 | * @description
24 | * @date 2019-04-18 12:48
25 | */
26 | public enum WebPage {
27 |
28 |
29 | /**
30 | * 注册界面
31 | */
32 | REGISTER_JSP,
33 | /**
34 | * 网站首页
35 | */
36 | INDEX_JSP,
37 | /**
38 | * 错误页面
39 | */
40 | ERROR_JSP,
41 |
42 | /**
43 | * 登陆界面
44 | */
45 | LOGIN_JSP;
46 |
47 | @Override
48 | public String toString() {
49 | return "/"+super.toString().toLowerCase().replaceAll("_", ".");
50 | }
51 | }
--------------------------------------------------------------------------------
/src/com/hyc/www/service/FriendService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 | import com.hyc.www.model.po.Friend;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @description 负责好友相关服务
25 | * @date 2019-05-06 05:57
26 | */
27 | public interface FriendService {
28 | /**
29 | * 添加好友关系
30 | *
31 | * @param friend 要添加的好友关系
32 | * @return
33 | * @name addFriend
34 | * @notice none
35 | * @author 黄钰朝
36 | * @date 2019/5/6
37 | */
38 | ServiceResult addFriend(Friend friend);
39 |
40 |
41 | /**
42 | * 返回一个用户的好友列表
43 | *
44 | * @param userId 用户id
45 | * @return
46 | * @name listFriend
47 | * @notice none
48 | * @author 黄钰朝
49 | * @date 2019/5/6
50 | */
51 | ServiceResult listFriend(Object userId);
52 |
53 |
54 | /**
55 | * 返回一个用户关注的人
56 | *
57 | * @param userId
58 | * @return
59 | * @name listFollow
60 | * @notice none
61 | * @author 黄钰朝
62 | * @date 2019/5/30
63 | */
64 | ServiceResult listFollow(Object userId);
65 |
66 | /**
67 | * 返回一个用户的粉丝
68 | *
69 | * @param userId
70 | * @return
71 | * @name listMyfans
72 | * @notice none
73 | * @author 黄钰朝
74 | * @date 2019/5/30
75 | */
76 | ServiceResult listMyFans(Object userId);
77 |
78 | /**
79 | * 更新好友信息
80 | *
81 | * @param friend 朋友
82 | * @name updateFriend
83 | * @notice none
84 | * @author 黄钰朝
85 | * @date 2019/5/6
86 | */
87 | ServiceResult updateFriend(Friend friend);
88 |
89 |
90 | /**
91 | * 移除好友
92 | *
93 | * @param friend 要移除的好友关系
94 | * @return
95 | * @name removeFriend
96 | * @notice none
97 | * @author 黄钰朝
98 | * @date 2019/5/6
99 | */
100 | ServiceResult removeFriend(Friend friend);
101 |
102 |
103 | /**
104 | * 判断是否存在一条这样的朋友记录
105 | *
106 | * @param friend 判断该朋友关系是否是双向的
107 | * @name isFriend
108 | * @notice none
109 | * @author 黄钰朝
110 | * @date 2019/5/6
111 | */
112 | boolean isFriend(Friend friend);
113 |
114 | /**
115 | * 通过用户id和朋友id查询朋友关系
116 | *
117 | * @param uid 用户id
118 | * @param friendId 朋友id
119 | * @return
120 | * @name getByUidAndFriendId
121 | * @notice none
122 | * @author 黄钰朝
123 | * @date 2019/5/6
124 | */
125 | Friend getByUidAndFriendId(Object uid, Object friendId);
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/MessageService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 | import com.hyc.www.model.po.Message;
21 |
22 | import java.math.BigInteger;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @description 负责提供消息保存,聊天记录管理的服务
27 | * @date 2019-05-07 11:15
28 | */
29 | public interface MessageService {
30 |
31 | /**
32 | * 将一条消息存入数据库,同时给聊天中的所有成员生成一份聊天记录
33 | *
34 | * @param message 要插入的消息
35 | * @name insertMessage
36 | * @notice none
37 | * @author 黄钰朝
38 | * @date 2019/5/7
39 | */
40 | void insertMessage(Message message);
41 |
42 | /**
43 | * 获取一个用户在一个聊天中的所有消息记录,不包括被删除的消息记录
44 | *
45 | * @param userId 用户id
46 | * @param chatId 聊天id
47 | * @param page 页数
48 | * @return
49 | * @author 黄钰朝
50 | * @date 2019/5/7
51 | */
52 | ServiceResult listAllMessage(Object userId, Object chatId, int page);
53 |
54 | /**
55 | * 获取一个用户在一个聊天中的所有未读的消息
56 | *
57 | * @param userId 用户id
58 | * @param chatId 聊天id
59 | * @param page 页数
60 | * @name listUnreadMessage
61 | * @notice none
62 | * @author 黄钰朝
63 | * @date 2019/5/7
64 | */
65 | ServiceResult listUnreadMessage(Object userId, Object chatId, int page);
66 |
67 |
68 | /**
69 | * 获取一个用户的所有未读的消息
70 | *
71 | * @param userId 用户id
72 | * @param page 页数
73 | * @notice none
74 | * @author 黄钰朝
75 | * @date 2019/5/7
76 | */
77 | ServiceResult listAllUnreadMessage(Object userId, int page);
78 |
79 | /**
80 | * 将一条消息从一个用户的消息记录中移除,并不会删除这条消息
81 | *
82 | * @param userId 用户id
83 | * @param messageId 要移除的消息记录id
84 | * @name removeMessage
85 | * @notice 本方法没有将消息删除,只是将该用户的对应这条消息的记录删除,
86 | * 其他拥有这条消息的记录的用户依然可以访问这条消息
87 | * @author 黄钰朝
88 | * @date 2019/5/7
89 | */
90 | ServiceResult removeMessage(BigInteger userId, BigInteger messageId);
91 |
92 |
93 | /**
94 | * 删除一个用户在一个聊天中的所有记录
95 | *
96 | * @param userId 用户id
97 | * @param chatId 要移除的消息记录的聊天id
98 | * @name removeAllMessage
99 | * @notice 本方法没有将消息删除,只是将该用户的对应这条消息的记录删除,
100 | * 其他拥有这条消息的记录的用户依然可以访问这条消息
101 | * @author 黄钰朝
102 | * @date 2019/5/7
103 | */
104 | ServiceResult removeAllMessage(BigInteger userId, BigInteger chatId);
105 |
106 | /**
107 | * 导出一个用户在一个聊天中的所有消息记录,返回文件名
108 | *
109 | * @param userId 用户id
110 | * @param chatId 聊天id
111 | * @author 黄钰朝
112 | * @date 2019/5/7
113 | */
114 | ServiceResult exportMessage(Object userId, Object chatId);
115 |
116 |
117 | /**
118 | * 撤回一条消息
119 | *
120 | * @param userId 用户id
121 | * @param messageId 消息id
122 | * @name drawMessage
123 | * @notice 这个方法会将消息删除
124 | * @author 黄钰朝
125 | * @date 2019/5/7
126 | */
127 | ServiceResult drawBackMessage(BigInteger userId, BigInteger messageId);
128 |
129 |
130 |
131 |
132 | /**
133 | * 将一个用户在一个聊天中收到的消息记录设置为已读
134 | *
135 | * @param userId 用户id
136 | * @param chatId 聊天id
137 | * @name setAlreadyRead
138 | * @notice none
139 | * @author 黄钰朝
140 | * @date 2019/5/7
141 | */
142 | void setAlreadyRead(Object userId, Object chatId);
143 | }
144 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/RemarkService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 | import com.hyc.www.model.po.Remark;
21 | import com.hyc.www.service.annotation.Freeze;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 负责评论服务
28 | * @date 2019-05-14 01:14
29 | */
30 | public interface RemarkService {
31 | /**添加一条评论
32 | * @name addRemark
33 | * @param remark 评论
34 | * @notice none
35 | * @author 黄钰朝
36 | * @date 2019/5/14
37 | */
38 | @Freeze
39 | ServiceResult addRemark(BigInteger userId,Remark remark);
40 | /**
41 | * 查询一条评论
42 | *
43 | * @param momentId 朋友圈id
44 | * @param page 页数
45 | * @name listRemark
46 | * @notice none
47 | * @author 黄钰朝
48 | * @date 2019/5/14
49 | */
50 | ServiceResult listRemark(BigInteger momentId, int page);
51 |
52 | /**
53 | * 删除一条评论
54 | *
55 | * @param remarkId 评论id
56 | * @name removeRemark
57 | * @notice none
58 | * @author 黄钰朝
59 | * @date 2019/5/14
60 | */
61 | ServiceResult removeRemark(BigInteger remarkId);
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/ReplyService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 负责回复服务
22 | * @date 2019-05-14 01:14
23 | */
24 | public interface ReplyService {
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/TweetService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 | import com.hyc.www.model.po.Tweet;
21 | import com.hyc.www.service.annotation.Freeze;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 负责提供微博相关的服务
28 | * @date 2019-05-07 13:13
29 | */
30 | public interface TweetService {
31 |
32 | /**
33 | * 插入一条微博
34 | *
35 | * @param tweet 微博
36 | * @name insertTweet
37 | * @notice none
38 | * @author 黄钰朝
39 | * @date 2019/5/7
40 | */
41 | @Freeze
42 | ServiceResult insertTweet(BigInteger userId,Tweet tweet);
43 |
44 |
45 | /**
46 | * 删除一条微博
47 | *
48 | * @param tweetId 微博id
49 | * @name removeTweet
50 | * @notice none
51 | * @author 黄钰朝
52 | * @date 2019/5/7
53 | */
54 | ServiceResult removeTweet(BigInteger tweetId);
55 |
56 | /**
57 | * 更新一条微博
58 | *
59 | * @param tweet 要更新的微博
60 | * @name updateTweet
61 | * @notice none
62 | * @author 黄钰朝
63 | * @date 2019/5/7
64 | */
65 | ServiceResult updateTweet(Tweet tweet);
66 |
67 | /**
68 | * 查询一个用户所发的所有微博
69 | *
70 | * @param page 页数
71 | * @param userId 用户id
72 | * @name listNews
73 | * @notice none
74 | * @author 黄钰朝
75 | * @date 2019/5/7
76 | */
77 | ServiceResult listMyTweet(BigInteger userId, int page);
78 |
79 |
80 | /**
81 | * 查询一个用户可见的所有微博,包括自己的和朋友的
82 | *
83 | * @param userId 用户id
84 | * @param page 页数
85 | * @param sort 分类
86 | * @name listTweet
87 | * @notice none
88 | * @author 黄钰朝
89 | * @date 2019/5/7
90 | */
91 | public ServiceResult listTweet(BigInteger userId, String sort, int page);
92 |
93 | /**
94 | * 更新一个用户对一条微博的点赞状态
95 | *
96 | * @param userId 用户id
97 | * @param momentId 微博id
98 | * @name love
99 | * @notice none
100 | * @author 黄钰朝
101 | * @date 2019/5/8
102 | */
103 | ServiceResult love(BigInteger userId, BigInteger momentId);
104 |
105 | /**
106 | * 查询一个用户微博中的所有图片
107 | *
108 | * @param userId 用户id
109 | * @param page 页数
110 | * @name loadPhoto
111 | * @notice none
112 | * @author 黄钰朝
113 | * @date 2019/5/10
114 | */
115 | ServiceResult listPhoto(BigInteger userId, int page);
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/UploadService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 |
21 | import javax.servlet.http.Part;
22 |
23 | /**
24 | * @author 黄钰朝
25 | * @description 负责提供文件上传服务
26 | * @date 2019-05-06 02:23
27 | */
28 | public interface UploadService {
29 |
30 | /**
31 | * 负责将文件写入文件,并将数据库表对应的记录上的photo属性值修改为文件名
32 | *
33 | * @param part 文件
34 | * @param id 记录id
35 | * @param tableName 表名
36 | * @return
37 | * @name uploadPhoto
38 | * @notice none
39 | * @author 黄钰朝
40 | * @date 2019/5/6
41 | */
42 | ServiceResult uploadPhoto(Part part, Object id, String tableName);
43 |
44 | /**
45 | * 负责将文件写入文件,并将数据库表对应聊天背景属性值修改为文件名
46 | *
47 | * @param part 文件
48 | * @param id 记录id
49 | * @return
50 | * @name uploadBackground
51 | * @notice none
52 | * @author 黄钰朝
53 | * @date 2019/5/9
54 | */
55 | ServiceResult uploadBackground(Part part, Object id);
56 |
57 |
58 | /**
59 | * 负责将文件写入文件,并返回文件名
60 | *
61 | * @param part 文件
62 | * @name uploadFile
63 | * @notice none
64 | * @author 黄钰朝
65 | * @date 2019/5/14
66 | */
67 | ServiceResult uploadFile(Part part);
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/UserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service;
18 |
19 | import com.hyc.www.model.dto.ServiceResult;
20 | import com.hyc.www.model.po.User;
21 | import com.hyc.www.service.annotation.Admin;
22 |
23 | import java.math.BigInteger;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @program www
28 | * @description 负责提供用户服务
29 | * @date 2019-05-02 02:18
30 | */
31 | public interface UserService {
32 | /**
33 | * 检查注册用户的信息是否有效
34 | *
35 | * @param user 用户对象
36 | * @return 返回传入时的对象
37 | */
38 | ServiceResult checkRegister(User user);
39 |
40 | /**
41 | * 添加一个用户账号
42 | *
43 | * @param user 用户对象
44 | * @return 返回传入的用户的对象
45 | */
46 | ServiceResult insertUser(User user);
47 |
48 | /**
49 | * 校验用户的密码
50 | *
51 | * @param user 用户对象
52 | * @return 返回传入的用户对象
53 | */
54 | ServiceResult checkPassword(User user);
55 |
56 | /**
57 | * 校验用户名(微信号),是否合法,是否已被占用
58 | *
59 | * @param weiboId 微信号
60 | * @return 返回传入的用户名
61 | */
62 | ServiceResult checkWeiboId(String weiboId);
63 |
64 | /**
65 | * 通过用户id获取用户个人信息
66 | *
67 | * @param id 用户id
68 | * @return 返回用户的个人信息
69 | */
70 | ServiceResult getUser(BigInteger id);
71 |
72 |
73 | /**
74 | * 更新用户的个人信息,不包括密码,邮箱
75 | *
76 | * @param user 用户对象
77 | * @return 返回传入的用户对象,如果由密码信息/邮箱信息,将被清空
78 | */
79 | ServiceResult updateUser(User user);
80 |
81 | /**
82 | * 更新用户的个人密码
83 | *
84 | * @param oldPwd 旧密码
85 | * @param newPwd 新密码
86 | * @param userId 用户id
87 | * @return 返回传入的用户对象,如果由密码信息/邮箱信息,将被清空
88 | */
89 | ServiceResult updatePwd(String oldPwd, String newPwd, BigInteger userId);
90 |
91 | /**
92 | * 返回昵称与传入参数相似的用户列表
93 | *
94 | * @param name 用户昵称
95 | * @return
96 | * @name listUserLikeName
97 | * @notice none
98 | * @author 黄钰朝
99 | * @date 2019/5/6
100 | */
101 | ServiceResult listUserLikeName(String name);
102 |
103 | /**
104 | * 创建一个游客账号,并自动通过登陆
105 | *
106 | * @name visitorLogin
107 | * @notice none
108 | * @author 黄钰朝
109 | * @date 2019/5/9
110 | */
111 | ServiceResult visitorLogin();
112 |
113 |
114 | /**
115 | * 冻结一个用户
116 | *
117 | * @param operatorId 操作者id
118 | * @param userId 被冻结用户id
119 | * @return
120 | * @name freezeUser
121 | * @notice none
122 | * @author 黄钰朝
123 | * @date 2019/5/30
124 | */
125 | @Admin
126 | ServiceResult freezeUser(BigInteger operatorId, BigInteger userId);
127 |
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/annotation/Admin.java:
--------------------------------------------------------------------------------
1 | package com.hyc.www.service.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * @author 黄钰朝
7 | * @description 负责注解需要检查用户是否是管理员的方法
8 | * @date 2019-05-30 17:24
9 | */
10 | @Documented
11 | @Target(value = ElementType.METHOD)
12 | @Retention(value= RetentionPolicy.RUNTIME)
13 | public @interface Admin {
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/annotation/Freeze.java:
--------------------------------------------------------------------------------
1 | package com.hyc.www.service.annotation;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * @author 黄钰朝
7 | * @description 负责注解需要检查用户是否被冻结的方法
8 | * @date 2019-05-30 17:24
9 | */
10 | @Documented
11 | @Target(value = ElementType.METHOD)
12 | @Retention(value= RetentionPolicy.RUNTIME)
13 | public @interface Freeze {
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/constants/ChatType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service.constants;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 聊天类型
22 | * @date 2019-05-14 17:20
23 | */
24 | public enum ChatType {
25 | /**
26 | * 群聊
27 | */
28 | GROUP,
29 | /**
30 | * 私聊
31 | */
32 | FRIEND;
33 |
34 | @Override
35 | public String toString() {
36 | return super.toString().toLowerCase();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/constants/MessageType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service.constants;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 用于枚举消息的类型
22 | * @date 2019-05-13 11:29
23 | */
24 | public enum MessageType {
25 | /**
26 | * 用户之间的文本消息
27 | */
28 | USER,
29 | /**
30 | * 图片消息
31 | */
32 | IMG,
33 | /**
34 | * 文件消息
35 | */
36 | FILE,
37 | /**
38 | * 加好友通知
39 | */
40 | FRIEND;
41 | @Override
42 | public String toString() {
43 | return super.toString().toLowerCase();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/hyc/www/service/constants/Status.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service.constants;
18 |
19 |
20 | /**
21 | * 用于描述服务的状态
22 | * @author 黄钰朝
23 | * @description 服务状态码
24 | * @date 2019-05-01
25 | */
26 | public enum Status {
27 |
28 | /*
29 | **************************************************************
30 | * 操作状态
31 | **************************************************************
32 | */
33 | /**
34 | * 服务成功
35 | */
36 | SUCCESS,
37 | /**
38 | * 服务错误
39 | */
40 | ERROR;
41 | }
--------------------------------------------------------------------------------
/src/com/hyc/www/service/constants/UserType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.service.constants;
18 |
19 | /**
20 | * @author 黄钰朝
21 | * @description 聊天类型
22 | * @date 2019-05-14 17:20
23 | */
24 | public enum UserType {
25 | /**
26 | * 用户
27 | */
28 | USER,
29 | /**
30 | * 管理员
31 | */
32 | ADMIN;
33 |
34 | @Override
35 | public String toString() {
36 | return super.toString().toLowerCase();
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/com/hyc/www/test/TestDao.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.test;
18 |
19 | import com.hyc.www.dao.MessageDao;
20 | import com.hyc.www.factory.DaoProxyFactory;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @program www
25 | * @description 测试SQLHandler
26 | * @date 2019-05-01 17:50
27 | */
28 | public class TestDao {
29 | public static void main(String[] args) {
30 | MessageDao messageDao = (MessageDao) DaoProxyFactory.getInstance().getProxyInstance(MessageDao.class);
31 |
32 | // RecordDao recordDao = (RecordDao) DaoProxyFactory.getInstance().getProxyInstance(RecordDao.class);
33 | //
34 | // recordDao.deleteAllRecordInChat(210,59);
35 | // User user = new User();
36 | // user.setName("testasdf中文");
37 | // userDao.insert(user);
38 | // System.out.println(userDao.getLastInsert().getId());
39 | // user = userDao.getUserById("50");
40 | // List list = userDao.listLikeName("%昵称%");
41 | // System.out.println("查询到记录:" + list.size() + "条");
42 | // ChatDao chatDao = (ChatDao) DaoProxyFactory.getInstance().getProxyInstance(ChatDao.class);
43 | // chatDao.toFriendChat("4", "123");
44 | // Tweet moment = new Tweet();
45 | // moment.setOwnerId(BigInteger.valueOf(0));
46 | // moment.setContent("一条朋友圈");
47 | // moment.setLove(10L);
48 | // TweetDao momentDao = (TweetDao) DaoProxyFactory.getInstance().getProxyInstance(TweetDao.class);
49 | // momentDao.insert(moment);
50 | //
51 | // messageDao.listMessageByUserIdAndChatId("0","0",10,1000);
52 | //
53 | // News news = new News();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/hyc/www/test/TestDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.test;
18 |
19 | import com.hyc.www.dao.DataSource;
20 | import com.hyc.www.dao.impl.DataSourceImpl;
21 | import com.hyc.www.util.JdbcUtils;
22 |
23 | import java.sql.Connection;
24 | import java.sql.SQLException;
25 |
26 | /**
27 | * @author 黄钰朝
28 | * @program www
29 | * @description 测试数据源
30 | * @date 2019-05-01 16:49
31 | */
32 | public class TestDataSource {
33 | public static void main(String[] args) throws SQLException {
34 | System.out.println("测试直接从数据源获取连接");
35 | DataSource dataSource = DataSourceImpl.getInstance();
36 | Connection conn = dataSource.getConnection();
37 | System.out.println("获取一个连接\n");
38 | System.out.println(conn);
39 | System.out.println("当前已创建连接数 = " + dataSource.getCurrentCount());
40 | System.out.println("当前空闲连接数 = " + dataSource.getfreeCount());
41 | System.out.println("释放一个连接");
42 | dataSource.freeConnection(conn);
43 | for (int i = 0; i < 10; i++) {
44 | conn = dataSource.getConnection();
45 | System.out.println(conn);
46 | JdbcUtils.close(conn);
47 | }
48 | System.out.println("释放一个连接");
49 | dataSource.freeConnection(conn);
50 | System.out.println("当前已创建连接数 = " + dataSource.getCurrentCount());
51 | System.out.println("当前空闲连接数 = " + dataSource.getfreeCount());
52 |
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/hyc/www/test/TestJson.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.test;
18 |
19 | import com.alibaba.fastjson.JSON;
20 | import com.alibaba.fastjson.JSONObject;
21 | import com.hyc.www.model.po.User;
22 |
23 | import java.util.Date;
24 |
25 | /**
26 | * @author 黄钰朝
27 | * @description 测试Json
28 | * @date 2019-05-04 01:02
29 | */
30 | public class TestJson {
31 | public static void main(String[] args) {
32 | JSON json = JSONObject.parseObject(
33 | "{\"id\":\"2\", " +
34 | "\"wechat___id\":\"s\"}"
35 | );
36 | User user = JSONObject.toJavaObject(json,User.class);
37 | System.out.println(user.getId());
38 | System.out.println(user.getWeiboId());
39 | System.out.println(new Date(1309237).toString());
40 |
41 | System.out.println(user.toString());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/hyc/www/test/TestLog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.test;
18 |
19 |
20 | import org.apache.log4j.Logger;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @description 用于测试日志打印
25 | * @date 2019-05-02 17:12
26 | */
27 | public class TestLog {
28 | public static void main(String[] args) {
29 | log("日志信息");
30 |
31 | }
32 |
33 | public static void log(String logInfo){
34 | // 1. create log
35 | Logger log = Logger.getLogger(TestLog.class);
36 | // 2. get log config file
37 | // 3. start log
38 | log.debug(logInfo);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/hyc/www/test/TestService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.test;
18 |
19 | import com.hyc.www.model.po.Message;
20 | import com.hyc.www.model.po.Tweet;
21 | import com.hyc.www.service.MessageService;
22 | import com.hyc.www.service.TweetService;
23 | import com.hyc.www.service.UserService;
24 | import com.hyc.www.service.impl.MessageServiceImpl;
25 | import com.hyc.www.service.impl.TweetServiceImpl;
26 | import com.hyc.www.service.impl.UserServiceImpl;
27 |
28 | import java.math.BigInteger;
29 | import java.sql.Timestamp;
30 | import java.util.List;
31 |
32 | /**
33 | * @author 黄钰朝
34 | * @description 测试服务层
35 | * @date 2019-05-06 06:43
36 | */
37 | public class TestService {
38 | public static void main(String[] args) {
39 | UserService userService = new UserServiceImpl();
40 | List list = (List) userService.listUserLikeName("昵称").getData();
41 | System.out.println("查询到:"+list.size());
42 |
43 | MessageService messageService = new MessageServiceImpl();
44 | Message message = new Message();
45 | message.setChatId(BigInteger.valueOf(44));
46 | message.setSenderId(BigInteger.valueOf(0));
47 | message.setContent("测试");
48 | Timestamp timestamp = new Timestamp(1234);
49 | message.setTime(new Timestamp(1111111111));
50 | messageService.insertMessage(message);
51 | messageService.listAllMessage(0,40,1);
52 | messageService.listUnreadMessage(0,40,1);
53 | messageService.setAlreadyRead(0,40);
54 |
55 | TweetService tweetService = new TweetServiceImpl();
56 | Tweet tweet =new Tweet();
57 | tweet.setOwnerId(BigInteger.valueOf(0));
58 | tweet.setContent("第一条朋友圈");
59 | tweetService.removeTweet(BigInteger.valueOf(8));
60 | tweetService.listMyTweet(BigInteger.valueOf(0),1);
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/hyc/www/util/ControllerUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.util;
18 |
19 | import com.alibaba.fastjson.JSON;
20 | import com.hyc.www.provider.constant.RequestMethod;
21 | import com.hyc.www.model.dto.ServiceResult;
22 | import org.apache.log4j.Logger;
23 |
24 | import javax.servlet.http.HttpServletResponse;
25 | import java.io.IOException;
26 |
27 | /**
28 | * @author 黄钰朝
29 | * @program www
30 | * @description 控制层工具类
31 | * @date 2019-05-02 17:35
32 | */
33 | public class ControllerUtils {
34 |
35 |
36 | /**
37 | * 返回请求中method对应的RequestMethod枚举项
38 | *
39 | * @param name 请求中的method参数值
40 | * @name valueOf
41 | * @notice none
42 | * @author 黄钰朝
43 | * @date 2019/4/20
44 | * @see RequestMethod
45 | */
46 | public static RequestMethod valueOf(String name) {
47 | try {
48 | name = name.toUpperCase().replaceAll("\\.", "_");
49 | return RequestMethod.valueOf(name);
50 | } catch (IllegalArgumentException | NullPointerException e) {
51 | //此处异常表明请求参数没有匹配到任何服务,为无效请求
52 | e.printStackTrace();
53 | return RequestMethod.INVALID_REQUEST;
54 | }
55 | }
56 |
57 | /**
58 | * 用户将服务结果转换成json数据并返回客户端
59 | *
60 | * @param resp 响应
61 | * @param result 服务结果
62 | * @return
63 | * @name returnJsonObject
64 | * @notice none
65 | * @author 黄钰朝
66 | * @date 2019/5/6
67 | */
68 | public static void returnJsonObject(HttpServletResponse resp, ServiceResult result) throws IOException {
69 | JSON json = (JSON) JSON.toJSON(result);
70 | resp.getWriter().write(json.toJSONString());
71 | }
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/src/com/hyc/www/util/Md5Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.util;
18 |
19 | import java.io.UnsupportedEncodingException;
20 | import java.security.MessageDigest;
21 | import java.security.NoSuchAlgorithmException;
22 | import java.util.Base64;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @program www
27 | * @description 用于对用户的密码进行摘要处理
28 | * @date 2019-04-16 00:50
29 | */
30 | public class Md5Utils {
31 | private static final String ENCODING = "UTF-8";
32 |
33 | private Md5Utils() {
34 | }
35 |
36 | public static String getDigest(String originText) {
37 | MessageDigest md = null;
38 | byte[] digest = null;
39 | try {
40 | md = MessageDigest.getInstance("md5");
41 | digest = md.digest(originText.getBytes(ENCODING));
42 | } catch (NoSuchAlgorithmException e) {
43 | throw new RuntimeException("无法支持md5加密", e);
44 | } catch (UnsupportedEncodingException e) {
45 | throw new RuntimeException("无法支持UTF-8编码格式", e);
46 | }
47 | return Base64.getEncoder().encodeToString(digest);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/hyc/www/util/ReflectUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.util;
18 |
19 | import java.lang.reflect.Field;
20 | import java.lang.reflect.Method;
21 | import java.util.Arrays;
22 | import java.util.LinkedList;
23 |
24 | /**
25 | * @author 黄钰朝
26 | * @program XHotel
27 | * @description 用于反射的工具
28 | * @date 2019-04-20 02:28
29 | */
30 | public class ReflectUtils {
31 |
32 |
33 | public static LinkedList getMethods(Object obj) {
34 | return getMethods(obj.getClass());
35 | }
36 |
37 | public static LinkedList getMethods(Class clazz) {
38 | LinkedList methods = new LinkedList<>();
39 | for (Class cla = clazz; cla != Object.class; cla = cla.getSuperclass()) {
40 | methods.addAll(Arrays.asList(cla.getDeclaredMethods()));
41 | }
42 | return methods;
43 | }
44 |
45 | public static LinkedList getFields(Object obj) {
46 | return getFields(obj.getClass());
47 | }
48 |
49 | public static LinkedList getFields(Class clazz) {
50 | LinkedList fields = new LinkedList<>();
51 | for (Class cla = clazz; cla != Object.class; cla = cla.getSuperclass()) {
52 | fields.addAll(Arrays.asList(cla.getDeclaredFields()));
53 | }
54 | return fields;
55 | }
56 |
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/hyc/www/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019. 黄钰朝
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.hyc.www.util;
18 |
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * @author 黄钰朝
24 | * @program www
25 | * @description 用于字符串的转换
26 | * @date 2019-04-15 17:28
27 | */
28 | public class StringUtils {
29 |
30 | /**
31 | * 返回一个关键词的各种模糊搜索数组
32 | *
33 | * @param keyWord
34 | * @return
35 | * @name toLikeSql
36 | * @notice none
37 | * @author 黄钰朝
38 | * @date 2019/5/6
39 | */
40 | public static String[] toLikeSql(String keyWord) {
41 | //TODO 添加每个字符的模糊搜索
42 | ArrayList list = new ArrayList<>();
43 | String sql = "%" + keyWord + "%";
44 | list.add(sql);
45 | String[] strings = new String[list.size()];
46 | return list.toArray(strings);
47 | }
48 |
49 | /**
50 | * 将属性名转成get方法名
51 | *
52 | * @param field 属性名
53 | * @return
54 | * @name field2GetMethod
55 | * @notice none
56 | * @author 黄钰朝
57 | * @date 2019/5/6
58 | */
59 | public static String field2GetMethod(String field) {
60 | StringBuilder method = new StringBuilder("get" + field);
61 | method.setCharAt(3, (char) (method.charAt(3) - 32));
62 | return method.toString();
63 | }
64 |
65 | /**
66 | * 将java变量名转化成mysql的属性名,在每个大写字母的前面加上'_'
67 | *
68 | * @param field java属性
69 | * @return mysql属性名
70 | * @name field2SqlField
71 | * @notice none
72 | * @author 黄钰朝
73 | * @date 2019/5/3
74 | */
75 | public static String field2SqlField(String field) {
76 | byte[] bytes = field.getBytes();
77 | StringBuilder name = new StringBuilder();
78 | for (byte aByte : bytes) {
79 | if (aByte >= 'A' && aByte <= 'Z') {
80 | name.append('_');
81 | }
82 | name.append((char) aByte);
83 | }
84 | return name.toString();
85 | }
86 |
87 | public static String field2SetMethod(String field) {
88 | StringBuilder method = new StringBuilder("set" + field);
89 | method.setCharAt(3, (char) (method.charAt(3) - 32));
90 | return method.toString();
91 | }
92 |
93 | /**
94 | * 去除输入中的不合法字符,防止标签注入
95 | *
96 | * @param str 需要被过滤的字符
97 | * @return
98 | * @name
99 | * @notice none
100 | * @author 黄钰朝
101 | * @date 2019/4/23
102 | */
103 | public static String toLegalText(String str) {
104 | if (str == null || str.trim().isEmpty()) {
105 | return "";
106 | }
107 | str = toLegalTextIgnoreTag(str);
108 | String htmlLabel = "<[^>]+>";
109 | str = str.replaceAll(htmlLabel, "");
110 | str = str.replace("\"", "");
111 | str = str.replaceAll("\t|\r|\n", "");
112 | return str;
113 | }
114 |
115 | /**
116 | * 去除输入中的不合法字符,忽略html标签
117 | *
118 | * @param str 需要被过滤的字符
119 | * @return
120 | * @name
121 | * @notice none
122 | * @author 黄钰朝
123 | * @date 2019/4/23
124 | */
125 | public static String toLegalTextIgnoreTag(String str) {
126 | if (str == null || str.trim().isEmpty()) {
127 | return "";
128 | }
129 | String styleLabel = "
151 |