Based on SSM (worker management system), add, delete, modify, query, file upload, multi condition search and paging are realized

1, The worker management system contains functions

1. Develop a worker management system using SSM framework, including the following functional requirements:

  • Realize the addition, deletion, modification and paging list of workers
  • The ID card of the worker shall be unique, and the uniqueness shall be verified before saving
  • The ID card of the worker is required to be legal. The length to be verified is 18, the 7th-11th is year, the 12th-13th is month, and the 14th-15th is day
  • The paging list shall support fuzzy query based on name
  • The size of the picture of the worker's Avatar shall not exceed 1M. It is required that the suffix of the picture must be one of png/jpg/bmp
  • When editing, the worker's picture should be echoed.
  • The worker's Avatar to be echoed in the list.
  • The storage address of the worker's head picture shall be yyyymm / ddhhmmsxxxx. Suffix format. XXXX is a random 4-digit number.
  • When editing, if no new picture is uploaded, there is no need to change the existing picture
  • When editing, if you upload a new picture, you don't need to create a new picture, just overwrite the existing picture.
  • When deleting, if there is a avatar picture, first delete the avatar picture from the hard disk, and then delete the worker information.

2, Technology used by workers in the project

1. The main technologies used are

1. Main framework: Spring MVC + Spring + mybatis

2. Security framework: Spring security

3. Database: Mysql

4. Asynchronous update: Ajax

5. Front end framework: zui, bootstrap, Jquery, vue

3, The effect of the worker page is demonstrated as follows (gif)

4, Construction drawing of SSM worker project

5, Worker data sheet

