四、后台管理
1.VideoInfoMapper.xml
<select id="selectAll" parameterType="com.itmayiedu.entity.VideoInfo"
resultType="com.itmayiedu.entity.VideoInfo">
select a.id as id,a.video_name as videoName, a.video_html as videoHtml ,a.video_url as videoUrl, a.video_del as videoDel
, b.type_name as typeName
from video_info as a inner join video_type as b on a.video_type_id=b.id;
</select>
2.videoInfoMapper.java
3.videoInfoServiceImpl.java
4.VideoInfoController.java
**5.IndexVideoInfo.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理系统</title>
</head>
<body>
<center>
<h1>蚂蚁视频后台管理系统</h1>
<a href="locaAddVideo">添加资源</a>
<table style="BORDER-COLLAPSE: collapse; text-align: center;"
borderColor=#000000 height=40 cellPadding=1 width="70%"
align="center" border=1>
<thead>
<tr>
<th>图片</th>
<th>视频名称</th>
<th>视频类型</th>
<th>预览视频</th>
</tr>
</thead>
<tbody>
<c:forEach items="${listVideoInfo}" var="p">
<tr style="font-size: 18px">
<td><img alt="" width="150px;" height="150px;"
src="static/imgs/${p.videoUrl}"></td>
<td>${p.videoName}</td>
<td>${p.typeName}</td>
<td><a href="videoDetails?id=${p.id}" style='text-decoration:none;'>预览视频</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</center>
</body>
</html>
注意要点:该jsp文件里面有url要被springmvc拦截,要修改springmvc.xml放行指定路径
要在springmvc.xml里面加上
最后访问成功
PageHelper分页管理
mybatis提供的一个插件工具
首先新建一个mybatis-config.xml文件,然后放在spring文件夹下:
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>
然后要在application-dao.xml中引入:注入到sqlSessionFactory里面
然后要把VideoInfoMapper.xml里面的select sql语句后面的逗号去掉
然后在controller里面引入:
PageHelper公式如下: PageHelper.startPage(1, 2):参数1:当前页码
起始位置:(当前页码-1)*长度
查询几条记录:由第二个参数决定(第2个参数是每页记录数的意思)
分页功能扩展
在IndexVideoInfo.jsp页面取得总页数,然后显示页码链接
最终得到的效果
Springmvc文件上传
前提:要在springmvc.xml里面添加如下
1.VideoInfoController.java
2.addVideo.jsp
提交页面到VideoInfoController里面的addVideo这个handler里面
解释:springMvc有自动匹配赋值功能,从jsp页面提交给controller,根据jsp里面元素的name属性自动匹配封装进videoInfo对象里面,name为file的那个input,也自动封装到MultipartFile file里面
1.VideoInfoServiceImpl.java
最终效果: