计算机系毕业设计福利1---后台管理系统为例实现SSM框架整合---3w6k字附带源码【完整版!!!】

一、SSM框架整合

spring+springMVC+Mybatis
spring整合mybatis 已经做过,
spring整合springMVC 可以无缝整合,本身就是一个体系,
springMVC是一个web框架,怎么把spring容器在web项目中创建,应该是在项目启动的时候创建容器,项目结束的时候关闭容器。
监听器是servlet中的一个组件,监听域对象的创建、销毁和绑定对象。
spring本身提供了一个监听context的监听器,在contxt启动的时候创建spring容器。
我们只需要在web.xml中配置监听器就可以了。

1、创建项目,导入依赖

<properties>
    <spring-version>5.1.5.RELEASE</spring-version>
    <jackson-versin>2.9.8</jackson-versin>
</properties>

<dependencies>
    <!--spring上下文管理-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring-version}</version>
    </dependency>
    <!--springAOP依赖-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring-version}</version>
    </dependency>
    <!--spring-jdbc依赖-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring-version}</version>
    </dependency>
    <!--织入依赖包-->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.9.6</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring-version}</version>
    </dependency>
    <!-- springWeb依赖-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring-version}</version>
    </dependency>
    <!--springMVC转化json依赖包-->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson-versin}</version>
    </dependency>
    <!--mysql连接-->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>
    <!--mybatis依赖-->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.3</version>
    </dependency>
    <!--mybati整合spring依赖-->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.3.2</version>
    </dependency>
</dependencies>

2、创建各种配置文件

1、springmvc的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd ">


    <!--扫描controller注释-->
    <context:component-scan base-package="com.csdn.controller"/>
    <!--配置自动加载驱动-->
    <mvc:annotation-driven/>
    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

spring的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ">

    <!--扫描springIOC的注释-->
    <context:component-scan base-package="com.csdn">
        <!--忽略controller注解-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
        <!--配置jdbc数据源-->
        <bean id="dataSourse" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql:127.0.0.1:3306"/>
            <property name="username" value="root"/>
            <property name="password" value="root"/>
        </bean>
</beans>

spring整合mybatis配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ">

    <!--sqlsessionfactory-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--引入数据源-->
        <property name="dataSource" ref="dataSource"/>
        <!--设置别名-->
        <property name="typeAliasesPackage" value="com.csdn.pojo"/>
    </bean>
    <!--配置扫描mapper文件-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.csdn.mapper"/>
    </bean>
</beans>

在spring配置文件中添加引入:
在这里插入图片描述
springs事务管理配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ">

    <!--配置事物管理平台-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <constructor-arg name="dataSource" ref="dataSourse"/>
    </bean>

    <!--配置事物的增强-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--根据方法 配置具体的属性-->
        <tx:attributes>
            <tx:method name="add*"/>
            <tx:method name="insert*"/>
            <tx:method name="del*"/>
            <tx:method name="drop*"/>
            <tx:method name="save*"/>
            <tx:method name="update*"/>
            <tx:method name="edit*"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="select*" read-only="true"/>
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!--使用aop将事物配置到项目中-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.csdn.service..*Impl.*(..))"/>
    </aop:config>
</beans>

将事务管理引入到spring核心配置:
在这里插入图片描述

修改web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!--监听器读取文件的设置-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <!--配置spring容器自动的监听器-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--配置springmvc的前端控制器-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!--解决post乱码的过滤器-->
    <filter>
        <filter-name>EncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>EncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

测试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、SSM框架整合案例完成

1、创建数据库

CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT,
nick_name varchar(255) DEFAULT NULL,
sex int(1) DEFAULT NULL,
age int(3) DEFAULT NULL,
birthday datetime DEFAULT NULL,
user_name varchar(255) DEFAULT NULL,
password varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

添加一条数据:
在这里插入图片描述

2、逆向工程生成

在这里插入图片描述

3、创建页面

导入web资源
在这里插入图片描述

因为资源是静态的,在springmvc核心配置文件中添加静态资源放行:
在这里插入图片描述
创建登陆页面:
${pageContext.request.contextPath} jsp中一个方法 获取当前项目的路径,一般用作配置绝对路径使用
替换图片修改为绝对路径:

${pageContext.request.contextPath}/images
在这里插入图片描述
修改登陆界面提交的name:因为逆向工程创建的pojo是userName
在这里插入图片描述

4、创建登陆的方法

创建controller层

package com.csdn.controller;