drop table if exists t_worker;
CREATE TABLE `t_worker` (
  `noid` int(11) NOT NULL AUTO_INCREMENT,
  `worker_name` varchar(32) NOT NULL COMMENT 'Name of worker',
  `id_card` varchar(32)  default NULL comment 'ID card No.',
  `gender` tinyint(4) NOT NULL COMMENT 'Gender, 1 male, 2 female',
  `age` int(11) NOT NULL COMMENT 'Age',
  `constructor_id` int(11) not null comment 'Workers' participating units',
  `head_img_path` varchar(64) DEFAULT NULL COMMENT 'The relative address of the avatar can be obtained according to the relative address url And physical storage address',
  PRIMARY KEY (`noid`),
  UNIQUE KEY `unq_worker_id_card` (`id_card`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;

6, pom.xml (jar package that the worker project depends on)

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>3.0-alpha-1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!--Configuration of section jar package -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--mybatis,Used to load SqlSessionFactoryBean and MapperScannerConfigurer -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.8</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>
        <!--Database driver package -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.32</version>
        </dependency>
        <!--log file -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.22</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.9</version>
        </dependency>



        <!--Mail dependency-->
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.2</version>
        </dependency>


        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>



    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>

        <spring.version>5.3.8</spring.version>
    </properties>
    <build>
        <finalName>Admin</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>8081</port>
                    <path>/Admin</path>
                    <uriEncoding>UTF-8</uriEncoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

7, Springmvc.xml (including file upload parser)

<?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:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/util
                            http://www.springframework.org/schema/util/spring-util-3.1.xsd
                            http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/mvc
                            http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">


    <!-- Annotation auto scan, configuration convert,data validation(Not recommended,Recommended front end) -->
    <mvc:annotation-driven/>

    <!--spring mvc scanning controller Do not scan service-->
    <context:component-scan base-package="com.wanshi.mvc">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
    </context:component-scan>

    <!-- Profile upload parser -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- Set file upload size -->
        <property name="maxUploadSize" value="5000000"></property>
    </bean>
</beans>


8, mybatis-Context.xml

<?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>
    <mappers><!-- Mapper tells MyBatis Where can I find the mapping file -->
        <mapper resource="mapper/WorkMapper.xml" />
    </mappers>
</configuration>

9, applicationContext.xml

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                        http://www.springframework.org/schema/task
                        http://www.springframework.org/schema/task/spring-task-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- bean annotation -->
    <context:annotation-config/>

    <context:component-scan base-package="com.wanshi.ssm">
        <!-- Do not scan spring mvc of controller -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!-- create data source -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/zhuangao?useSSL=true" />
        <property name="username" value="root" />
        <property name="password" value="111111" />
        <!--initialize value -->
        <property name="initialSize" value="3" />
        <!--Minimum spare quantity -->
        <property name="minIdle" value="3" />
        <!--Maximum number of connections -->
        <property name="maxActive" value="20" />
        <!--Maximum waiting time -->
        <property name="maxWait" value="60000" />
        <!--filter -->
        <property name="filters" value="stat,wall" />
    </bean>

    <!--  SqlSessionFactory  -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- configLocation The attribute value of is Mybatis Core profile for -->
        <property name="configLocation" value="classpath:mybatis-config.xml" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- mybatis-spring Component scanner -->
        <property name="basePackage" value="com.wanshi.ssm.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

</beans>



10, Worker backend code

1. Worker entity class (worker)

package com.wanshi.ssm.bean;

    public class Worker {
    private String noid;
    private String worker_name;
    private String id_card;
    private String gender;
    private String age;
    private String constructor_id;
    private String head_img_path;

    private String constructor_name;
    public String getConstructor_name() {
        return constructor_name;
    }


    public void setConstructor_name(String constructor_name) {
        this.constructor_name = constructor_name;
    }

        public String getNoid() {
        return noid;
    }

    public void setNoid(String noid) {
        this.noid = noid;
    }

    public String getWorker_name() {
        return worker_name;
    }

    public void setWorker_name(String worker_name) {
        this.worker_name = worker_name;
    }

    public String getId_card() {
        return id_card;
    }

    public void setId_card(String id_card) {
        this.id_card = id_card;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getConstructor_id() {
        return constructor_id;
    }

    public void setConstructor_id(String constructor_id) {
        this.constructor_id = constructor_id;
    }

    public String getHead_img_path() {
        return head_img_path;
    }

    public void setHead_img_path(String head_img_path) {
        this.head_img_path = head_img_path;
    }
}

2. Worker paging entity class (WorkerPage)

package com.wanshi.ssm.bean;

import java.util.ArrayList;
import java.util.List;

public class WorkerPage {
    private int page;
    private int pageMax;
    private int pagecount;
    private int pagesize;
    private List<Worker> list;
    private List<Integer> listpage = new ArrayList();
    public WorkerPage(int page, int pageMax, int pagecount, int pagesize, List list) {
        super();
        this.page = page;
        this.pageMax = pageMax;
        this.pagecount = pagecount;
        this.pagesize = pagesize;
        this.list = list;
        for (int i = page-5; i < page+4; i++) {
            if(i<=0||i>pageMax){
                continue;
            }else{
                listpage.add(i);
            }
        }
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageMax() {
        return pageMax;
    }

    public void setPageMax(int pageMax) {
        this.pageMax = pageMax;
    }

    public int getPagecount() {
        return pagecount;
    }

    public void setPagecount(int pagecount) {
        this.pagecount = pagecount;
    }

    public int getPagesize() {
        return pagesize;
    }

    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }

    public List<Worker> getList() {
        return list;
    }

    public void setList(List<Worker> list) {
        this.list = list;
    }

    public List<Integer> getListpage() {
        return listpage;
    }

    public void setListpage(List<Integer> listpage) {
        this.listpage = listpage;
    }
}

3. Worker Mapper layer interface (WorkerMapper)

package com.wanshi.ssm.mapper;

import com.wanshi.ssm.bean.User;
import com.wanshi.ssm.bean.Worker;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface WorkerMapper {
    Integer addWorker(Worker worker);

    List<Worker> listWorker();

    Worker selectByNoid(String noid);

    Integer deleteNoid(String noid);

    Integer alterWorker(Worker worker);


    public int selectcount(Map map);
    public List<Worker> select(Map map);
    public Worker selectById(int noid);
}

4. Worker WorkerMapper.xml file

<?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.wanshi.ssm.mapper.WorkerMapper">
    <insert id="addWorker" parameterType="com.wanshi.ssm.bean.Worker">
        insert into t_worker (worker_name,id_card,gender,age,constructor_id,head_img_path) values (#{worker_name},#{id_card},#{gender},#{age},#{constructor_id},#{head_img_path})
    </insert>

    <select id="listWorker" resultType="com.wanshi.ssm.bean.Worker" parameterType="com.wanshi.ssm.bean.Worker">
        SELECT t_worker.*,t_constructor.`constructor_name` FROM t_worker JOIN t_constructor WHERE t_constructor.`noid` = t_worker.`constructor_id`;
    </select>

    <delete id="deleteNoid" parameterType="com.wanshi.ssm.bean.Worker">
        delete from t_worker
        <where>
            noid = #{noid}
        </where>
    </delete>

    <select id="selectByNoid" resultType="com.wanshi.ssm.bean.Worker" parameterType="com.wanshi.ssm.bean.Worker">
        SELECT * FROM t_worker
        <where>
            noid = #{noid}
        </where>
    </select>

    <update id="alterWorker" parameterType="com.wanshi.ssm.bean.Worker">
        update t_worker
        <set>
            worker_name =  #{worker_name},
            id_card =  #{id_card},
            gender = #{gender},
            age = #{age},
            constructor_id = #{constructor_id}
            <if test="head_img_path != null and head_img_path != ''">
                ,head_img_path = #{head_img_path}
            </if>

        </set>
<!--        <if test="head_img_path!=null and head_img_path!=''">-->
<!--            ,head_img_path = #{head_img_path}-->
<!--        </if>-->
        <where>
            noid = #{noid}
        </where>
    </update>



    <select id="selectcount" resultType="int" parameterType="map">
        select count(1) from t_worker
        <where>
            <if test="worker_name != null and worker_name != ''">
                worker_name like concat('%',#{worker_name},'%')
            </if>
            <if test="realname !=null and realname != '' and realname != 0">
                and realname = #{realname}
            </if>
        </where>
    </select>
    <select id="select" resultType="com.wanshi.ssm.bean.Worker" parameterType="map">
        SELECT t_worker.*,t_constructor.`constructor_name` FROM t_worker JOIN t_constructor on t_constructor.`noid` = t_worker.`constructor_id`
        <where>
            <if test="worker_name != null and worker_name != ''">
                worker_name like concat('%',#{worker_name},'%')
            </if>
            <if test="realname !=null and realname != '' and realname != 0">
                and realname = #{realname}
            </if>
        </where>
        limit #{tiao},#{pagesize}
    </select>

    <select id="selectById" parameterType="int" resultType="com.wanshi.ssm.bean.Worker">
        select * from t_worker where noid = #{noid}
    </select>



</mapper>

5. Worker service layer interface (worker service)

package com.wanshi.ssm.service;

import com.wanshi.ssm.bean.*;

import java.util.List;

public interface WorkerService {
    boolean addWorker( Worker worker);

    List<Worker> listWorker();

    Worker selectByNoid(String noid);

    boolean deleteNoid(String noid);

    boolean alterWorker( Worker worker);

    public WorkerPage select(Worker worker, Integer page , Integer pagesize);
    public Worker selectById(int id);
}


6. Worker ServiceImpl layer implementation class (WorkerServiceImpl)

package com.wanshi.ssm.service.impl;

import com.wanshi.ssm.bean.*;
import com.wanshi.ssm.mapper.CityMapper;
import com.wanshi.ssm.mapper.WorkerMapper;
import com.wanshi.ssm.service.CityService;
import com.wanshi.ssm.service.WorkerService;
import com.wanshi.ssm.utils.config.GlobalSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkerServiceImpl implements WorkerService {
    @Autowired
    private WorkerMapper workerMapper;

    @Override
    public boolean addWorker(Worker worker) {
       int i =  workerMapper.addWorker(worker);
        return i > 0;
    }

    @Override
    public List<Worker> listWorker() {
        return workerMapper.listWorker();
    }

    @Override
    public Worker selectByNoid(String noid) {
        return workerMapper.selectByNoid(noid);
    }

    @Override
    public boolean deleteNoid(String noid) {
        int i = workerMapper.deleteNoid(noid);
        return i > 0;
    }

    @Override
    public boolean alterWorker(Worker worker) {
        int i = workerMapper.alterWorker(worker);
        return i > 0;
    }

    @Override
    public WorkerPage select(Worker worker, Integer page, Integer pagesize) {
        Map map  = new HashMap();
        map.put("worker_name", worker.getWorker_name());
        //map.put("realname", worker.getRealname());
        //System.out.println(map.get("usercode"));
        int pagecount = workerMapper.selectcount(map);
        int pageMax = pagecount%pagesize==0?pagecount/pagesize:pagecount/pagesize+1;
        if(page<1){
            page = 1;
        }else if(page>pageMax&&pageMax!=0){
            page = pageMax;
        }
        map.put("tiao", (page-1)*pagesize);
        map.put("pagesize", pagesize);
        List<Worker> list = workerMapper.select(map);
        for (Worker w:list) {
           w.setHead_img_path(GlobalSet.RootUrl+w.getHead_img_path());
        }
        WorkerPage paging = new WorkerPage(page,pageMax,pagecount,pagesize,list);
        return paging;
    }

    @Override
    public Worker selectById(int id) {
        return workerMapper.selectById(id);
    }
}


7. Worker Controller layer (WorkerController)

package com.wanshi.mvc.web;

import com.wanshi.ssm.bean.*;
import com.wanshi.ssm.service.ConstructorService;
import com.wanshi.ssm.service.WorkerService;
import com.wanshi.ssm.utils.UploadUtil;
import com.wanshi.ssm.utils.config.GlobalSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/Worker")
public class WorkerController {
    static final Integer pagesize = 2;

    @Autowired
    private WorkerService workerService;

    @Autowired
    private ConstructorService constructorService;

    @GetMapping("/add.do")
    public String add(Model model){
       List<Constructor> constructorList =  constructorService.lsitConstructor();
        model.addAttribute("constructorList",constructorList);
        return  "/WEB-INF/Worker/add.jsp";
    }
    @PostMapping("/addPost.do")
    public String addPost(Worker worker,MultipartFile img_path){
        String headImgRelatPath = UploadUtil.upload(img_path);
        worker.setHead_img_path(headImgRelatPath);
        workerService.addWorker(worker);
        return "redirect:/Worker/list.do";
    }

    @GetMapping("/delete.do")
    public String delete(String noid){
        Worker  WorkerNoid = workerService.selectByNoid(noid);
        if(WorkerNoid.getHead_img_path()!=null){
            File file = new File(GlobalSet.FileUploadRoot+WorkerNoid.getHead_img_path());
            file.delete();
        }
        workerService.deleteNoid(noid);
        return "redirect:/Worker/list.do";
    }

    @GetMapping("/alter.do")
    public String alter(String noid,Model model,HttpServletRequest req){
        Worker  Worker = workerService.selectByNoid(noid);
        Worker.setHead_img_path(GlobalSet.RootUrlAlter+req.getContextPath()+"/imegs/"+Worker.getHead_img_path());
        model.addAttribute("Worker",Worker);

        return "/WEB-INF/Worker/alter.jsp";
    }
    @PostMapping("/alterPost.do")
    public String alterPost(Worker worker,String noid,MultipartFile img_path){

        if(worker.getHead_img_path()!=null && !worker.getHead_img_path().equals("")){
            File file = new File(GlobalSet.FileUploadRoot+worker.getHead_img_path());
            file.delete();
        }
        String headImgRelatPath = UploadUtil.upload(img_path);
        worker.setHead_img_path(headImgRelatPath);
        workerService.alterWorker(worker);
        return "redirect:/Worker/list.do";
    }


    @GetMapping("/list.do")
    public String list(Model model, HttpServletRequest req,String worker_name,String realname,String page){
        Worker worker = new Worker();
        if(worker_name!=null&&!worker_name.equals("")){
            worker.setWorker_name(worker_name);
        }

        Integer pag = 1;
        if(page!=null&&!page.equals("")){
            pag = Integer.valueOf(page);
        }
        WorkerPage paging = workerService.select(worker,pag,pagesize);
        req.setAttribute("paging", paging);
        req.setAttribute("worker_name", worker_name);
        req.setAttribute("realname", realname);


        return "/WEB-INF/Worker/list.jsp";
    }

}


8. Upload file path, my path is like this (according to the path you need)

package com.wanshi.ssm.utils.config;

import java.io.File;

/**
 * global International public
 * set set up
 */
public class GlobalSet {

    // Root path of all file uploads
    public final static String FileUploadRoot = "E:/IDear/Admin/src/main/webapp/imegs";
    public static final String RootUrl = "http://127.0.0.1:8081/Admin/imegs";
    public static final String RootUrlAlter = "http://127.0.0.1:8081/";


}

11, Worker front end code (jsp)

1. Worker addition

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<%
		request.setAttribute("APP_PATH", request.getContextPath());
	%>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="${APP_PATH}/static/admin/css/bootstrap.min.css">
	<script src="${APP_PATH}/static/admin/js/jquery-2.1.0.min.js"></script>
	<script src="${APP_PATH}/static/admin/js/bootstrap.min.js"></script>

</head>
<body>
	<div class="container cus-container">
        <h3 class="text-center" style="font-weight:bold">Worker Library</h3>

        <form action="${APP_PATH}/Worker/addPost.do" method="post" enctype="multipart/form-data">
            <div class="form-group">
              <label for="user">Name of worker:</label>
              <input type="text" class="form-control" name="worker_name">
            </div>
            <div class="form-group">
               <label for="user">ID card No.</label>
               <input type="text" class="form-control" name="id_card">

             </div>
            <div class="form-group">
                <label for="user">Gender:</label>
                <label>male<input type="radio" class="form-control" value="1" name="gender"></label>
                <label>female<input type="radio" class="form-control" value="2" name="gender"></label>
            </div>
            <div class="form-group">
                <label for="user">Age:</label>
                <input type="text" class="form-control" name="age">
            </div>
            <div class="form-group">
                <label for="user">Workers' participating units:</label>
                <select class="form-control" name="constructor_id">
                    <c:forEach items="${constructorList}" var="con">
                        <option value="${con.noid}">${con.constructor_name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="form-group">
                <label for="user">head portrait:</label>
                <input type="file" class="form-control" name="img_path">
            </div>


             <div class="text-center">
                 <input type="submit" class="btn btn-primary" value="Submit">
                 <button type="reset" class="btn btn-default">Reset</button>
              </div>
          </form>
       
    </div>
</body>
</html>

2. Worker modification

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html>
<html lang="en">
<head>
	<%
		request.setAttribute("APP_PATH", request.getContextPath());
	%>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="${APP_PATH}/static/admin/css/bootstrap.min.css">
	<script src="${APP_PATH}/static/admin/js/jquery-2.1.0.min.js"></script>
	<script src="${APP_PATH}/static/admin/js/bootstrap.min.js"></script>

</head>
<body>
	<div class="container cus-container">
        <h3 class="text-center" style="font-weight:bold">Worker library modification</h3>

        <form action="${APP_PATH}/Worker/alterPost.do" method="post" enctype="multipart/form-data">
            <div class="form-group">
              <label for="user">Name of worker:</label>
              <input type="text" class="form-control" name="worker_name" value="${Worker.worker_name}">
            </div>
            <div class="form-group">
               <label for="user">ID card No.</label>
               <input type="text" class="form-control" name="id_card" value="${Worker.id_card}">

             </div>
            <div class="form-group">
                <label for="user">Gender:</label>
                <label>male<input type="radio" class="form-control" value="1" name="gender"></label>
                <label>female<input type="radio" class="form-control" value="2" name="gender"></label>
            </div>
            <div class="form-group">
                <label for="user">Age:</label>
                <input type="text" class="form-control" name="age" value="${Worker.age}">
            </div>
            <div class="form-group">
                <label for="user">Workers' participating units:</label>
                <input type="text" class="form-control" name="constructor_id" value="${Worker.constructor_id}">
            </div>
            <div class="form-group">
                <label for="user">head portrait:</label>
                <input type="file" class="form-control" name="img_path">
            </div>
            <div class="form-group">
                <img src=" ${Worker.head_img_path}" width="200px" height="100px">
            </div>

             <div class="text-center">
                 <input type="hidden" class="btn btn-primary" name="noid" value="${Worker.noid}">
                 <input type="submit" class="btn btn-primary" value="Submit">
                 <button type="reset" class="btn btn-default">Reset</button>
              </div>
          </form>
       
    </div>
</body>
</html>

3. Workers show

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<%
		request.setAttribute("APP_PATH", request.getContextPath());
		request.setAttribute("BASE_PATH", "http://localhost:8080/upload/");
	%>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- Relative path to start searching relative to the location of the currently accessed file -->
    <link rel="stylesheet" href="${APP_PATH}/static/admin/css/bootstrap.min.css">
    <style>
       .cus-container{
           width: 1368px;
       }
       .success th,table td{text-align:center;}
    </style>
</head>
<body>
    <div class="container cus-container">

        <h3 class="text-center" style="font-weight:bold">List of workers</h3>
        <a class="" href="${pageContext.request.contextPath}/index.do">Return to the system interface</a>
        <div>
            <!-- Search box div -->
            <div id="search-user" style="float: left; margin: 10px 0px;">
                <form class="form-inline" action="${APP_PATH }/Worker/list.do" method="get">
                    <div class="form-group">
                        <label for="exampleInputName2">Name of worker:</label>
                        <input type="text" name="worker_name" value="${worker_name}" class="form-control" id="exampleInputName2" >
                    </div>
                    <input type="submit" class="btn btn-default" value="query">
                </form>
            </div>
       <table class="table table-bordered clearfix">
        <tr class="success">
            <th>Serial number</th>
            <th>Name of worker</th>
            <th>ID card No.</th>
            <th>Gender</th>
            <th>Age</th>
            <th>Workers' participating units</th>
            <th>head portrait</th>
            <th>operation</th>
        </tr>
        <c:forEach items="${paging.list}" var="wor" varStatus="staus">
	        <tr>
	            <td style="vertical-align:middle;">
                    ${staus.count}
	            </td>
	            <td style="vertical-align:middle;">
                    ${wor.worker_name}
                </td>
                <td style="vertical-align:middle;">
                        ${wor.id_card}
                </td>
                <td style="vertical-align:middle;">
                        ${wor.gender == 1?'male':'female'}
                </td>
                <td style="vertical-align:middle;">
                        ${wor.age}
                </td>
                <td style="vertical-align:middle;">
                        ${wor.constructor_name}
                </td>
                <td style="vertical-align:middle;">
                    <img src=" ${wor.head_img_path}" width="200px" height="100px">
                </td>
                <td style="vertical-align:middle;">
                    <a class="" href="${pageContext.request.contextPath}/Worker/alter.do?noid=${wor.noid}">modify</a>
                    <a class="" href="${pageContext.request.contextPath}/Worker/delete.do?noid=${wor.noid}">Delete</a>
                </td>
	        </tr>
</c:forEach>
      </table>
            <!-- Paging navigation -->
            <div>
                <!-- Paging navigation -->
                <nav style="float: left;">
                    <ul class="pagination">
                        <li>
                            <a href="${pageContext.request.contextPath }/Worker/list.do?page=${paging.page-1}&worker_name=${worker_name}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach items="${paging.listpage }" var="page" varStatus="status" >
                            <li><a href="${pageContext.request.contextPath }/Worker/list.do?page=${page}&worker_name=${worker_name}">${status.count}</a></li>
                        </c:forEach>

                        <li>
                            <a href="${pageContext.request.contextPath }/Worker/list.do?page=${paging.page+1}&worker_name=${worker_name}" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
                <div style="float: right;margin-top: 25px;">
                    <span>common ${paging.pagecount }Records, minutes ${paging.pageMax }Page display</span>
                </div>
            </div>
        </div>
</body>
</html>

Tags: Java Spring bootstrap architecture Project

Posted on Fri, 03 Dec 2021 03:18:16 -0500 by wad