ssm project integration, simple user management system

Project Overview

Roughly pass the basic knowledge of ssm, then let's do a small project of ssm integration, practice your hands!
Because it is a process of practicing integration, the business is the basic CRUD.
A user management system, administrators can add, delete, modify and check user accounts (you heard it right, it's that simple!!!!)

Project build

create project

1. Create a maven project

Open the idea, select file–>new–>project in the upper left corner, select maven, then click next to
insert image description here
set your own project name and groupid, and then finish.
insert image description here

2. Import project dependencies and maven resource filtering settings

Import the dependencies we need and maven's static resource filtering in pom.xml:

	<dependencies>
        <!--Junit-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>
        <!--数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.30</version>
        </dependency>
        <!-- 数据库连接池 -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.5</version>
        </dependency>
        <!--Servlet - JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!--Mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.11</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!--Spring-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.1.9.RELEASE</version>
        </dependency>
          <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <!--maven静态资源过滤-->
	<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
	</build>

After importing, remember to update the dependent packages

3. Add web support

Click on the project folder, then right click and select add framework support to add web support
insert image description here

4. Configure tomcat

In the upper right corner of the idea:
insert image description here
click edit configurations and configure tomcat
insert image description here
, then the following interface will pop up, click the plus sign, and find local tomcat
insert image description here
Here I use tomcat9, and then the port number and tomcat name can be modified by yourself
insert image description here
Select deployment, add artfacts
insert image description here

5. Configure web publishing to depend on jar packages

Click file in the upper left corner, then select project structure, select artifacts after the pop-up window, then find the artifacts of your current project, create a new lib folder under its root directory, then right-click and select add of...library files to put all the dependencies in the project Enter the lib folder, then ok
insert image description here

6. Database table creation

insert image description here
Initial data added:
insert image description here

7. Entity class creation

Create a new package com/gothic/sunset/pojo and create a new User.java entity class

package com.gothic.sunset.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor  //有参构造
@NoArgsConstructor  //无参构造
public class User {
    
    

    private int id;  //id号
    private String userName;//用户名
    private String password;//密码
}

Here I use lombok to automatically inject, avoiding handwritten construction with parameters and no parameters and the corresponding getters and setters...

  		<!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
            <scope>provided</scope>
        </dependency>

7.1 Common annotations for lombok:

@Data: This annotation is defined on JavaBean, which generates getter(), setter(), parameterless constructor, tostring(), hashcode(), equals() for JavaBean

@NoArgsConstructor: Produces a parameterless constructor

@Getter: Generate getter()

@Setter: generate setter()

@ToString: produces toString()

@RequiredArgsConstructor + @NonNull: Can be used to define parameterized constructors

@AllArgsConstructor: Generates a parameterized construction with all attributes

dao layer

1. Create daoMapper interface

Create a new UserMapper.java interface under com/gothic/sunset/dao

package com.gothic.sunset.dao;

import com.gothic.sunset.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


public interface UserMapper {
    
    

    //添加用户
    public int addUser(User user);

    //删除用户  根据id
    public int delUser(@Param("id") int id);

    //更新用户信息  根据id
    public int updateUser(User user);

    //查询单个用户 根据id查
    public User findUserById(@Param("id") int id);

    //查询所有用户信息
    public List<User> selectAllUser();

    //根据用户名查询用户
    public List<User> findUserByName(@Param("userName") String userName);
}

2. Mapper.xml configuration file

In the resources directory, create a new com/gothic/sunset/dao directory, and then create a new UserMapper.xml mapping file under this package

<?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">
<!--namespace用来绑定mapper接口-->
<mapper namespace="com.gothic.sunset.dao.UserMapper">


    <!-- public int addUser(User user);-->
    <insert id="addUser" parameterType="User">
        insert into
            (id,userName,password)
            values(#{userName},#{password})
    </insert>


    <!--public int delUser(@Param("id") int id);-->
    <delete id="delUser" parameterType="int">
        delete from user where id = #{id}
    </delete>

    <!--public int updateUser(User user,@Param("id") int id);-->
    <update id="updateUser" parameterType="User">
        update user
        set userName = #{userName},
            password =#{password}
        where id =#{id}
    </update>

    <!--public User findUserById(@Param("id") int id);-->
    <select id="findUserById" resultType="User">
        select id,userName,password from user where id = #{id}
    </select>

    <!--public List<User> selectAllUser();-->
    <select id="selectAllUser" resultType="User">
        select
               id,userName,password
        from user
    </select>
	
	<!--public List<User> findUserByName(@Param("userName") String userName);-->
    <select id="findUserByName" resultType="User">
        select
            id,userName,password
        from user
        where userName = #{userName}
    </select>
</mapper>

3.mybatis-config.xml core configuration file

In the resources directory, create a new mybatis-config.xml file

<?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>

    <settings>
        <!--将下划线映射为驼峰-->
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>


    <!--设定实体类别名-->
    <typeAliases>
        <package name="com.gothic.sunset.pojo"/>
    </typeAliases>

    <!--引入映射文件-->
    <mappers>
        <package name="com/gothic/sunset/dao/UserMapper.xml"/>
    </mappers>
</configuration>

4. Database connection configuration file

In the resources directory, create a new jdbc.properties file to store the database connection username and password verification...

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=UTF-8
jdbc.username=root
jdbc.password=root

5. spring-dao.xml configuration file

In the resources directory, create a new spring-dao.xml configuration file

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


    <!--配置数据源-->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!--cp30连接池   自动化操作(自动的加载配置文件 并且设置到对象里面)-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <!--sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据库连接池   注意数据库连接池是引用,别写成value-->
        <property name="dataSource" ref="dataSource"/>
        <!--绑定核心配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>

    <!-- 配置扫描Dao接口包,动态实现Dao接口注入到spring容器中 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <!-- 给出需要扫描Dao接口包 -->
        <property name="basePackage" value="com.gothic.sunset.dao"/>
    </bean>
</beans>

Here, if sqlSessionFactory is injected into the database connection pool and written as value="dataSource", an exception will occur
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'.

service layer

1. service interface creation

Create a new package com/gothic/sunset/service Create a new UserService.java interface in this package

package com.gothic.sunset.service;

import com.gothic.sunset.pojo.User;


import java.util.List;

public interface UserService {
    
    

    //添加用户
    public int addUser(User user);

    //删除用户  根据id
    public int delUser( int id);

    //更新用户信息  根据id
    public int updateUser(User user);

    //查询单个用户 根据id查
    public User findUserById(int id);

    //查询所有用户信息
    public List<User> selectAllUser();

    //根据用户名查询用户
    public List<User> findUserByName( String userName);
}


2. Service interface implementation class creation

In the same directory as the UserService.java interface, create a new UserServiceImpl.java interface implementation class

package com.gothic.sunset.service;

import com.gothic.sunset.dao.UserMapper;
import com.gothic.sunset.pojo.User;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public class UserServiceImpl implements UserService{
    
    

    private UserMapper userMapper;

    public void setUserMapper(UserMapper userMapper) {
    
    
        this.userMapper = userMapper;
    }

    @Override
    public int addUser(User user) {
    
    
        return userMapper.addUser(user);
    }

    @Override
    public int delUser(int id) {
    
    
        return userMapper.delUser(id);
    }

    @Override
    public int updateUser(User user) {
    
    
        return userMapper.updateUser(user);
    }

    @Override
    public User findUserById(int id) {
    
    
        return userMapper.findUserById(id);
    }

    @Override
    public List<User> selectAllUser() {
    
    
        return userMapper.selectAllUser();
    }

    @Override
    public List<User> findUserByName(String userName) {
    
    
        return userMapper.findUserByName(userName);
    }
}


What needs to be explained here is that you can use the automatic assembly bean combined with the annotation @AutuWired to do it. Here I (just recalled the integration) first use the manual settter injection method.

3. spring-service.xml configuration file

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

    <!--
        service层 最主要的是 事务管理
    -->

    <!--service层扫描包,将类交由ioc容器来管理-->
    <context:component-scan base-package="com.gothic.sunset.service"/>

    <!--因为这里我们是使用xml配置bean的方式,所以需要手动将bean注入-->
    <bean id="userServiceImpl" class="com.gothic.sunset.service.UserServiceImpl">
        <!--因为这里,我们service层使用了dao层的类。所以需要将dao层的类单独注入-->
        <property name="userMapper" ref="userMapper"/>
    </bean>

    <!--配置事务管理器-->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--注入数据库连接池-->
        <property name="dataSource" ref="dataSource"/>
    </bean>


</beans>

Then here, the transaction cross-cuts aop. This small example has not been used yet, so... there is no configuration, and the dependency package aspectj is not imported.

controller layer

controller class

Under the com/gothic/sunset/controller package, create a new UserController.java class

package com.gothic.sunset.controller;

import com.gothic.sunset.pojo.User;
import com.gothic.sunset.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/user")
public class UserController {
    
    

    // controller层调用service层,service层调用dao层 mvc架构,我就不多说了
   //@Qualifier注解 别名

    @Autowired
    @Qualifier("userServiceImpl")
    private UserService userService;



    @RequestMapping("/allUser")
    public String  selectAllUser(Model model){
    
    
        //使用业务层调用dao层查询出数据,通过model对象渲染到前台页面
        List<User> userList = userService.selectAllUser();
        model.addAttribute(userList);
        return "allUser";
    }


    //添加书籍,首先需要跳转到添加用户的表单页面
    @RequestMapping("/toAddUser")
    public String toAddUser(){
    
    
        //接收到前端请求后,跳到添加用户表单页面
        return "addUser";
    }

    //接收添加用户表单的数据,进行正式的添加用户,添加完成后,重定向到所有用户页面
    @RequestMapping("addUser")
    public String addUser(User user){
    
    
        userService.addUser(user);
        System.out.println(user.toString());
        return "redirect:/user/allUser";
    }

    //更新用户,与添加用户流程基本一样
    @RequestMapping("toUpdateUser")
    public String toUpdateUser(Model model,int id){
    
    
        User user = userService.findUserById(id);
        model.addAttribute("user",user);
        //跳转到用户修改页面,同时将要修改的用户的信息传递过去
        return "updateUser";
    }

    //正式更新用户
    @RequestMapping("updateUser")
    public String updateUser(User user){
    
    
        System.out.println(user.toString());
        userService.updateUser(user);
        System.out.println(user.getId());
        return "redirect:/user/allUser";
    }


    //删除就直接删除用户即可
    @RequestMapping("delUser")
    public String delUser(int id){
    
    
        userService.delUser(id);
        return "redirect:/user/allUser";
    }


    //查询用户 根据用户名查询
    @RequestMapping("/queryUser")
    public  String queryUser(String userName,Model model){
    
    
        List<User> userList = userService.findUserByName(userName);
        model.addAttribute(userList);
        return "allUser";
    }
}

spring-mvc.xml configuration file

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

    <!--controller层扫描包-->
    <context:component-scan base-package="com.gothic.sunset.controller"/>

    <!--mvc注解驱动 -->
    <mvc:annotation-driven/>

    <!--mvc静态资源过滤-->
    <mvc:default-servlet-handler/>

    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
        <!--前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!--后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

spring integration file

applicationContext.xml

Import the three spring configuration files into a new applicationContext.xml (created under the Resources directory).

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

    <import resource="classpath:spring-dao.xml"/>
    <import resource="classpath:spring-service.xml"/>
    <import resource="classpath:spring-mvc.xml"/>
</beans>

web layer|view layer

1. web.xml configuration file

<?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">


    <!--配置前端控制器-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <!--绑定springmvc配置文件,这里绑定配置的是最终的整合的spring文件,别出错了-->
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <!--启动级别-->
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <!--过滤器配置-->
    <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>

    <!--Session过期时间-->
    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>


</web-app>

What needs to be noted here is that in the front controller, the final binding is to integrate the general configuration file applicationContext.xml . Don’t make a mistake, otherwise it will tell you that some beans cannot be found. to modify.

2. View layer jsp page

a. Home page

index.jsp page

<%--
  Created by IntelliJ IDEA.
  User: gothi
  Date: 2022/12/3
  Time: 10:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>首页</title>
    <style type="text/css">
      a {
      
      
        text-decoration: none;
        color: black;
        font-size: 18px;
      }
      h3 {
      
      
        width: 180px;
        height: 38px;
        margin: 100px auto;
        text-align: center;
        line-height: 38px;
        background: deepskyblue;
        border-radius: 4px;
      }
    </style>
  </head>
  <body>

    <h3><a href="${pageContext.request.contextPath}/user/allUser">点击进入</a></h3>
  </body>
</html>

b. User list page

Create a new jsp page in the /WEB-INF/jsp/ directory

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: gothi
  Date: 2022/12/3
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询所有用户</title>
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>用户列表 —— 显示所有用户</small>
                </h1>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4 column">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/user/toAddUser">新增</a>
        </div>
        <div class="col-md-4 column">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/user/allUser">显示所有用户</a>
        </div>
        <div class="col-md-4 column">
            <form class="form-inline" action="${pageContext.request.contextPath}/user/queryUser" method="post" style="float: right">
                <input type="text" name="userName" class="form-control" placeholder="输入用户名" required>
                <input type="submit" value="查询" class="btn btn-primary">
            </form>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-hover table-striped">
                <thead>
                <tr>
                    <th>用户id</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="user" items="${requestScope.get('userList')}">
                    <tr>
                        <td>${user.id}</td>
                        <td>${user.userName}</td>
                        <td>${user.password}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/user/toUpdateUser?id=${user.getId()}">更改</a> |
                            <a href="${pageContext.request.contextPath}/user/delUser/?id=${user.getId()}">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>

c. Add user page

addUser.jsp

<%--
  Created by IntelliJ IDEA.
  User: gothi
  Date: 2022/12/3
  Time: 19:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户添加</title>
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>用户添加</small>
                </h1>
            </div>
        </div>
    </div>
    <form action="${pageContext.request.contextPath}/user/addUser" method="post">
        用户名:<input type="text" name="userName"><br><br><br>&nbsp;&nbsp;码:<input type="text" name="password"><br><br><br>
        <input type="submit" value="添加">
    </form>
</div>
</body>
</html>

d. Update the user page

updateUser.jsp

<%--
  Created by IntelliJ IDEA.
  User: gothi
  Date: 2022/12/3
  Time: 19:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户更新</title>
    <!-- 引入 Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>修改用户信息</small>
                </h1>
            </div>
        </div>
    </div>
    <form action="${pageContext.request.contextPath}/user/updateUser" method="post">
        <input type="hidden" name="id" value="${user.id}"/>
        用户名:<input type="text" name="userName" value="${user.userName}"/>&nbsp;&nbsp;码:<input type="text" name="password" value="${user.password}"/>
        <input type="submit" value="提交"/>
    </form>
</div>
</body>
</html>

Start the server running

front page:
insert image description here

User list page:
insert image description here

Add user page:

insert image description here
After clicking Add:
insert image description here
This is because the primary key is self-incrementing. Some data was tested before, so the id number will be displayed as 10.
Modify the user page:
insert image description here

Modify the test:
insert image description here
Query according to the user name:
insert image description here
insert image description here
the same user name here will find out multiple user data, because I only have one data of the user name named Da Mo Gu Yan here, so only one data is displayed.


personal summary

Sure enough, the configuration of ssm is really cumbersome, but if you do it layer by layer, it's not too complicated, so practice more! After more than 10 days, the second scan is over, and the next step is to do some ssm practice projects to get familiar with the process.

Then, because of the rush of time, the writing is a bit simple, and the front desk is ugly. After a while, I will do a real ssm project, and after I finish it, I will learn springboot, and redis... Finally, I will learn the related technologies of the front desk carefully. ! ! ! !

Guess you like

Origin blog.csdn.net/m0_63622279/article/details/128157791#comments_26331036