import com.csdn.pojo    .User;
import com.csdn.service.UserService;
import com.csdn.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String login(User user, HttpServletRequest request){
        //调用业务层实现登录的方法

        boolean bl = userService.findUserByUserNameAndPwd(user,request);
        //判断登陆结果实现页面跳转
        if(bl){
            //去首页
            return "main";
        }else {
            //去登录面
            return "forward:/login.jsp";
        }
    }
}

UserService:

package com.csdn.service;

import com.csdn.pojo.User;

import javax.servlet.http.HttpServletRequest;

public interface UserService {

     boolean findUserByUserNameAndPwd(User user, HttpServletRequest request);

  
}

UserServiceImpl

package com.csdn.service.impl;

import com.csdn.mapper.UserMapper;
import com.csdn.pojo.User;
import com.csdn.pojo.UserExample;
import com.csdn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    //用户登陆的方法
    @Override
    public boolean findUserByUserNameAndPwd(User user, HttpServletRequest request) {
        try {
            //登陆的方法 创建实例类
            UserExample ue = new UserExample();
            //创建条件类
            UserExample.Criteria criteria = ue.createCriteria();
            //添加条件
            criteria.andUserNameEqualTo(user.getUserName());
            //查询
            List<User> list = userMapper.selectByExample(ue);
            //判断是否有用户名
            if(!list.isEmpty()){
                //获取对应的用户数据
                User loginUser = list.get(0);
                //对比登陆密码是否正确
                if(loginUser.getPassword().equals(user.getPassword())){
                    //将用户数据存放到session中
                    request.getSession().setAttribute("login",loginUser);
                    //返回登录结果
                    return true;
                }else {
                    //密码错误
                    request.setAttribute("message","登录密码错误,请重新登录");
                    //回显用户名
                    request.setAttribute("userName",user.getUserName());
                }
                //没有用户名 提示
                request.setAttribute("message","用户名不存在,请练习管理员!!!");
            }
        }catch (Exception e){
            //登陆失败
            request.setAttribute("message","出现异常,登陆失败");
        }
        return false;

    }
    //用户登录的方法

}

5、修改登陆页面:

在这里插入图片描述
在这里插入图片描述
修改首页,在web.xml中添加
在这里插入图片描述

测试:
在这里插入图片描述
登陆失败
在这里插入图片描述
继续做以修改:
在userserviceimpl中修改:
在这里插入图片描述
测试:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

创建成功之后的首页
在这里插入图片描述

<%--
  Created by IntelliJ IDEA.
  User: 呼正
  Date: 2021/1/7
  Time: 下午 11:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>管理平台</title>
</head>
<frameset rows="89,*,24" cols="*" framespacing="0" frameborder="no" border="0">
    <frame src="${pageContext.request.contextPath}/user/forword/top" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" />
    <frameset cols="200,*">
        <frame src="${pageContext.request.contextPath}/user/forword/left" name="leftFrame" id="leftFrame" />
        <frame src="${pageContext.request.contextPath}/user/forword/center" name="mainFrame" id="mainFrame" />
    </frameset>

    <frame src="${pageContext.request.contextPath}/user/forword/down" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" />
</frameset>
<noframes><body>
</body>
</noframes></html>

测试成功:
在这里插入图片描述
为什么读取不到?因为页面在WEB-INF目录下 该目录下的资源是受保护的 不能直接访问的。
controller层跳转是可以访问WEB-INF页面的:
在controller层添加一个页面跳转的方法:
在这里插入图片描述
修改main页面:
在这里插入图片描述
查看结果
在这里插入图片描述

修改页面所有对应相对路径
修改top页面展示登陆名和时间:
在这里插入图片描述

7、完成用户展示功能

创建list.jsp
在这里插入图片描述

添加分页插件:
在这里插入图片描述
修改spring整合mybatis配置:
在这里插入图片描述

创建后台分页查询用户的方法

控制层:
在这里插入图片描述

业务层:
在这里插入图片描述
实现类:
在这里插入图片描述
修改left页面:
在这里插入图片描述

修改list页面,分页展示数据
导入标准标签库
在这里插入图片描述

