JavaWeb small project - [source code] use Vue+axios+Servlet+Lombok+JDBC+MySQL technology stack to realize the development of cloud note management system case

lead out

Use Vue+axios+Servlet+Lombok+JDBC+MySQL technology stack to realize the development of cloud note management system case

Small project requirements

(1) Topic requirements
Use Vue+axios+Servlet+Lombok+JDBC+MySQL technology stack to realize the development of a cloud note management system case

(2) Database design (10 points)
Create database woniu_note
(1) User table: t_user, required fields include: username (username), password (passwd)
(2) Folder table: t_folder, required fields include: folder id (id), folder name (folder_name)
(3) Note table: t_note, required fields include: note id (id), note title (title), note content (content), associated folder table id (folder_id)

(3) Project requirements (90 points in total)
(1) Realize user login (10 points)
① After successful login, you can jump to the home page (5 points)
② Require the use of filters to verify the user’s login authority (5 points)
insert image description here

(2) Realize the note list query function (20 points)
① Remarks: The folder is obtained by connecting the note table (t_note) to query the folder table (t_folder), otherwise no score (10 points)

(3) Realize the paging display function of the note list (20 points)
① Remarks: The folder is obtained by connecting the note table (t_note) to query the folder table (t_folder), otherwise no points (10 points)
insert image description here

(4) Realize the function of adding notes (10 points)
insert image description here

(5) Realize the function of modifying notes (20 points)
① Require data echo (10 points)
② Successful modification (10 points)

(6) Realize the function of deleting notes (10 points)

fixed things

1. pom.xml file configuration + web.xml file configuration

pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.tianju</groupId>
  <artifactId>javawebTest0612</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

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

    <!--    jsp相关-->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.3</version>
    </dependency>

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

    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>

    <!--    数据库相关-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.20</version>
    </dependency>

    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.2.16</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.2.22.RELEASE</version>
    </dependency>

    <!--    其他-->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.22</version>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.5</version>
    </dependency>

    <!--    工具包-->
    <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-all</artifactId>
      <version>5.8.11</version>
    </dependency>

    <!--    fastjson包-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.76</version>
    </dependency>

  </dependencies>
</project>

web.xml 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">
</web-app>


2. DBUtils of JDBC in util + string tool StringUtils

DBUtils.java file:

package com.tianju.util;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

public class DBUtils {
    
    
    private static DruidDataSource dataSource =null;
    static {
    
    
        String driverClassname = "com.mysql.cj.jdbc.Driver";
        String ip = "127.0.0.1:3306/javaweb";
//        String ip = ConfigMap.getConfig().get("ip");
        // jdbc:mysql://127.0.0.1:3306/javaweb06?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8
        String url = "jdbc:mysql://"+ip+"?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
//        String url = "jdbc:mysql://"+"127.0.0.1:3306/javaweb"+"?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "123";
        dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassname);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
    }

    /**
     *
     * @return 返回一个JdbcTemplate对象
     */
    public static JdbcTemplate getJdbcTemplate(){
    
    
        return new JdbcTemplate(dataSource);
    }
}

StringUtils.java file

package com.tianju.util;

/**
 * 防止前端传过来为null 或者 ""
 */
public class StringUtils {
    
    
    public static Boolean isBlank(String str){
    
    
        if(str==null || str.trim().equals("")){
    
    
            return true;
        }
        return false;
    }
}

3. The PageInfo paging entity class in entity + ResData response standard format

PageInfo.java

package com.tianju.entity;

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

import java.util.List;

/**
 * 和分页相关的实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageInfo<T> {
    
    
    private Integer pageNum; // 当前是第几页,如果没有输入,默认是第一页
    private Integer pageSize; // 每页显示的数据条数,百度默认一页10条
    private Integer total; // 总条数;
    private Integer pages; // 总页数;
    private List<T> list; // 传给前端的list
}

ResData.java

package com.tianju.entity;

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

/**
 * 响应的实体类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResData {
    
    
    private Integer code;
    private String msg;
    private Object data;
}

4. The encoding CharacterEncodingFilter and permission LoginAuthorFilter in the filter

CharacterEncodingFilter.java file

package com.tianju.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 解决编码问题的过滤器
 */
@WebFilter("/*")
public class CharacterEncodingFilter implements Filter {
    
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
    

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
    
        // 编码问题
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        // 一定要记得放行
        chain.doFilter(request, response);

    }

    @Override
    public void destroy() {
    
    

    }
}

LoginAuthorFilter.java file

package com.tianju.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 控制权限
 */
@WebFilter("/*")
public class LoginAuthorFilter implements Filter {
    
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
    

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
    
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        String requestURI = req.getRequestURI();
        // 1.不登录也可以访问的连接,放行
        if (requestURI.contains("/js/")
                || requestURI.contains("/bootstrap/")
                || requestURI.contains("/css/")
                || requestURI.contains("/img/")
                || requestURI.contains("/user/login")
                || requestURI.contains("/user/login.jsp")
        ){
    
    
            chain.doFilter(request, response);
        }else {
    
    
            // 2.其他连接必须登陆后才能访问
            HttpSession session = req.getSession();
            Object user = session.getAttribute("user");
            // 如果没有登陆,就去登陆页面
            if (user==null){
    
    
                resp.sendRedirect(req.getContextPath()+"/user/login.jsp");
            }else {
    
    
                //登陆了,就放行
                chain.doFilter(request, response);
            }
        }
    }

    @Override
    public void destroy() {
    
    

    }
}

5. Front-end fixed js package and bootstrap package

See the code package for this article

Small project source code

See the code package for this article

insert image description here

insert image description here
insert image description here


Summarize

Use Vue+axios+Servlet+Lombok+JDBC+MySQL technology stack to realize the development of cloud note management system case

Guess you like

Origin blog.csdn.net/Pireley/article/details/131204612