愿景:"让编程不再难学,让技术与生活更加有趣"
更多架构课程请访问 xdclass.net
目录
Maven3.x创建小滴课堂开发者论坛项目和配置tomcat9
大话互联网公司软件开发流程
简介: 概述互联网公司软件开发流程
-
软件开发流程
-
需求分析
-
设计
- UI设计
- 架构设计
-
开发
- 前端开发
- 后端开发
-
测试
- 功能测试
- 性能测试
- 安全测试
-
上线
- 预发布环境
- 灰度
- 全量
-
多次迭代更新
-
小滴课堂开发者论坛效果演示和需求分析
简介:小滴课堂开发者论坛效果演示和需求分析
- 演示功能,后续开发不演示流程
- 分类列表功能
- 主题列表功能-分页
- 主题详情功能-分页
- 注册登录
- 回复盖楼功能
- 练手项目,从Javaweb基础整合进阶,学完再继续跟着路线学习综合项目
小滴课堂开发者论坛数据库ER关系图设计
简介:小滴课堂开发者论坛数据库ER图设计
-
什么是ER图
- 实体关系图,是一种提供了实体,属性和联系的方法,用来描述现实世界的概念模型
-
实体
- 现实世界中的对象,可以具体到人,事,物,比如 学生、教师、商品、订单、主题、菜单等
- ER图里面 用矩形表示,矩形框内写明实体名
-
属性
- 实体所具有的某一个特性称为属性,在E-R图中属性用来描述实体,比如 商品实体,有标题、价格、图片等属性
- ER图里面用椭圆形或圆角矩形表示,并用无向边将其与相应的实体连接起来
-
关系
-
任何事物都不是孤立存在的,事物内部和事物之间都有联系的,实体之间的联系通常有3种类型:一对一联系,一对多联系,多对多联系;比如商品和订单的关系、班级和学生的关系、主题和评论的关系
-
ER图里用菱形表示,菱形框内写明联系名,并用无向边分别与有关实体连接起来
- 1对1关系在两个实体连线方向写1;
- 1对多关系在1的一方写1,多的一方写N;
- 多对多关系则是在两个实体连线方向各写N,M
-
小滴课堂开发者论坛Mysql相关表录入
简介:小滴课堂开发者论坛数据库设计
-
cateogry分类表
CREATE TABLE `category` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(128) DEFAULT NULL, `weight` int(11) DEFAULT NULL, `create_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-
topic主题表
CREATE TABLE `topic` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `c_id` int(11) DEFAULT NULL COMMENT '分类', `title` varchar(128) DEFAULT NULL COMMENT '标题', `content` varchar(1024) DEFAULT NULL COMMENT '内容', `pv` int(11) DEFAULT NULL COMMENT '浏览量', `user_id` int(11) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `user_img` varchar(128) DEFAULT NULL, `create_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL, `hot` int(2) DEFAULT '0' COMMENT '是否热门 1是热门', `delete` int(11) DEFAULT '0' COMMENT '0是未删除,1是一件删除', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
-
reply回复表
CREATE TABLE `reply` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `topic_id` int(11) DEFAULT NULL, `floor` int(11) DEFAULT NULL COMMENT '楼层编号,回复是不能删除的', `content` varchar(524) DEFAULT NULL COMMENT '回复内容', `user_id` int(11) DEFAULT NULL, `username` varchar(64) DEFAULT NULL COMMENT '回复人名称', `user_img` varchar(128) DEFAULT NULL COMMENT '回复人头像', `create_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL, `delete` int(11) DEFAULT NULL COMMENT '0是正常,1是禁用', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
-
user用户表
CREATE TABLE `user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `phone` varchar(32) DEFAULT NULL, `pwd` varchar(128) DEFAULT NULL, `sex` int(2) DEFAULT NULL, `img` varchar(128) DEFAULT NULL, `create_time` datetime DEFAULT NULL, `role` int(11) DEFAULT NULL COMMENT '1是普通用户,2是管理员', `username` varchar(128) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
-
sql文件在我们这章这集的资料里面,可以直接导入
Maven3.x创建小滴课堂开发者论坛项目和配置tomcat9
简介:IDEA+Maven3.x创建Javaweb项目配置tocmat9
- 创建Maven3.x + Javaweb项目
- 提高创建速度,会在本地优先查找资源,本地找不到再去下载 Name:archetypeCatalog Value:internal
- 如何导入课程项目
小滴课堂开发者论坛Maven依赖包和基础实体类开发
简介: 小滴课堂开发者论坛相关依赖包和实体类开发
-
maven依赖包添加
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> </dependency> <!-- JSP --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils --> <dependency> <groupId>commons-dbutils</groupId> <artifactId>commons-dbutils</artifactId> <version>1.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.7.0</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.4</version> </dependency>
-
包结构创建
-
实体类开发
-
工具类开发
- 连接池开发
封装通用BaseServlet和分类列表接口开发
简介: 封装通用BaseServlet和分类列表接口开发
-
开发Controller
- 通用Servlet
-
开发Service
-
开发Dao层
-
使用PostMan测试
小滴课堂开发者论坛主题列表开发-支持分页
简介:主题列表接口开发和通用PageDTO开发
-
什么是分页接口
-
数据过多,一页显示不过来,就会分页请求;
-
核心:当前第几页、每页显示多少条、总条数
-
数据数据库查询使用
select * from table limit m,n m——是指记录的起始位置,从0开始,表示第一条记录。 n——是指从第m+1条开始,取n条。
select * from tablename limit 2,4 即取出第3条至第6条,4条记录
-
- PageDTO开发
- Servlet-Service-Dao层开发
小滴课堂开发者论坛之主题详情接口开发-支持分页
简介:小滴课堂开发者论坛主题详情页接口开发
- Servlet-Service-Dao层开发
小滴课堂开发者论坛之用户注册接口开发
简介:讲解小滴课堂开发者论坛之用户注册接口
-
Servlet-Service-Dao层开发
-
user表使用phone唯一索引
CREATE TABLE `user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `phone` varchar(32) DEFAULT NULL, `pwd` varchar(128) DEFAULT NULL, `sex` int(2) DEFAULT NULL COMMENT '0是女,1是男,2未知', `img` varchar(128) DEFAULT NULL, `create_time` datetime DEFAULT NULL, `role` int(11) DEFAULT NULL COMMENT '1是普通用户,2是管理员', `username` varchar(128) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `phone` (`phone`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-
MD5加密
public static String MD5(String data) { try { java.security.MessageDigest md = MessageDigest.getInstance("MD5"); byte[] array = md.digest(data.getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte item : array) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } return sb.toString().toUpperCase(); } catch (Exception exception) { } return null; }
-
POSTMan测试 x-www-form-urlencoded格式
就是application/x-www-from-urlencoded,会将表单内的数据转换为键值对,&分隔。 当form的action为get时,浏览器用x-www-form-urlencoded的编码方式,将表单数据编码为 (name1=value1&name2=value2…),然后把这个字符串append到url后面,用?分隔,跳转 到这个新的url。当form的action为post时,浏览器将form数据封装到http body中,然后发送到server
小滴课堂开发者论坛之用户登录和注销接口开发
简介:讲解小滴课堂开发者论坛之用户登录和注销接口
- Servlet-Service-Dao层开发
//controller层代码
public void login(HttpServletRequest request,HttpServletResponse response){
String phone = request.getParameter("phone");
String pwd = request.getParameter("pwd");
User user = userService.login(phone,pwd);
if(user != null){
request.getSession().setAttribute("loginUser",user);
//跳转页面
}else {
request.setAttribute("msg","用户名或者密码不正确");
}
}
//service层代码
@Override
public User login(String phone, String pwd) {
String md5pwd = CommonUtil.MD5(pwd);
User user = userDao.findByPhoneAndPwd(phone,md5pwd);
return user;
}
//dao层代码
public User findByPhoneAndPwd(String phone, String md5pwd) {
String sql = "select * from user where phone=? and pwd=?";
User user = null;
try{
user = queryRunner.query(sql,new BeanHandler<>(User.class,processor),phone,md5pwd);
}catch (Exception e){
e.printStackTrace();
}
return user;
}
小滴课堂开发者论坛之发布主题接口
简介:小滴课堂开发者论坛发布主题接口开发
- Servlet-Service-Dao层开发
//controller层代码
/**
* http://localhost:8080/topic?method=addTopic
* 发布主题
* @param request
* @param response
*/
public void addTopic(HttpServletRequest request,HttpServletResponse response){
User loginUser = (User)request.getSession().getAttribute("loginUser");
if(loginUser == null){
request.setAttribute("msg","请登录");
return;
//页面跳转 TODO
}
String title = request.getParameter("title");
String content = request.getParameter("content");
int cId = Integer.parseInt(request.getParameter("c_id"));
int rows = topicService.addTopic(loginUser,title,content,cId);
if(rows ==1){
//发布主题成功
}else {
//发布主题失败
}
}
//service层代码
@Override
public int addTopic(User loginUser, String title, String content, int cId) {
Category category = categoryDao.findById(cId);
if(category == null){ return 0;}
Topic topic = new Topic();
topic.setTitle(title);
topic.setContent(content);
topic.setCreateTime(new Date());
topic.setUpdateTime(new Date());
topic.setPv(1);
topic.setDelete(0);
topic.setUserId(loginUser.getId());
topic.setUsername(loginUser.getUsername());
topic.setUserImg(loginUser.getImg());
topic.setcId(cId);
topic.setHot(0);
int rows = 0;
try {
rows = topicDao.save(topic);
} catch (Exception e) {
e.printStackTrace();
}
return rows;
}
//dao层代码
public int save(Topic topic) throws Exception {
String sql = "insert into topic(c_id,title,content,pv,user_id,username,user_img,create_time,update_time,hot,`delete`) " +"values(?,?,?,?,?,?,?,?,?,?,?)";
Object [] params = {
topic.getcId(),
topic.getTitle(),
topic.getContent(),
topic.getPv(),
topic.getUserId(),
topic.getUsername(),
topic.getUserImg(),
topic.getCreateTime(),
topic.getUpdateTime(),
topic.getHot(),
topic.getDelete()
};
int i =0;
try{
i= queryRunner.update(sql,params);
}catch (Exception e){
e.printStackTrace();
throw new Exception();
}
return i;
}
小滴课堂开发者论坛之回复盖楼功能开发
简介:小滴课堂开发者论坛盖楼回复功能开发
- Servlet-Service-Dao层开发
//controller层代码
/**
* http://localhost:8080/topic?method=replyByTopicId&topic_id=9
* 盖楼回复
* @param request
* @param response
*/
public void replyByTopicId(HttpServletRequest request,HttpServletResponse response){
User loginUser = (User)request.getSession().getAttribute("loginUser");
if(loginUser == null){
request.setAttribute("msg","请登录");
return;
//页面跳转 TODO
}
int topicId = Integer.parseInt(request.getParameter("topic_id"));
String content = request.getParameter("content");
int rows = topicService.replyByTopicId(loginUser,topicId,content);
if(rows ==1){
//回复成功
}else {
//回复失败
}
}
//service层代码
@Override
public int replyByTopicId(User loginUser, int topicId, String content) {
int floor = topicDao.findLatestFloorByTopicId(topicId);
Reply reply = new Reply();
reply.setContent(content);
reply.setCreateTime(new Date());
reply.setUpdateTime(new Date());
reply.setFloor(floor+1);
reply.setTopicId(topicId);
reply.setUserId(loginUser.getId());
reply.setUsername(loginUser.getUsername());
reply.setUserImg(loginUser.getImg());
reply.setDelete(0);
int rows = replyDao.save(reply);
return rows;
}
//dao层代码
public int save(Reply reply) {
String sql = "insert into reply (topic_id,floor,content,user_id,username,user_img,create_time,update_time,`delete`)" +
"values (?,?,?,?,?,?,?,?,?)";
Object [] params = {
reply.getTopicId(),
reply.getFloor(),
reply.getContent(),
reply.getUserId(),
reply.getUsername(),
reply.getUserImg(),
reply.getCreateTime(),
reply.getUpdateTime(),
reply.getDelete()
};
int rows = 0;
try{
rows = queryRunner.update(sql,params);
}catch (Exception e){
e.printStackTrace();
}
return rows;
}
小滴课堂开发者论坛之topic阅读量递增
简介:小滴课堂开发者论坛阅读量递增
- 通过session和topic进行绑定,一个session访问同个topic只算一次阅读
//controller层代码
//处理浏览量,如果同个session内只算一次
String sessionReadKey = "is_read_"+topicId;
Boolean isRead = (Boolean) request.getSession().getAttribute(sessionReadKey);
if(isRead == null){
request.getSession().setAttribute(sessionReadKey,true);
//新增一个pv
topicService.addOnePV(topicId);
}
//service层代码
@Override
public void addOnePV(int topicId) {
Topic topic = topicDao.findById(topicId);
int newPV = topic.getPv()+1;
topicDao.updatePV(topicId,newPV,topic.getPv());
}
//dao层代码
/**
* 更新浏览量
*/
public int updatePV(int topicId, int newPV, int oldPV) {
String sql = "update topic set pv=? where pv=? and id=?";
int rows = 0;
try {
rows = queryRunner.update(sql,newPV,oldPV,topicId);
}catch (Exception e){
e.printStackTrace();
}
return rows;
}
小滴课堂开发者论坛前端页面相关资源准备
简介: 前端相关资源准备和文件创建
-
页面技术 bootstrap + jsp
- bootstrap 3.x地址:https://www.bootcss.com/
- 添加相关依赖js和css
- 页面基础
<meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap.min.css"> <script src="${pageContext.request.contextPath}/static/bootstrap.min.js"></script> <script src="${pageContext.request.contextPath}/static/jquery.min.js"></script>
-
pom文件添加依赖
<!-- https://mvnrepository.com/artifact/taglibs/standard --> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
-
jsp页面添加jstl表达式依赖包
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
修改web.xml版本
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
小滴课堂开发者论坛之主题列表页开发和联调《上》
简介:主题列表页开发和联调《上》
小滴课堂开发者论坛之主题列表页开发和联调《下》
简介:主题列表页开发和联调《下》
小滴课堂开发者论坛之主题详情页开发和联调
简介:主题详情页开发和联调
小滴课堂开发者论坛之注册页面开发和联调
简介:注册页面开发联调
小滴课堂开发者论坛之登录-退出页面开发和联调
简介:登录和退出页面开发联调
小滴课堂开发者论坛之发布主题页面开发和联调
简介:发布主题页开发和联调
小滴课堂开发者论坛之回复盖楼页面开发和联调
简介:回复盖楼页开发和联调
小滴课堂开发者论坛之首页自动跳转配置
简介:小滴课堂首页自动跳转配置
- home.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>小滴课堂开发者论坛</title>
</head>
<body>
<jsp:forward page="/topic?method=list&c_id=1"></jsp:forward>
</body>
</html>
- web.xml
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
小滴课堂开发者论坛项目部署外置tomcat和课程总结
简介:项目打包war部署外置tomcat和课程总结
- 项目打包mvn install
- 部署到外部的tomcat
- 项目总结
-
备注:
- javaweb开发小滴课堂论坛项目是练手的用来巩固基础
- 同学可以自己增加更多的功能,比如积分、绑定等,也可以做下安全控制,比如防止刷帖子、防止xss攻击等
干货文档
关注公众号发送:“CSDN干货文档” 即可领取