版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/helloworld_1996/article/details/82779905
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'list.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table>
<tr>
<th>id</th>
<th>name</th>
<th>sex</th>
<th>age</th>
<th>操作
<c:if test="${id!=1}">
<c:if test="${id!=2}">
|<input type="button" value="导出">
</c:if>
</c:if>
</th>
</tr>
<c:forEach items="${sList}" var="s">
<tr>
<th>${s.ID}</th>
<th>${s.STUNAME}</th>
<th>${s.STUSEX}</th>
<th>${s.STUAGE}</th>
<th>
<c:if test="${id==1}">
<input type="button" value="修改">
</c:if>
<c:if test="${id==2}">
<input type="button" value="删除">
</c:if>
</th>
</tr>
</c:forEach>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hao.mapper.IUserMapper">
<select id="login" parameterType="com.hao.dto.User" resultType="com.hao.dto.User">
select * from t_user0918 where userid = #{userid} and userpwd = #{userpwd}
</select>
<select id="getTree" parameterType="int" resultType="com.hao.dto.Ztree">
select z.id,z.pid,z.name,z.url,z.target from t_user0918 u
left join t_ur0918 ur on u.id = ur.userid
left join t_role0918 r on ur.rid = r.rid
left join t_rz0918 rz on r.rid = rz.rid
left join t_ztree0918 z on rz.zid = z.id
where u.id = #{id}
</select>
</mapper>
package com.hao.controller;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hao.dto.User;
import com.hao.service.IUserService;
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private IUserService iUserService;
@RequestMapping("login")
public String login(User user,HttpServletRequest request){
HttpSession session = request.getSession();
System.out.println(user);
User u = iUserService.login(user);
System.out.println(u);
if(u!=null){
System.out.println("登录成功");
session.setAttribute("u", u);
session.setAttribute("uid", u.getId());
return "main";
}else{
System.out.println("登录失败");
return "loginfail";
}
}
@RequestMapping("getTree")
@ResponseBody
public List<com.hao.dto.Ztree> getTree(Integer id){
List<com.hao.dto.Ztree> tList = iUserService.getTree(id);
System.out.println(tList);
return tList;
}
@RequestMapping("toLog")
public String toLog(HttpServletRequest request){
HttpSession session = request.getSession();
session.invalidate();
return "loguser";
}
@RequestMapping("top")
public String top(){
return "top";
}
@RequestMapping("left")
public String left(){
return "left";
}
@RequestMapping("right")
public String right(){
return "right";
}
@RequestMapping("chars")
public String chars(){
return "chars";
}
}
package com.hao.controller;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.hao.service.ITableService;
@Controller
@RequestMapping("table")
public class TableController {
@Autowired
private ITableService iTableService;
@RequestMapping("list")
public String list(HttpServletRequest request,Integer id){
System.out.println(id);
List<Map<String, Object>> sList = iTableService.findStuList();
request.setAttribute("id", id);
request.setAttribute("sList", sList);
return "list";
}
@RequestMapping("toAdd")
public String toAdd(){
return "add";
}
}
“天下的事 并不是你所求 就能所得”
《如懿传》