帮助文档

基本项目结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
├─pom.xml
|
├─src
│ ├─main
│ │ ├─java
│ │ │ └─top
│ │ │ └─jezer
│ │ │ ├─controller //控制器包
│ │ │ ├─entity //POJO包
│ │ │ ├─interceptor //拦截器包
│ │ │ ├─mapper //Mapper接口包
│ │ │ ├─service //Service接口包
│ │ │ ├─serviceImpl //service实现类包
│ │ │ └─util //工具包
│ │ └─resources //资源文件夹(配置文件)
│ │ ├─mapper //mapper.xml文件夹
│ │ │ └─BooksMapper.xml
| | ├─applicationContext.xml //Spring配置文件
| | ├─dbconfig.properties //数据库配置文件
| | ├─log4j.properties //log4j配置文件
| | ├─mybatis-config.xml //mybatis配置文件
| | ├─spring-mvc.xml //springMvc配置文件
| | ├─spring-mapper.xml //spring-mapper配置文件
| | └─spring-service.xml //spring-service配置文件
│ └─test
│ └─java
|
└─web
├─static
│ ├─css
│ ├─img
│ └─js
└─WEB-INF
│ └─pages
│ │ └─books
│ │ └─allBooks.jsp
│ └─web.xml
└─index.jsp
└─login.jsp