遍历user数据展示
在这里插入图片描述
最终源码:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
        <!--
        body {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
        }
        .STYLE1 {font-size: 12px}
        .STYLE4 {
            font-size: 12px;
            color: #1F4A65;
            font-weight: bold;
        }

        a:link {
            font-size: 12px;
            color: #06482a;
            text-decoration: none;

        }
        a:visited {
            font-size: 12px;
            color: #06482a;
            text-decoration: none;
        }
        a:hover {
            font-size: 12px;
            color: #FF0000;
            text-decoration: underline;
        }
        a:active {
            font-size: 12px;
            color: #FF0000;
            text-decoration: none;
        }
        .STYLE7 {font-size: 12px}

        -->
    </style>

    <script>
        var  highlightcolor='#eafcd5';
        //此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
        var  clickcolor='#51b2f6';
        function  changeto(){
            source=event.srcElement;
            if  (source.tagName=="TR"||source.tagName=="TABLE")
                return;
            while(source.tagName!="TD")
                source=source.parentElement;
            source=source.parentElement;
            cs  =  source.children;
//alert(cs.length);
            if  (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor=highlightcolor;
                }
        }

        function  changeback(){
            if  (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
                return
            if  (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor="";
                }
        }

        function  clickto(){
            source=event.srcElement;
            if  (source.tagName=="TR"||source.tagName=="TABLE")
                return;
            while(source.tagName!="TD")
                source=source.parentElement;
            source=source.parentElement;
            cs  =  source.children;
//alert(cs.length);
            if  (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor=clickcolor;
                }
            else
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor="";
                }
        }
    </script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="15" height="30"><img src="${pageContext.request.contextPath}/images/tab_03.gif" width="15" height="30" /></td>
                <td width="1101" background="${pageContext.request.contextPath}/images/tab_05.gif"><img src="${pageContext.request.contextPath}/images/311.gif" width="16" height="16" /> <span class="STYLE4">人员列表</span></td>
                <td width="281" background="${pageContext.request.contextPath}/images/tab_05.gif"><table border="0" align="right" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="60"><table width="87%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="STYLE1"><div align="center">
                                    <input type="checkbox" name="checkbox62" value="checkbox" />
                                </div></td>
                                <td class="STYLE1"><div align="center">全选</div></td>
                            </tr>
                        </table></td>
                        <td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="STYLE1"><div align="center"><img src="${pageContext.request.contextPath}/images/001.gif" width="14" height="14" /></div></td>
                                <td class="STYLE1"><div align="center"><a href="add.html">新增</a></div></td>
                            </tr>
                        </table></td>
                        <td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="STYLE1"><div align="center"><img src="${pageContext.request.contextPath}/images/114.gif" width="14" height="14" /></div></td>
                                <td class="STYLE1"><div align="center">修改</div></td>
                            </tr>
                        </table></td>
                        <td width="52"><table width="88%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="STYLE1"><div align="center"><img src="${pageContext.request.contextPath}/images/083.gif" width="14" height="14" /></div></td>
                                <td class="STYLE1"><div align="center">删除</div></td>
                            </tr>
                        </table></td>
                    </tr>
                </table></td>
                <td width="14"><img src="${pageContext.request.contextPath}/images/tab_07.gif" width="14" height="30" /></td>
            </tr>
        </table></td>
    </tr>
    <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="9" background="${pageContext.request.contextPath}/images/tab_12.gif">&nbsp;</td>
                <td bgcolor="#f3ffe3"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98" onmouseover="changeto()"  onmouseout="changeback()">
                    <tr>
                        <td width="6%" height="26" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">选择</div></td>
                        <td width="8%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">序号</div></td>
                        <td width="24%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">姓名</div></td>
                        <td width="10%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">性别</div></td>
                        <td width="14%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2 STYLE1">年龄</div></td>
                        <%--<td width="24%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">出生日期</div></td>--%>
                        <td width="7%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">编辑</div></td>
                        <td width="7%" height="18" background="${pageContext.request.contextPath}/images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE2">删除</div></td>
                    </tr>

                    <!--数据-->
                    <c:forEach items="${pageInfo.list}" var="user" varStatus="vs" >
                        <tr>
                            <td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE1">
                                <input name="checkbox" type="checkbox" class="STYLE2" value="${user.id}" />
                            </div></td>
                            <td height="18" bgcolor="#FFFFFF" class="STYLE2"><div align="center" class="STYLE2 STYLE1">A00${user.id}</div></td>
                            <td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${user.nickName}</div></td>
                            <td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${user.sex eq 0 ? "女" : "男"}</div></td>
                            <td height="18" bgcolor="#FFFFFF"><div align="center" class="STYLE2 STYLE1">${user.age}</div></td>
                            <%--<td height="18" bgcolor="#FFFFFF"><div align="center" ><a href="#">
                                <fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"></fmt:formatDate>
                            </a></div></td>--%>
                            <td height="18" bgcolor="#FFFFFF">
                                <div align="center">
			      <span class="STYLE2">
			         <img src="${pageContext.request.contextPath}/images/037.gif" width="9" height="9" />
				  </span>
                                    <span class="STYLE1">[</span>
                                    <a href="${pageContext.request.contextPath}/user/toEdit?id=${user.id}&pageNum=${pageInfo.pageNum}">编辑</a>
                                    <span class="STYLE1">]</span>
                                </div>
                            </td>
                            <td height="18" bgcolor="#FFFFFF">
                                <div align="center">
				   <span class="STYLE2">
				     <img src="${pageContext.request.contextPath}/images/010.gif" width="9" height="9" />
				   </span>
                                    <span class="STYLE1">[</span>
                                    <a href="#${user.id}">删除</a>
                                    <span class="STYLE1">]</span>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>



                </table></td>
                <td width="9" background="${pageContext.request.contextPath}/images/tab_16.gif">&nbsp;</td>
            </tr>
        </table></td>
    </tr>
    <tr>
        <td height="29"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="15" height="29"><img src="${pageContext.request.contextPath}/images/tab_20.gif" width="15" height="29" /></td>
                <td background="${pageContext.request.contextPath}/images/tab_21.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="25%" height="29" nowrap="nowrap">
			<span class="STYLE1">
			     共${pageInfo.total}条纪录,当前第${pageInfo.pageNum}/${pageInfo.pages}页,每页${pageInfo.pageSize}条纪录
			</span></td>
                        <td width="75%" valign="top" class="STYLE1"><div align="right">
                            <table width="352" height="20" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td width="62" height="22" valign="middle">
                                        <div align="right">
                                            <c:if test="${!pageInfo.hasPreviousPage}">
                                                &lt;
                                            </c:if>
                                            <c:if test="${pageInfo.hasPreviousPage}">
                                                <a href="${pageContext.request.contextPath}/user/page?pageNum=1">&lt;</a>
                                            </c:if>
                                            <c:forEach begin="1" end="${pageInfo.pages}" step="1" var="item">
                                                <c:if test="${pageInfo.pageNum eq item}">
                                                    ${item}
                                                </c:if>
                                                <c:if test="${pageInfo.pageNum != item}">
                                                    <a href="${pageContext.request.contextPath}/user/page?pageNum=${item}">${item}</a>
                                                </c:if>
                                            </c:forEach>
                                            <c:if test="${!pageInfo.hasNextPage}">
                                                &gt;
                                            </c:if>
                                            <c:if test="${pageInfo.hasNextPage}">
                                                <a href="${pageContext.request.contextPath}/user/page?pageNum=${pageInfo.pages}">&gt;</a>
                                            </c:if>
                                        </div></td>

                                </tr>
                            </table>
                        </div></td>
                    </tr>
                </table></td>
                <td width="14"><img src="${pageContext.request.contextPath}/images/tab_22.gif" width="14" height="29" /></td>
            </tr>
        </table></td>
    </tr>
