7月20日 SSM 周五

<%@ 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">
    -->

  <link rel="stylesheet" href="<%=basePath%>/css/index_work.css" type="text/css"></link>
  </head>

  <body>
    <table>
        <tr>
            <th>userid</th>
            <th>username</th>
            <th>password</th>
            <th>usersex</th>
            <th>birthday</th>
            <th>usertel</th>
            <th>userlive</th>
            <th>rname</th>
            <th><input type="button" value="用户" onclick="location ='<%=basePath%>/view/add.jsp'"></th>
        </tr>
        <c:forEach items="${userList }" var="u">
            <tr>
                <th>${u.userid }</th>
                <th>${u.username }</th>
                <th>${u.password }</th>
                <th>${u.usersex }</th>
                <th>${u.birthday }</th>
                <th>${u.usertel }</th>
                <th>${u.userlive }</th>
                <th>${u.r.rname }</th>
                <th><input type="button" value="权限" onclick="location='<%=basePath%>/view/upd.jsp?id=${u.userid }&name=${u.username }&r=${u.r.rid}'"></th>
            </tr>
        </c:forEach>
    </table>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'upd.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">
    -->

  <link rel="stylesheet" href="<%=basePath%>/css/index_work.css" type="text/css"></link>
  <script type="text/javascript" src="<%=basePath%>/js/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        var id = "${param.id}";
        $(function (){
            $("select").val("${param.r}");
        });

        function sub(){
            var rid = $("[name='rid']").val();
            console.log("id为"+id+"rid为"+rid);
            $.post(
                "upd.do",
                {"userid":id,"r.rid":rid},
                function (data){
                    if(data==1){
                        alert("修改成功");
                        location = "<%=basePath%>/list.do";
                    }
                },"json"
            );
        }

    </script>
  </head>

  <body>
  <%-- id:"${param.id}"<br> --%>
    用户:${param.name}<br>

    权限:<select name="rid">
        <option value="1">管理员</option>
        <option value="2">会员</option>
        <option value="3">普通用户</option>
    </select><br>
    <input type="button" value="修改" onclick="sub()">
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'add.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">
    -->

  <link rel="stylesheet" href="<%=basePath%>/css/index_work.css" type="text/css"></link>
  <script type="text/javascript" src="<%=basePath%>/js/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        function sub(){
            $.post(
                "add.do",
                $("form").serialize(),
                function (data){
                    if(data==1){
                        alert("修改成功");
                        location = "<%=basePath%>/list.do";
                    }
                },"json"
            );
        }
    </script>
  </head>

  <body>
  <form>
  userid:<input type="hidden" name="userid"><br>
  username:<input type="text" name="username"><br>
  password:<input type="text" name="password"><br>
  usersex:<input type="radio" name="usersex" value="男"><input type="radio" name="usersex" value="女"><br>
  birthday:<input type="text" name="birthday"><br>
  usertel:<input type="text" name="usertel"><br>
  userlive:<input type="text" name="userlive"><br>
    权限:<select name="r.rid">
        <option value="1">管理员</option>
        <option value="2">会员</option>
        <option value="3">普通用户</option>
    </select><br>
    <input type="hidden" name="r.rname" value="1">
  </form>
    <input type="button" value="添加" onclick="sub()">
  </body>
</html>

package com.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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.dto.User;
import com.service.UserService;

@Controller
public class UserController {
@Autowired
private UserService userService;

@RequestMapping("list")
public String list(HttpServletRequest request){
    List<User> userList = userService.findUserList();
    System.out.println(userList);
    request.setAttribute("userList", userList);
    return "list";
}
@RequestMapping("upd")
@ResponseBody
public void upd(User user,HttpServletResponse response) throws IOException{
    System.out.println(user.getUserid());
    System.out.println(user.getR().getRid());
    int i = userService.upd(user);
    response.getWriter().print(i);
}
@RequestMapping("add")
public void add(HttpServletResponse response,User user) throws IOException{
    Integer rid = user.getR().getRid();
    System.out.println("add的User"+user);
    int i = userService.add(user);
    User u = null;
    Integer uid=null;
    if(i==1){
        u = userService.getObj(user);
        System.out.println("u的属性为"+u);
        uid = u.getUserid();
    }
    int a = userService.changeUr(uid,rid);
    response.getWriter().print(a);

}

}

<?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.mapper.UserMapper">
    <resultMap type="com.dto.User" id="userMap">
        <id property="userid" column="userid"/>
        <result property="username" column="username"/>
        <result property="password" column="password"/>
        <result property="usersex" column="usersex"/>
        <result property="birthday" column="birthday"/>
        <result property="usertel" column="usertel"/>
        <result property="userlive" column="userlive"/>
        <association property="r" resultMap="relationMap"></association>
    </resultMap>
    <resultMap type="com.dto.Relation" id="relationMap">
        <id property="rid" column="rid"/>
        <result property="rname" column="rname"/>
    </resultMap>

    <select id="findUserList" resultMap="userMap">
        select * from t_user u 
        left join u_r ur on u.userid = ur.uid
        left join t_relation r on ur.rid = r.rid
    </select>

    <update id="upd">
        update u_r set rid = ${r.rid} where uid = ${userid}
    </update>

    <insert id="add">
        insert into t_user set username=#{username},password=#{password},usersex=#{usersex},birthday=#{birthday},usertel=#{usertel},userlive=#{userlive}
    </insert>

    <select id="getObj" resultType="com.dto.User">
        select * from t_user where username=#{username}
    </select>

    <insert id="changeUr">
        insert into u_r set uid = ${uid},rid = ${rid}
    </insert>
</mapper>

There is nothing noble in being superior to some other man. The true nobility is in being superior to your previous self.
优于别人,并不高贵。真正的高贵应该是优于过去的自己。
投稿人没有留下姓名。这句话出自海明威《真实的高贵》。小编想说:昨日种种,皆成今我;今日种种,方成新我。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值