基本环境搭建

  1. 创建数据库表

    init.sql
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    CREATE DATABASE `ssmbuild`;

    USE `ssmbuild`;

    DROP TABLE IF EXISTS `books`;

    CREATE TABLE `books` (
    `bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '书id',
    `bookName` VARCHAR(100) NOT NULL COMMENT '书名',
    `bookCounts` INT(11) NOT NULL COMMENT '数量',
    `detail` VARCHAR(200) NOT NULL COMMENT '描述',
    KEY `bookID` (`bookID`)
    ) ENGINE=INNODB DEFAULT CHARSET=utf8

    INSERT INTO `books`(`bookID`,`bookName`,`bookCounts`,`detail`)VALUES
    (1,'Java',1,'从入门到放弃'),
    (2,'MySQL',10,'从删库到跑路'),
    (3,'Linux',5,'从进门到进牢');
  2. 新建一个空的Maven项目

  3. pom.xml中导入相关的pom依赖!

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    <dependencies>
    <!--Junit测试工具-->
    <!--https://mvnrepository.com/artifact/junit/junit-->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    </dependency>

    <!--mysql数据库驱动-->
    <!--https://mvnrepository.com/artifact/mysql/mysql-connector-java-->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.28</version>
    </dependency>


    <!-- 数据库连接池:c3p0 -->
    <!--https://mvnrepository.com/artifact/com.mchange/c3p0-->
    <dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.5</version>
    </dependency>

    <!-- 实体类插件:lombok-->
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.22</version>
    </dependency>

    <!--Servlet - JSP-->
    <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    </dependency>
    <!--https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api-->
    <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.2</version>
    </dependency>
    <!--https://mvnrepository.com/artifact/javax.servlet/jstl-->
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    </dependency>

    <!--Mybatis-->
    <!--https://mvnrepository.com/artifact/org.mybatis/mybatis-->
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.9</version>
    </dependency>
    <!--https://mvnrepository.com/artifact/org.mybatis/mybatis-spring-->
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>2.0.7</version>
    </dependency>

    <!--Spring-->
    <!--https://mvnrepository.com/artifact/org.springframework/spring-webmvc-->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.16</version>
    </dependency>
    <!--https://mvnrepository.com/artifact/org.springframework/spring-jdbc-->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.3.16</version>
    </dependency>

    <!--log4j日志工厂-->
    <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
    </dependency>

    </dependencies>
  4. pom.xml中设置Maven静态资源过滤

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <!--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>
  5. 连接数据库

  6. 创建基本项目结构

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    interceptor ---> 拦截器包
    controller ----> 控制器包
    entity ----> POJO包
    mapper ----> Mapper接口包
    service ----> Service接口包
    serviceImpl ----> service实现类包
    util ----> 工具包
    mapping ---> mapper.xml文件夹
    mybatis-config.xml ----> mybatis配置文件
    applicationContext.xml ----> Spring配置文件
    mybatis-config.xml
    1
    2
    3
    4
    5
    6
    7
    8
    <?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>

    </configuration>

    applicationContext.xml
    1
    2
    3
    4
    5
    6
    7
    <?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
    https://www.springframework.org/schema/beans/spring-beans.xsd">

    </beans>

Mybatis层编写

  1. log4j日志配置文件log4j.properties

    log4j.properties
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    #将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码
    log4j.rootLogger=DEBUG,console,file

    #控制台输出的相关设置
    log4j.appender.console = org.apache.log4j.ConsoleAppender
    log4j.appender.console.Target = System.out
    log4j.appender.console.Threshold=DEBUG
    log4j.appender.console.layout = org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=[%c]-%m%n

    #文件输出的相关设置
    log4j.appender.file = org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=./log/kuang.log
    log4j.appender.file.MaxFileSize=10mb
    log4j.appender.file.Threshold=DEBUG
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

    #日志输出级别
    log4j.logger.org.mybatis=DEBUG
    log4j.logger.java.sql=DEBUG
    log4j.logger.java.sql.Statement=DEBUG
    log4j.logger.java.sql.ResultSet=DEBUG
    log4j.logger.java.sql.PreparedStatement=DEBUG
  2. 使用lombok编写数据库对应实体类Books

    Books.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    package top.jezer.entity;

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

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Books {
    private int bookID;
    private String bookName;
    private int bookCounts;
    private String detail;
    }
  3. 编写Books实体类的BooksMapper接口

    BooksMapper.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package top.jezer.mapper;
    import top.jezer.entity.Books;

    import java.util.List;

    public interface BooksMapper {

    int addBook(Books book);
    int deleteBookById(int id);
    int updateBook(Books books);
    Books queryBookById(int id);
    List<Books> queryAllBook();

    }
  4. 编写BooksMapper.java对应的BooksMapper.xml文件

    BooksMapper.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="top.jezer.mapper.BooksMapper">
    <!--增加一个Book-->
    <insert id="addBook" parameterType="Books">
    insert into ssmbuild.books(bookName,bookCounts,detail)
    values (#{bookName}, #{bookCounts}, #{detail})
    </insert>

    <!--根据id删除一个Book-->
    <delete id="deleteBookById" parameterType="int">
    delete from ssmbuild.books where bookID=#{bookID}
    </delete>

    <!--更新Book-->
    <update id="updateBook" parameterType="Books">
    update ssmbuild.books
    set bookName = #{bookName},bookCounts = #{bookCounts},detail = #{detail}
    where bookID = #{bookID}
    </update>

    <!--根据id查询,返回一个Book-->
    <select id="queryBookById" resultType="Books">
    select * from ssmbuild.books
    where bookID = #{bookID}
    </select>

    <!--查询全部Book-->
    <select id="queryAllBook" resultType="Books">
    SELECT * from ssmbuild.books
    </select>
    </mapper>
  5. 更新配置文件mybatis-config.xml配置文件

    mybatis-config.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?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>
    <!--log4j日志功能-->
    <settings>
    <setting name="logImpl" value="LOG4J"/>
    </settings>

    <!--配置数据源的任务已转接给Spring完成-->
    <typeAliases>
    <!--实体类实现自动取别名-->
    <package name="top.jezer.entity"/>
    </typeAliases>

    <mappers>
    <mapper resource="mapping/BooksMapper.xml"/>
    </mappers>
    </configuration>
  6. 编写Service层的接口和实现类

    BooksService.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package top.jezer.service;

    import top.jezer.entity.Books;

    import java.util.List;

    public interface BooksService {

    int addBook(Books book);
    int deleteBookById(int id);
    int updateBook(Books books);
    Books queryBookById(int id);
    List<Books> queryAllBook();
    }
    BooksServiceImpl.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    package top.jezer.serviceImpl;

    import top.jezer.entity.Books;
    import top.jezer.mapper.BooksMapper;
    import top.jezer.service.BooksService;
    import java.util.List;
    public class BooksServiceImpl implements BooksService {

    //调用mapper层的操作,设置一个set接口,方便Spring管理
    private BooksMapper booksMapper;
    //在control层通过注解实现自动装配@autowire
    public void setBooksMapper(BooksMapper booksMapper) {
    this.booksMapper = booksMapper;
    }

    @Override
    public int addBook(Books book) {
    return booksMapper.addBook(book);
    }

    @Override
    public int deleteBookById(int id) {
    return booksMapper.deleteBookById(id);
    }

    @Override
    public int updateBook(Books books) {
    return booksMapper.updateBook(books);
    }

    @Override
    public Books queryBookById(int id) {
    return booksMapper.queryBookById(id);
    }

    @Override
    public List<Books> queryAllBook() {
    return booksMapper.queryAllBook();
    }
    }

Spring层

  1. 数据库配置文件dbconfig.properties

    dbconfig.properties
    1
    2
    3
    4
    jdbc.driver=com.mysql.cj.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&&serverTimezone=Asia/Shanghai
    jdbc.username=root
    jdbc.password=12345678
  2. 编写spring-mapper.xml文件

    spring-mappers.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    <?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
    https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 配置整合mybatis -->
    <!-- 1.关联数据库文件 -->
    <context:property-placeholder location="classpath:dbconfig.properties"/>

    <!-- 2.数据库连接池 -->
    <!--数据库连接池
    dbcp 半自动化操作 不能自动连接
    c3p0 自动化操作(自动的加载配置文件 并且设置到对象里面)
    -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
    <!-- 配置连接池属性 -->
    <property name="driverClass" value="${jdbc.driver}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <!-- c3p0连接池的私有属性 -->
    <property name="maxPoolSize" value="30"/>
    <property name="minPoolSize" value="10"/>
    <!-- 关闭连接后不自动commit -->
    <property name="autoCommitOnClose" value="false"/>
    <!-- 获取连接超时时间 -->
    <property name="checkoutTimeout" value="10000"/>
    <!-- 当获取连接失败重试次数 -->
    <property name="acquireRetryAttempts" value="2"/>
    </bean>

    <!-- 3.配置SqlSessionFactory对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 注入数据库连接池 -->
    <property name="dataSource" ref="dataSource"/>
    <!-- 配置MyBatis全局配置文件:mybatis-config.xml -->
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>

    <!-- 4.配置扫描Mapper接口包,动态实现Mapper接口注入到spring容器中 -->
    <!--解释 :https://www.cnblogs.com/jpfss/p/7799806.html-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 注入sqlSessionFactory -->
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    <!-- 给出需要扫描Mapper接口包 -->
    <property name="basePackage" value="top.jezer.mapper"/>
    </bean>


    </beans>
  3. 编写spring-service.xml

    spring-service.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <?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
    https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 扫描service相关的bean -->
    <context:component-scan base-package="top.jezer.service"/>
    <!--BooksServiceImpl注入到IOC容器中-->
    <bean id="BooksServiceImpl" class="top.jezer.serviceImpl.BooksServiceImpl">
    <property name="booksMapper" ref="booksMapper"/>
    </bean>

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

springMVC层

  1. 添加web框架支持

  2. 编辑web.xml

    web.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    <?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">
    <!--DispatcherServlet-->
    <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: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>

    <!--encodingFilter-->
    <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>

    <!-- 设置默认欢迎界面 -->
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
  3. 编写spring-mvc.xml

    spring-mvc.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <?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
    https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 配置SpringMVC -->
    <!-- 1.开启SpringMVC注解驱动 -->
    <mvc:annotation-driven/>

    <!-- 2.静态资源默认servlet配置-->
    <mvc:default-servlet-handler/>

    <!-- 3.配置jsp 显示ViewResolver视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".jsp" />
    </bean>

    <!-- 4.扫描web相关的bean -->
    <context:component-scan base-package="top.jezer.controller"/>

    </beans>

Controller 和 View层

  1. 编写login.jsp(放到web目录下,不要放到WEB_INF下)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html lang="en">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1786038_m62pqneyrzf.css">
    <link rel="stylesheet" href="static/css/login.css">
    <title>Document</title>
    </head>

    <body>
    <div class="form-wrapper">
    <div class="header">
    login
    </div>
    <div class="input-wrapper">
    <div class="border-wrapper">
    <input type="text" name="username" placeholder="username" class="border-item" autocomplete="off">
    </div>
    <div class="border-wrapper">
    <input type="password" name="password" placeholder="password" class="border-item" autocomplete="off">
    </div>
    </div>
    <div class="action">
    <div class="btn">login</div>
    </div>
    <div class="icon-wrapper">
    <i class="iconfont icon-weixin"></i>
    <i class="iconfont icon-qq"></i>
    <i class="iconfont icon-git"></i>
    </div>
    </div>

    </body>

    </html>
  2. 编写对应的login.css

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    * {
    margin: 0;
    padding: 0;
    }

    html {
    height: 100%;
    }

    body {
    height: 100%;
    font-family: JetBrains Mono Medium;
    display: flex;
    align-items: center;
    justify-content: center;
    /* background-color: #0e92b3; */
    background: url(https://pic.imgdb.cn/item/61cc7a302ab3f51d9119b16a.png) no-repeat;
    background-size: 100% 100%;
    }

    .form-wrapper {
    width: 300px;
    background-color: rgba(41, 45, 62, .8);
    color: #fff;
    border-radius: 2px;
    padding: 50px;
    }

    .form-wrapper .header {
    text-align: center;
    font-size: 35px;
    text-transform: uppercase;
    line-height: 100px;
    }

    .form-wrapper .input-wrapper input {
    background-color: rgb(41, 45, 62);
    border: 0;
    width: 100%;
    text-align: center;
    font-size: 15px;
    color: #fff;
    outline: none;
    }

    .form-wrapper .input-wrapper input::placeholder {
    text-transform: uppercase;
    }

    .form-wrapper .input-wrapper .border-wrapper {
    background-image: linear-gradient(to right, #e8198b, #0eb4dd);
    width: 100%;
    height: 50px;
    margin-bottom: 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    }

    .form-wrapper .input-wrapper .border-wrapper .border-item {
    height: calc(100% - 4px);
    width: calc(100% - 4px);
    border-radius: 30px;
    }

    .form-wrapper .action {
    display: flex;
    justify-content: center;
    }

    .form-wrapper .action .btn {
    width: 60%;
    text-transform: uppercase;
    border: 2px solid #0e92b3;
    text-align: center;
    line-height: 50px;
    border-radius: 30px;
    cursor: pointer;
    }

    .form-wrapper .action .btn:hover {
    background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
    }

    .form-wrapper .icon-wrapper {
    text-align: center;
    width: 60%;
    margin: 0 auto;
    margin-top: 20px;
    border-top: 1px dashed rgb(146, 146, 146);
    padding: 20px;
    }

    .form-wrapper .icon-wrapper i {
    font-size: 20px;
    color: rgb(187, 187, 187);
    cursor: pointer;
    border: 1px solid #fff;
    padding: 5px;
    border-radius: 20px;
    }

    .form-wrapper .icon-wrapper i:hover {
    background-color: #0e92b3;
    }
  3. 编写index.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <html lang="en">
    <head>
    <title>$Title$</title>
    </head>
    <body>
    <h3>
    <a href="${pageContext.request.contextPath}/book/allBooks">点击进入列表页</a>
    </h3>
    </body>
    </html>
  4. 编写BooksController.java

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    package top.jezer.controller;

    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 top.jezer.entity.Books;
    import top.jezer.service.BooksService;

    import java.util.List;

    /**
    * @author Jezer
    */
    @Controller
    @RequestMapping("/book")
    public class BooksController {
    @Autowired
    @Qualifier("BooksServiceImpl")
    private BooksService booksService;

    @RequestMapping("/allBooks")
    public String list(Model model) {
    List<Books> list = booksService.queryAllBook();
    model.addAttribute("list", list);
    return "pages/books/allBooks";
    }
    }
  5. 编写allBooks.jsp

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <%--
    Created by IntelliJ IDEA.
    User: Jezer
    Date: 2022/3/4
    Time: 23:07
    To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
    <title>Title</title>
    </head>
    <body>
    hello
    </body>
    </html>