基于javaweb+jsp的个人日记管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap Ajax
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、日记模块的增删改查管理
}
@RequestMapping("authLogout")
public void logout(HttpServletResponse response, HttpServletRequest request) throws IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("loginUser");
if (user != null) {
session.removeAttribute("loginUser");
}
response.sendRedirect("login.jsp");
}
@RequestMapping("authValidationCode")
public void validationCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
// 获得验证码集合的长度
int charsLength = codeChars.length();
// 下面三条记录是关闭客户端浏览器的缓冲区
<div style="float: right;padding-right: 10px;color: #515151;"><jsp:include page="split.jsp"/></div>
</div>
</div>
</div>
<!-- add -->
<div class="modal fade" id="modal-add" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="noticeAdd" onsubmit="return addCheck()">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">增加公告</h4>
</div>
<div class="modal-body">
<div class="form-group hidden">
<label class="control-label">(hidden)</label>
<input type="text" class="form-control" name="action" value="add">
</div>
<div class="form-group">
<label for="add-noticeName" class="control-label">标题:</label>
<input type="text" class="form-control" name="noticeName" id="add-noticeName">
</div>
</div>
<div class="form-group">
<label for="add-diaryText" class="control-label">内容:</label>
<textarea style="height: 100px;" class="form-control" name="diaryText" id="add-diaryText"></textarea>
</div>
<div class="form-group">
<label for="add-diaryType" class="control-label">类别:</label>
<input type="text" class="form-control" name="diaryType" id="add-diaryType">
</div>
<div class="form-group">
<label for="add-diaryDate" class="control-label">时间:</label>
<input type="text" class="form-control" name="diaryDate" id="add-diaryDate">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-pill btn-line btn-warning" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-pill btn-line btn-primary">提交</button>
</div>
</form>
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = userService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = Util.decode(request, "pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
/**
* Diary模块的Service层(业务层)的具体实现类,对DiaryService接口中定义的抽象方法作出具体的功能实现
*/
@Service
public class DiaryServiceImpl implements DiaryService {
@Autowired
private DiaryMapper diaryMapper;
//@Override
public boolean insert(Diary vo) {
return this.diaryMapper.doCreate(vo) == 1;
}
//@Override
public boolean delete(Collection<Serializable> ids) {
return ids.isEmpty() ? false : this.diaryMapper.doRemoveBatch(ids) == ids.size();
}
//@Override
public boolean update(Diary vo) {
return this.diaryMapper.doUpdate(vo) == 1;
return true;
}
//编辑表单提交之前进行检查,如果return false,则不允许提交
function editCheck() {
//根据ID获取值
if (document.getElementById("edit-noticeName").value.trim().length == 0) {
alert("标题不能为空");
return false;
}
if (document.getElementById("edit-noticeType").value.trim().length == 0) {
alert("类型不能为空");
return false;
}
if (document.getElementById("edit-createDate").value.trim().length == 0) {
alert("创建时间不能为空");
return false;
}
return true;
}
</script>
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<!-- 配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!--数据库驱动 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<!--连接数据库的url -->
<property name="url" value="jdbc:mysql://localhost:3306/project_000000000000?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true"></property>
<!--连接数据库的用户名 -->
<property name="username" value="root"></property>
<!--连接数据库的密码 -->
<property name="password" value="123456"></property>
</bean>
<!-- 配置MyBatis工厂SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源 -->
<property name="dataSource" ref="dataSource"/>
<!--指定核MyBatis心配置文件位置 -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--xml文件的路径配置-->
<property name="mapperLocations">
<list>
<value>classpath:mapper/*.xml</value>
<button type="button" class="btn btn-pill btn-line btn-warning" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-pill btn-line btn-primary">提交</button>
</div>
</form>
</div>
</div>
</div>
<!-- info -->
<div class="modal fade" id="modal-info" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">公告</h4>
Map<String, Object> map = userService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = Util.decode(request, "pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) userService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("userList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
<if test ='diaryText != null'>`diary_text`,</if>
<if test ='diaryType != null'>`diary_type`,</if>
<if test ='diaryDate != null'>`diary_date`</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test ='id != null'>#{id},</if>
<if test ='diaryName != null'>#{diaryName},</if>
<if test ='diaryText != null'>#{diaryText},</if>
<if test ='diaryType != null'>#{diaryType},</if>
<if test ='diaryDate != null'>#{diaryDate}</if>
</trim>
</insert>
<!--批量删除-->
<delete id="doRemoveBatch" parameterType="java.util.Collection">
DELETE FROM `t_diary` WHERE `id` IN
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row">
<div class="col-sm-7">
<div class="input-group">
<input class="form-control" type="hidden" id="searchColumn" name="searchColumn" value="diary_name"/>
<input class="form-control" type="text" id="search_keyword" name="search_keyword" placeholder="标题"/> <span class="input-group-btn"><button class="btn btn-pill btn-line btn-default" type="button" onclick="searchList()">搜索</button></span>
</div>
</div>
<div class="col-sm-5">
<button type="button" <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"</c:if> class="btn btn-pill btn-line btn-primary" data-toggle="modal" data-target="#modal-add">添加日记
</button>
</div>
</div>
<br>
<br>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>标题</th>
$('#modal-edit').on('show.bs.modal', function (event) {
let button = $(event.relatedTarget);
let id = button.data('id');
let modal = $(this);
$.ajax({
url: 'diaryGet?id=' + id,
type: "get",
success: function (voString) {
let vo = eval('(' + voString + ')');
modal.find('#edit-id').val(vo.id);
modal.find('#edit-diaryName').val(vo.diaryName);
modal.find('#edit-diaryText').val(vo.diaryText);
modal.find('#edit-diaryType').val(vo.diaryType);
modal.find('#edit-diaryDate').val(vo.diaryDate);
}
})
})
</div>
</div>
<!-- edit -->
<div class="modal fade" id="modal-edit" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="userEdit" onsubmit="return editCheck()">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">更新用户</h4>
</div>
<div class="modal-body">
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}
package com.demo.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.text.SimpleDateFormat;
/**
@Autowired
private DiaryMapper diaryMapper;
//@Override
public boolean insert(Diary vo) {
return this.diaryMapper.doCreate(vo) == 1;
}
//@Override
public boolean delete(Collection<Serializable> ids) {
return ids.isEmpty() ? false : this.diaryMapper.doRemoveBatch(ids) == ids.size();
}
//@Override
public boolean update(Diary vo) {
return this.diaryMapper.doUpdate(vo) == 1;
}
<div class="form-group">
<label for="add-username" class="control-label">用户名:</label>
<input type="text" class="form-control" name="username" id="add-username">
</div>
<div class="form-group">
<label for="add-password" class="control-label">密码:</label>
<input type="text" class="form-control" name="password" id="add-password">
</div>
<div class="form-group">
<label for="add-realName" class="control-label">姓名:</label>
<input type="text" class="form-control" name="realName" id="add-realName">
</div>
<div class="form-group">
<label class="control-label">性别:</label>