</table>
</body>
</html>



添加分页数据
在这里插入图片描述
查看:
在这里插入图片描述

8、完成修改功能

控制层添加方法
在这里插入图片描述
在这里插入图片描述
添加业务层的方法:
在这里插入图片描述
找到user对象然后再实现修改
控制层添加方法
在这里插入图片描述
在这里插入图片描述
添加业务层的方法:
在这里插入图片描述
添加edit页面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
        <!--
        body {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
        }
        .STYLE1 {font-size: 12px}
        .STYLE4 {
            font-size: 12px;
            color: #1F4A65;
            font-weight: bold;
        }

        a:link {
            font-size: 12px;
            color: #06482a;
            text-decoration: none;

        }
        a:visited {
            font-size: 12px;
            color: #06482a;
            text-decoration: none;
        }
        a:hover {
            font-size: 12px;
            color: #FF0000;
            text-decoration: underline;
        }
        a:active {
            font-size: 12px;
            color: #FF0000;
            text-decoration: none;
        }
        .STYLE7 {font-size: 12px}

        -->
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/My97DatePicker/WdatePicker.js"></script>
    <script>
        var  highlightcolor='#eafcd5';
        //此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
        var  clickcolor='#51b2f6';
        function  changeto(){
            source=event.srcElement;
            if  (source.tagName=="TR"||source.tagName=="TABLE")
                return;
            while(source.tagName!="TD")
                source=source.parentElement;
            source=source.parentElement;
            cs  =  source.children;
//alert(cs.length);
            if  (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor=highlightcolor;
                }
        }

        function  changeback(){
            if  (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
                return
            if  (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor="";
                }
        }

        function  clickto(){
            source=event.srcElement;
            if  (source.tagName=="TR"||source.tagName=="TABLE")
                return;
            while(source.tagName!="TD")
                source=source.parentElement;
            source=source.parentElement;
            cs  =  source.children;
//alert(cs.length);
            if  (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor=clickcolor;
                }
            else
                for(i=0;i<cs.length;i++){
                    cs[i].style.backgroundColor="";
                }
        }
    </script>

</head>

<body>
<table width="100%" border="0"  bgcolor="#E7FAD0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="15" height="30"><img src="${pageContext.request.contextPath}/imagestab_03.gif" width="15" height="30" /></td>
                <td width="1101" background="${pageContext.request.contextPath}/imagestab_05.gif"><img src="${pageContext.request.contextPath}/images311.gif" width="16" height="16" /> <span class="STYLE4">添加人员</span></td>
                <td width="281" background="${pageContext.request.contextPath}/imagestab_05.gif"><table border="0" align="right" cellpadding="0" cellspacing="0">

                </table></td>
                <td width="14"><img src="${pageContext.request.contextPath}/imagestab_07.gif" width="14" height="30" /></td>
            </tr>
        </table></td>
    </tr>
    <tr>
        <td>
            <form action="${pageContext.request.contextPath}/user/edit" method="post">
                <input type="hidden" name="id" value="${user.id}">
                <input type="hidden" name="pageNum" value="${pageNum}">
                <table align="center">
                    <tr>
                        <td align="right">姓名:</td>
                        <td><input type="text" name="nickName" value="${user.nickName}"/></td>
                    </tr>
                    <tr>
                        <td align="right">性别:</td>
                        <td>
                            <input type="radio" name="sex" value="1" ${user.sex eq 1 ? "checked":""}/><input type="radio" name="sex" value="0" ${user.sex eq 0 ? "checked":""}/></td>
                    </tr>
                    <tr>
                        <td align="right">登陆名:</td>
                        <td>
                            <input type="text" name="userName" value="${user.userName}">
                        </td>
                    </tr>
                    <tr>
                        <td align="right">密码:</td>
                        <td>
                            <input type="text" name="password" value="${user.password}">
                        </td>
                    </tr>
                    <tr>
                        <td align="right">年龄:</td>
                        <td><input type="text" name="age" value="${user.age}"/></td>
                    </tr>
                   <%-- <tr>
                        <td align="right">出生日期:</td>
                        <td>
                            <input type="text" name="birthday" id="birthday"
                                   value="<fmt:formatDate value="${user.birthday}" pattern='yyyy-MM-dd' />"
                                   onfocus="WdatePicker({el:'birthday'})" readonly="readonly"/>

                    </tr>--%>
                    <tr>
                        <td colspan="2" align="center"><input type="submit" value="修改"/></td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>
</body>
</html>

修改:
在这里插入图片描述
修改list页面,编辑的a标签:
在这里插入图片描述
测试
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这里我的pojo因为逆向工程忘了将birthday加入,故页面没有展示,如果展示会报错500;在这里修改的时候如果有birthday日期类型格式会报错400

为什么会报错呢?
因为时间转化异常:将之前的时间转化器添加进来:
在这里插入图片描述

package com.csdn.utils;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyDateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String source) {
        //预留规则
        String param = "";
        //判断是-   \
        if (source.indexOf("-") > 0){
            //判断长度
            if(source.length() > 10){
                param = "yyyy-MM-dd HH:mm:ss";
            }else{
                param = "yyyy-MM-dd";
            }
        }else if(source.indexOf("\\") > 0){
            //判断长度
            if(source.length() > 10){
                param = "yyyy\\MM\\dd HH:mm:ss";
            }else{
                param = "yyyy\\MM\\dd";
            }
        }
        //创建时间格式化类
        SimpleDateFormat sdf = new SimpleDateFormat(param);
        //转化时间
        try {
           return sdf.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
            return new Date();
        }

    }
}

修改springmvc的配置文件:
在这里插入图片描述
重启项目解决~

9、添加拦截器

问题:如果没有登陆通过url一样使用项目功能;
添加登陆拦截器,实现对应操作:
在这里插入图片描述
在psringMVC核心配置文件中添加:

在这里插入图片描述
测试:
在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿福真的不想掉头发

大爷?赏点?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值