最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java?Web實(shí)戰(zhàn)之使用三層架構(gòu)與Servlet構(gòu)建登錄注冊(cè)模塊

 更新時(shí)間:2024年10月11日 10:02:32   作者:VaporGas  
這篇文章介紹了如何使用三層架構(gòu)(View,?Service,?DAO)和JDBCTemplate技術(shù)在JavaWeb環(huán)境下實(shí)現(xiàn)登錄和注冊(cè)功能,詳細(xì)說(shuō)明了構(gòu)建項(xiàng)目的步驟,包括創(chuàng)建數(shù)據(jù)庫(kù)表、實(shí)體類、DAO層、Service層、Servlet處理及頁(yè)面設(shè)計(jì),需要的朋友可以參考下

 前言導(dǎo)讀

三層架構(gòu):View(視圖層)Service(業(yè)務(wù)層)DAO(持久層)

  • 使用了JDBCtemplate技術(shù),封裝了原生的JDBC技術(shù)操作MySQL數(shù)據(jù)庫(kù)(DAO層)
  • 實(shí)現(xiàn)了登錄功能和注冊(cè)功能(Service層)
  • 使用Servlet操作前端表單提供的數(shù)據(jù),進(jìn)行登錄和注冊(cè),以及完成頁(yè)面跳轉(zhuǎn)的需求實(shí)現(xiàn)(View層)

 第一步:創(chuàng)建JavaWeb項(xiàng)目,在pom.xml中配置相關(guān)依賴

 pom.xml

不要把我的項(xiàng)目名也一起復(fù)制了,只復(fù)制依賴<dependency>和插件部分<build>

<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>org.example</groupId>
  <artifactId>maven_9_11</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>maven_9_11 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <!-- junit單元測(cè)試-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!--MySQL數(shù)據(jù)庫(kù)連接驅(qū)動(dòng)jar包-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.28</version>
    </dependency>
    <!-- servlet依賴支持-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    <!--JDBCTemplate依賴支持,因?yàn)镴DBCTemplate是Spring框架封裝的一個(gè)工具類,因此需要導(dǎo)入Spring相關(guān)依賴-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>5.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>

  </dependencies>
  <build>
    <!--配置項(xiàng)目名 -->
    <finalName>web</finalName>
    <plugins>
    <!--配置jetty服務(wù)器插件支持-->
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.3.14.v20161028</version>
    </plugin>
      <!--配置tomcat服務(wù)器插件支持-->
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.1</version>
      <configuration>
        <port>8080</port>
        <path>/</path>
        <uriEncoding>UTF-8</uriEncoding>
        <server>tomcat7</server>
      </configuration>
    </plugin>
    </plugins>
  </build>
</project>

第二步:創(chuàng)建數(shù)據(jù)庫(kù)表和實(shí)體類并導(dǎo)入JDBCTemplate工具類

數(shù)據(jù)庫(kù)表t_user:

這里不介紹如何創(chuàng)建這樣的一個(gè)數(shù)據(jù)庫(kù)了(保證user_id為主鍵即可)

User實(shí)體類:

package com.csx.entity;

import java.io.Serializable;

public class User implements Serializable {
    private Integer userId;
    private String userName;
    private String password;

    public User(){}

    public User(Integer userId, String userName, String password) {
        this.userId = userId;
        this.userName = userName;
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

工具類:

package com.csx.util;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCUtils {
    private static DataSource dataSource =null;

    static{
        try (
                InputStream is=JDBCUtils.class.getResourceAsStream("/JDBCUtils.properties")
        ){
            Properties p = new Properties();
            p.load(is);
            dataSource = new DriverManagerDataSource(p.getProperty("url"), p.getProperty("username"), p.getProperty("password"));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public static JdbcTemplate getJDBCTemplate(){
        //創(chuàng)建JDBCTemplate對(duì)象并傳入數(shù)據(jù)庫(kù)連接池
        JdbcTemplate template = new JdbcTemplate(dataSource);
        return template;
    }

    /**
     * 獲取數(shù)據(jù)庫(kù)連接池
     * @return
     */
    public static DataSource getDataSource(){
        return dataSource;
    }

    /**
     * 開(kāi)始線程綁定 +獲取連接
     * @return
     */
    public static Connection startTransaction(){
        if (!TransactionSynchronizationManager.isSynchronizationActive()){
            TransactionSynchronizationManager.initSynchronization();
        }
        Connection connection =DataSourceUtils.getConnection(dataSource);
        try {
            connection.setAutoCommit(false);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return connection;
    }

    /**
     * 提交事務(wù)
     * @param conn
     */
    public static void commit(Connection conn){
        try {
            conn.commit();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            clear(conn);
        }
    }

    /**
     * 回滾事務(wù)
     * @param conn
     */
    public static void rollback(Connection conn){
        try {
            conn.rollback();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            clear(conn);
        }
    }

    /**
     * 解除線程綁定+釋放資源+歸還連接到線程池
     * @param conn
     */
    public static void clear(Connection conn){
        //清除線程綁定的資源
        TransactionSynchronizationManager.clear();
        TransactionSynchronizationManager.unbindResourceIfPossible(dataSource);
        //歸還數(shù)據(jù)庫(kù)連接至連接池
        if (conn!=null){//非空判斷,判斷為空再歸還
            DataSourceUtils.releaseConnection(conn,dataSource);
        }
    }
}

在resources資源目錄下創(chuàng)建JDBCUtils.properties目錄

JDBCUtils.properties

url=jdbc:mysql://localhost:3306/csx_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=Asia/shanghai
username=root
password=root

第三步:創(chuàng)建DAO層,書(shū)寫(xiě)SQL支持

UserDao接口:

package com.csx.dao;

import com.csx.entity.User;

public interface UserDao {
    /**
     * 根據(jù)用戶名和密碼指定用戶是否存在
     * @param userName
     * @return
     */
    public User selectUserByUserName(String userName,String password);

    /**
     * 新增用戶信息
     * @param user
     * @return
     */
    public int insertUser(User user);
}

UserDaoImpl實(shí)現(xiàn)類:

package com.csx.dao.impl;

import com.csx.dao.UserDao;
import com.csx.entity.User;
import com.csx.service.UserService;
import com.csx.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate template = JDBCUtils.getJDBCTemplate();

    /**
     * 根據(jù)用戶名和密碼指定用戶是否存在
     *
     * @param userName
     * @param password
     * @return
     */
    @Override
    public User selectUserByUserName(String userName, String password) {
        String sql="select * from t_user where user_name=? and password=? ";
        List<User> list = template.query(sql, new BeanPropertyRowMapper<>(User.class), userName, password);
        return list.isEmpty()?null:list.get(0);
    }

    /**
     * 新增用戶信息
     *
     * @param user
     * @return
     */
    @Override
    public int insertUser(User user) {
        String sql="insert into t_user(user_name,password) values(?,?)";
        return template.update(sql, user.getUserName(), user.getPassword());
    }
}

第四步:創(chuàng)建Service層,書(shū)寫(xiě)登錄和注冊(cè)邏輯

UserService接口:

package com.csx.service;

public interface UserService {
    /**
     * 用戶登錄功能
     * @param username
     * @param password
     * @return
     */
    public boolean login(String username,String password);

    /**
     * 用戶注冊(cè)功能
     * @return
     */
    public boolean register(String username,String password);
}

UserServiceImpl實(shí)現(xiàn)類:

package com.csx.service.impl;

import com.csx.dao.UserDao;
import com.csx.dao.impl.UserDaoImpl;
import com.csx.entity.User;
import com.csx.service.UserService;
import com.csx.util.JDBCUtils;

import java.sql.Connection;

public class UserServiceImpl implements UserService {
    private UserDao userDao =new UserDaoImpl();

    /**
     * 用戶登錄功能
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public boolean login(String username, String password) {
        boolean boo =false;
        Connection conn =null;
        try{
            conn= JDBCUtils.startTransaction();
            //業(yè)務(wù)功能
            User user = userDao.selectUserByUserName(username,password);
            //判斷用戶名是否存在
            if (user!=null){
                //判斷密碼是否正確
                if (user.getPassword().equals(password)){
                    boo=true;
                }else {
                    throw new RuntimeException("密碼錯(cuò)誤!");
                }
            }else {
                throw new RuntimeException("用戶不存在!");
            }
            JDBCUtils.commit(conn);
        }catch (Exception e){
            JDBCUtils.rollback(conn);
            throw new RuntimeException(e);
        }
        return boo;

    }

    /**
     * 用戶注冊(cè)功能
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public boolean register(String username, String password) {
        boolean boo=false;
        Connection conn=null;
        try {
            conn = JDBCUtils.startTransaction();
            //業(yè)務(wù)功能
            User u = userDao.selectUserByUserName(username,password);
            if (u == null) {
                User user = new User(null, username, password);
                userDao.insertUser(user);
                boo = true;
            } else {
                throw new RuntimeException("用戶名重復(fù),注冊(cè)失敗!");
            }
            JDBCUtils.commit(conn);
        }catch (Exception e){
            JDBCUtils.rollback(conn);
            throw  new RuntimeException(e);
        }
        return boo;
    }
}

第五步:書(shū)寫(xiě)Servlet接收頁(yè)面?zhèn)魅氲臄?shù)據(jù),并響應(yīng)

LoginServlet:

package com.csx.servlet;

import com.csx.service.UserService;
import com.csx.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private UserService userService =new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name = request.getParameter("username");
        String pwd =request.getParameter("password");
        try {
            boolean login = userService.login(name, pwd);
            if (login){
                System.out.println("登錄成功!");
                response.sendRedirect("login_success.html");
            }else {

                }
        } catch (Exception e) {
            System.out.println("登錄失敗");
            response.sendRedirect("login_failed.html");
        }

    }
}

RegisterServlet:

package com.csx.servlet;

import com.csx.service.UserService;
import com.csx.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    private UserService userService =new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("username");
        String pwd =request.getParameter("password");
        try {
            boolean login = userService.register(name, pwd);
            if (login){
                System.out.println("注冊(cè)成功!");
//                response.sendRedirect("register_success.html");
                response.sendRedirect("register_success.html");
            }
        } catch (Exception e) {
            System.out.println("注冊(cè)失敗!");
            response.sendRedirect("register_failed.html");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}

web.xml配置 

創(chuàng)建一個(gè)JavaWeb項(xiàng)目,想要使用注解@WebServlet來(lái)配置Servlet路徑映射,需要將webapp目錄下的WBE-INF目錄下的web.xml中配置3.0 以上的配置頭,例如:

<?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_3_1.xsd"
         version="3.1">

</web-app>

 第六步:在webapp目錄下創(chuàng)建HTML頁(yè)面

login.html:

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Form</title>
    <style>
        /* 簡(jiǎn)單的樣式來(lái)美化表單 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .login-form {
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .login-form h2 {
            margin-bottom: 20px;
        }
        .login-form input[type="text"],
        .login-form input[type="password"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .login-form input[type="submit"] {
            background-color: #ff0000;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .login-form input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>

<div class="login-form">
    <h2>Login</h2>
    <form action="/login" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>

        <input type="submit" value="Login">
    </form>
</div>
</body>
</html>

login_success.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>登錄成功!</h1>
</body>
<script>alert('登錄成功!')</script>
</html>

login_failed:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>登錄失敗</h1>
</body>
<script>
    alert('登錄失敗')
</script>
</html>

register.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Registration Form</title>
    <style>
        /* 簡(jiǎn)單的樣式來(lái)美化表單 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .registration-form {
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .registration-form h2 {
            margin-bottom: 20px;
        }
        .registration-form input[type="text"],
        .registration-form input[type="password"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .registration-form input[type="submit"] {
            background-color: #28a745;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .registration-form input[type="submit"]:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>

<div class="registration-form">
    <h2>Registration</h2>
    <form action="/register" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>

        <input type="submit" value="Register">
    </form>
</div>

</body>
</html>

register_success:

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Form</title>
    <style>
        /* 簡(jiǎn)單的樣式來(lái)美化表單 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .login-form {
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .login-form h2 {
            margin-bottom: 20px;
        }
        .login-form input[type="text"],
        .login-form input[type="password"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .login-form input[type="submit"] {
            background-color: #ff0000;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .login-form input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>

<div class="login-form">
    <h2>Login</h2>
    <form action="/login" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>

        <input type="submit" value="Login">
    </form>
</div>
</body>
<script>
    alert(' 注冊(cè)成功,請(qǐng)登錄!');

   </script>
</html>

register_failed:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Registration Form</title>
    <style>
        /* 簡(jiǎn)單的樣式來(lái)美化表單 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .registration-form {
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .registration-form h2 {
            margin-bottom: 20px;
        }
        .registration-form input[type="text"],
        .registration-form input[type="password"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .registration-form input[type="submit"] {
            background-color: #28a745;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .registration-form input[type="submit"]:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>

<div class="registration-form">
    <h2>Registration</h2>
    <form action="/register" method="post">
        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>

        <input type="submit" value="Register">
    </form>
</div>

</body>
<script>
    alert("注冊(cè)失敗!")
</script>
</html>

第七步:項(xiàng)目啟動(dòng)與測(cè)試 

項(xiàng)目啟動(dòng),參考我的這篇博客:JavaWeb項(xiàng)目啟動(dòng)

運(yùn)行測(cè)試

登錄

登錄失敗

登錄成功

注冊(cè)

注冊(cè)成功

注冊(cè)成功會(huì)直接跳轉(zhuǎn)到登錄頁(yè)面

注冊(cè)失敗

注冊(cè)失敗,彈出警告框,并且返回注冊(cè)頁(yè)面

總結(jié)

整體結(jié)構(gòu)圖

忽略我沒(méi)有在博客書(shū)寫(xiě)的類和html頁(yè)面,它們是我自己測(cè)試時(shí)使用的,不影響整體功能執(zhí)行

基于三層架構(gòu)和Servlet進(jìn)行登錄和注冊(cè)功能的實(shí)現(xiàn)項(xiàng)目 

總結(jié) 

到此這篇關(guān)于Java Web實(shí)戰(zhàn)之使用三層架構(gòu)與Servlet構(gòu)建登錄注冊(cè)模塊的文章就介紹到這了,更多相關(guān)Java Web構(gòu)建登錄注冊(cè)模塊內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring整合Mybatis具體代碼實(shí)現(xiàn)流程

    Spring整合Mybatis具體代碼實(shí)現(xiàn)流程

    這篇文章主要介紹了Spring整合Mybatis實(shí)操分享,文章首先通過(guò)介紹Mybatis的工作原理展開(kāi)Spring整合Mybatis的詳細(xì)內(nèi)容,需要的小伙伴可以參考一下
    2022-05-05
  • Spring Boot 3 RestClient使用實(shí)戰(zhàn)案例

    Spring Boot 3 RestClient使用實(shí)戰(zhàn)案例

    本文詳細(xì)介紹了SpringBoot3中RestClient的使用方法,從基礎(chǔ)到高級(jí),涵蓋了各種常見(jiàn)場(chǎng)景和最佳實(shí)踐,通過(guò)本教程,讀者可以理解RestClient的核心概念和優(yōu)勢(shì),感興趣的朋友跟隨小編一起看看吧
    2026-01-01
  • Java8實(shí)戰(zhàn)之Stream的延遲計(jì)算

    Java8實(shí)戰(zhàn)之Stream的延遲計(jì)算

    JDK中Stream的中間函數(shù)如 filter(Predicate super T>)是惰性求值的,filter并非對(duì)流中所有元素調(diào)用傳遞給它的Predicate,下面這篇文章主要給大家介紹了關(guān)于Java8實(shí)戰(zhàn)之Stream延遲計(jì)算的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • 關(guān)于Lombok @Data注解:簡(jiǎn)化Java代碼的魔法棒

    關(guān)于Lombok @Data注解:簡(jiǎn)化Java代碼的魔法棒

    Lombok庫(kù)通過(guò)@Data注解自動(dòng)生成常見(jiàn)的樣板代碼如getter、setter、toString等,極大減少代碼量,提高開(kāi)發(fā)效率,@Data注解集成了@ToString、@EqualsAndHashCode、@Getter、@Setter、@RequiredArgsConstructor等注解的功能
    2024-10-10
  • Java實(shí)現(xiàn)刪除文件中的指定內(nèi)容

    Java實(shí)現(xiàn)刪除文件中的指定內(nèi)容

    在日常開(kāi)發(fā)中,經(jīng)常需要對(duì)文本文件進(jìn)行批量處理,其中,刪除文件中指定內(nèi)容是最常見(jiàn)的需求之一,下面我們就來(lái)看看如何使用java實(shí)現(xiàn)刪除文件中的指定內(nèi)容吧
    2025-06-06
  • Java如何去掉指定字符串的開(kāi)頭的指定字符

    Java如何去掉指定字符串的開(kāi)頭的指定字符

    這篇文章主要介紹了Java去掉指定字符串的開(kāi)頭的指定字符操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • Java設(shè)計(jì)模式之單例模式簡(jiǎn)單解析

    Java設(shè)計(jì)模式之單例模式簡(jiǎn)單解析

    這篇文章主要介紹了Java設(shè)計(jì)模式之單例模式簡(jiǎn)單解析,單例模式的優(yōu)點(diǎn)在于在內(nèi)存中某個(gè)類只有一個(gè)實(shí)例,減少了內(nèi)存的開(kāi)銷,尤其是頻繁的創(chuàng)建和銷毀實(shí)例,避免對(duì)資源的多重暫用,需要的朋友可以參考下
    2023-12-12
  • JAVA初探設(shè)計(jì)模式的六大原則

    JAVA初探設(shè)計(jì)模式的六大原則

    這篇文章主要介紹了JAVA初探設(shè)計(jì)模式的六大原則,對(duì)設(shè)計(jì)模式感興趣的同學(xué),可以參考下
    2021-05-05
  • SpringCloud安裝Nacos完成配置中心

    SpringCloud安裝Nacos完成配置中心

    如果不滿足上篇文章的eureka注冊(cè)中心,那么本文記錄的Nacos是不二之選。本文主要記錄Springboot基于Nacos實(shí)現(xiàn)配置中心
    2022-07-07
  • java通過(guò)isAccessAllowed方法實(shí)現(xiàn)訪問(wèn)控制

    java通過(guò)isAccessAllowed方法實(shí)現(xiàn)訪問(wèn)控制

    在Web應(yīng)用開(kāi)發(fā)中,使用Apache Shiro框架的isAccessAllowed方法可以有效管理用戶的訪問(wèn)權(quán)限,本文詳細(xì)解析了該方法的實(shí)現(xiàn)過(guò)程,包括用戶身份驗(yàn)證、權(quán)限判斷和安全性分析,下面就一起來(lái)了解一下
    2024-09-09

最新評(píng)論

松原市| 普兰县| 大丰市| 布尔津县| 从化市| 南木林县| 奎屯市| 定襄县| 南平市| 阿尔山市| 启东市| 山东| 武威市| 贞丰县| 弥勒县| 民县| 安化县| 开封县| 孝义市| 修文县| 九江市| 温泉县| 获嘉县| 新河县| 永胜县| 舟山市| 抚远县| 四平市| 北辰区| 育儿| 涟水县| 临猗县| 平顺县| 宁武县| 新营市| 登封市| 榆社县| 平原县| 瑞金市| 古丈县| 清新县|