实验课听课列表
- 结合course表、user表、courseanduser表查询所有课程
HTML页面代码<li th:style="'display:' + @{(${session.user.state==0} ? 'block' : 'none')} + ''"> <a href="javascript:;"> <i class="iconfont"></i> <cite>听课管理</cite> <i class="iconfont nav_right"></i> </a> <ul class="sub-menu"> <li> <a th:_href="@{/course/SelectKecheng}"> <i class="iconfont"></i> <cite>实验课听课列表</cite> </a> </li > <li> <a th:_href="@{/course/SelectKecheng_two}"> <i class="iconfont"></i> <cite>理论课听课列表</cite> </a> </li > </ul> </li>
对应的courseController代码
@RequestMapping("SelectKecheng")
public String SelectKecheng(Model model,Course course, Integer pageNum, Integer pageSize) {
if (pageNum==null || pageNum==0) {
//当前页
pageNum=1;
}
if (pageSize==null) {
//每页的数量
pageSize=4;
}
PageInfo<Course> page= courseService.queryByPage(course, pageNum, pageSize);
model.addAttribute("page",page);
return "admin-rule";
}
对应的courseServiceImpl.java代码
@Override
public PageInfo<Course> queryByPage(Course course, Integer pageNum, Integer pageSize) {
//获取当前页pageNum,pageSize条内容,开始分页
// 第一行是设置页数和每页显示几条,插件会自动对接下来的sql语句加上分页方式。
Page<Course> page=PageHelper.startPage(pageNum, pageSize,true);
System.out.println("course.getName"+course.getName());
//查询所有数据
courseMapper.SelectKecheng(course.getName());
//PageInfo中是分页的一些信息,包括总页数,当前页,总数据等。
return page.toPageInfo();
}
对应的courseMapper.java代码
List<Course> SelectKecheng(@Param("name") String name);
对应的courseMapper.xml代码
<select id="SelectKecheng" resultMap="ResultMap">
SELECT c.*,u.id AS uid,u.name AS uname,u.classes AS uclasses,u.sorce AS usorce,u.lsorce AS ulsorce FROM `course` AS c
JOIN `courseanduser` AS cu
ON c.id=cu.cid
JOIN `user` AS u
ON cu.uid=u.id
<where>
<if test="name!=null and name!=''">
c.name like concat ('%',#{name},'%')
</if>
and u.state=2
ORDER BY u.sorce DESC
</where>
</select>
将查询数据渲染到页面上
<div class="x-body">
<div class="layui-row">
<form class="layui-form layui-col-md12 x-so"
th:action="@{/course/SelectKecheng}" method="post">
<input type="text" name="name" placeholder="请输入课程名称"
autocomplete="off" class="layui-input">
<button class="layui-btn" lay-submit="" lay-filter="sreach">
<i class="layui-icon"></i>
</button>
</form>
</div>
<table class="layui-table">
<thead>
<tr>
<th>课程ID</th>
<th>课程名字</th>
<th>课程内容</th>
<th>该课程老师</th>
<th>班级</th>
<th>总分</th>
<th>操作</th>
</thead>
<tbody>
<tr class="r" th:each="item : ${page.list}">
<td th:text="${item.id}">1</td>
<td th:text="${item.name}">admin/user/userlist</td>
<td th:text="${item.context}">admin/user/userlist</td>
<td th:text="${item.user.name}">admin/user/userlist</td>
<td th:text="${item.user.classes}">会员列表</td>
<td class="z" th:text="${item.user.sorce}" th:id="${item.user.id}" ></td>
<td class="td-manage">
<a style="color: yellowgreen;" title="查看听课老师" th:onclick="openModak(this,[[${item.id}]])"
href="javascript:;"> <i class="layui-icon"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div class="page">
<div>
<a class="prev" th:href="@{/course/SelectKecheng?(pageNum=${page.prePage})}">上一页</a>
<a class="next" th:href="@{/course/SelectKecheng?(pageNum=${page.nextPage})}">下一页</a>
</div>
</div>
</div>
- 查看听课老师
HTML页面代码
<td class="td-manage">
<a style="color: yellowgreen;" title="查看听课老师" th:onclick="openModak(this,[[${item.id}]])"
href="javascript:;"> <i class="layui-icon"></i> </a>
</td>
var socre = 0;
function openModak(obj,id) {
var url=[[@{/user/SelectTingKeLaoShi}]];
$.ajax({
url:url,
type:"post",
dataType:"json",
data:{
id:id
},
success:function(result){
$(".tbody").html("");
$.each(result,function(i,obj){
var b=("<tr>"+
"<td>"+obj.name+"</td>"+
"<td>"+obj.classes+"</td>"+
"<td>"+obj.ex.time+"</td>"+
"<td>"+obj.ex.topic+"</td>"+
"<td>"+obj.ex.address+"</td>"+
"<td>"+obj.ex.evaluate+"</td>"+
"<td>"+obj.ex.comment+"</td>"+
"<td class='f'>"+obj.ex.score+"</td>"+
"</tr>");
socre += obj.ex.score;
$(".tbody").append(b);
});
var uid=$(".z").attr("id");
var url=[[@{/user/XiuGaiZongFen}]];
$.ajax({
url:url,
type:"post",
data:{
sorce:socre,
id:uid
},
success:function(result){
}
});
form.render();
}
});
layui.use([ 'layer' ], function() {
var layer = layui.layer, $ = layui.$;
layer.open({
type : 1,//类型
area : [ '900px', '500px' ],//定义宽和高
title : '查看听课老师',//题目
shadeClose : false,//点击遮罩层关闭
content : $('#motaikunag')
//打开的内容
});
})
}
userController.java
@RequestMapping("SelectTingKeLaoShi")
@ResponseBody
public List<User> SelectTingKeLaoShi(String id) {
List<User> list = userService.SelectTingKeLaoShi(id);
System.out.println(JSON.toJSONString(list));
return list;
}
userServiceImpl.java
@Override
public List<User> SelectTingKeLaoShi(String id) {
return userMapper.SelectTingKeLaoShi(id);
}
userMapper.java
List<User> SelectTingKeLaoShi(@Param("id") String id);
userMapper.xml
<select id="SelectTingKeLaoShi" resultMap="ResultMap_two">
SELECT u.*,e.topic AS
etopic,e.time AS etime, e.address AS eaddress,e.evaluate AS
eevaluate,e.comment AS ecomment,e.score AS escore FROM `user` AS u
JOIN `experiment` AS e
ON u.id=e.uid
JOIN course AS c
ON e.courseid=c.id
WHERE c.id=#{id}
</select>
将数据渲染到页面上
<div id="motaikunag" style="display: none;">
<table style="margin-top: 0%" class="layui-table main" width="100%" border="0" cellspacing="0" cellpadding="0" >
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th>听课老师</th>
<th>该老师班级</th>
<th>听课时间</th>
<th>课题</th>
<th>地址</th>
<th>评价</th>
<th>评论</th>
<th>分数</th>
</tr>
</thead>
<tbody class="tbody">
</tbody>
</table>
</div>