简介

为了减少写一些 get/set/toString 方法,让项目代码更加整洁,提高开发效率,发现大家都开始采用 Lombok 这个工具。Lombok 是一个 Java 类库,它会自动插入编辑器和构建工具,用于帮助开发人员消除 Java 中冗长样板代码。而我们开发人员所要做的,仅仅是添加几个 Lombok 中的注解,就可以替换掉原来的多行 get/set/toString 方法代码,既简洁也易于维护。下面我们就来看看,如何安装并使用这一工具。

安装 Lombok

日常开发中,相信大多数人现在使用的都是 IDEA 这个 Java 神器了,如果你还在使用 Eclipse 或者 MyEclipse 等工具,那强烈推荐你去体验一把 IDEA,相信你一用上它就会爱上他它的强大!下面我就一在 IDEA 中使用 Lombok 为例,看看如何安装并使用它。

在先前 IDEA 的版本中,Lombok 是需要通过插件来安装的,安装方法如下:依次进入File -> Settings -> Plugins,然后搜索 Lombok ,最后进行安装即可。而在新版本的 IDEA 中,Lombok 已经被集成到 IDEA 中,我们不用再去安装它就可以直接使用,可以说是十分方便了。

老版本 IDEA 安装 Lombok

新版本中集成了 Lombok

以上就是 Lombok 的安装过程了,是不是十分简单?那接下来我们就来看看,如何在我们的项目中使用 Lombok!

Lombok 使用

现在大家进行项目管理时用的工具大多应该都是 Maven,所以我们直接在需要使用 Lombok 的项目中加入 Lombok 编译支持,也就是在 pom.xml 文件中加入以下依赖。

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

导入相关依赖之后,接下来就是具体使用过程了。

具体使用

在需要的实体类中引入相关注解即可,只不过注解不同它们所对应的功能也不同,而且同一个注解可能在不同位置的功能也不一样。如下图;

常用注解

@Data

注解在 类 上:给类的所有属性提供 get 和 set 方法,此外还有 equals、canEqual、hashCode、toString 方法以及 默认参数为空的构造方法;

使用前:

package com.cunyu.user.entity;

public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;

    public User() {
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Integer getAge() {
        return this.age;
    }

    public String getEmail() {
        return this.email;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public void setName(final String name) {
        this.name = name;
    }

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

    public void setEmail(final String email) {
        this.email = email;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof User)) {
            return false;
        } else {
            User other = (User)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$id = this.getId();
                    Object other$id = other.getId();
                    if (this$id == null) {
                        if (other$id == null) {
                            break label59;
                        }
                    } else if (this$id.equals(other$id)) {
                        break label59;
                    }

                    return false;
                }

                Object this$age = this.getAge();
                Object other$age = other.getAge();
                if (this$age == null) {
                    if (other$age != null) {
                        return false;
                    }
                } else if (!this$age.equals(other$age)) {
                    return false;
                }

                Object this$name = this.getName();
                Object other$name = other.getName();
                if (this$name == null) {
                    if (other$name != null) {
                        return false;
                    }
                } else if (!this$name.equals(other$name)) {
                    return false;
                }

                Object this$email = this.getEmail();
                Object other$email = other.getEmail();
                if (this$email == null) {
                    if (other$email != null) {
                        return false;
                    }
                } else if (!this$email.equals(other$email)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof User;
    }

    public int hashCode() {
        int PRIME = true;
        int result = 1;
        Object $id = this.getId();
        int result = result * 59   ($id == null ? 43 : $id.hashCode());
        Object $age = this.getAge();
        result = result * 59   ($age == null ? 43 : $age.hashCode());
        Object $name = this.getName();
        result = result * 59   ($name == null ? 43 : $name.hashCode());
        Object $email = this.getEmail();
        result = result * 59   ($email == null ? 43 : $email.hashCode());
        return result;
    }

    public String toString() {
        Long var10000 = this.getId();
        return "User(id="   var10000   ", name="   this.getName()   ", age="   this.getAge()   ", email="   this.getEmail()   ")";
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.Data;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */

@Data
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@Setter

注解在 类 上:为该类所有属性均提供 set 方法,同时提供 默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
    public void setId(final Long id) {
        this.id = id;
    }
    public void setName(final String name) {
        this.name = name;
    }
    public void setAge(final Integer age) {
        this.age = age;
    }
    public void setEmail(final String email) {
        this.email = email;
    }
}

使用后:

package com.cunyu.user.entity;

import lombok.Setter;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@Setter
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

注解在 属性 上:为该属性提供 set 方法,同时提供 默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
    public void setId(final Long id) {
        this.id = id;
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.Setter;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
public class User {
    @Setter
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@Getter

注解在 类 上:为该类所有属性均提供 get 方法,同时提供 默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
    public Long getId() {
        return this.id;
    }
    public String getName() {
        return this.name;
    }
    public Integer getAge() {
        return this.age;
    }
    public String getEmail() {
        return this.email;
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.Getter;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@Getter
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

注解在 属性 上:为该属性提供 get 方法,同时提供 默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
    public Long getId() {
        return this.id;
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.Getter;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
public class User {
    @Getter
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@ToString

注解在 类 上:生成所有参数的 toString() 方法,同时提供 默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
    public String toString() {
        return "User(id="   this.id   ", name="   this.name   ", age="   this.age   ", email="   this.email   ")";
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.ToString;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@ToString
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@Value

注解在 类 上:生成 get 方法,以及 equals、hashCode、toString 方法,同时提供 含所有参数的构造方法;

使用前:

package com.cunyu.user.entity;
public final class User {
    private final Long id;
    private final String name;
    private final Integer age;
    private final String email;
    public User(final Long id, final String name, final Integer age, final String email) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.email = email;
    }
    public Long getId() {
        return this.id;
    }
    public String getName() {
        return this.name;
    }
    public Integer getAge() {
        return this.age;
    }
    public String getEmail() {
        return this.email;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof User)) {
            return false;
        } else {
            User other;
            label56: {
                other = (User)o;
                Object this$id = this.getId();
                Object other$id = other.getId();
                if (this$id == null) {
                    if (other$id == null) {
                        break label56;
                    }
                } else if (this$id.equals(other$id)) {
                    break label56;
                }
                return false;
            }
            label49: {
                Object this$age = this.getAge();
                Object other$age = other.getAge();
                if (this$age == null) {
                    if (other$age == null) {
                        break label49;
                    }
                } else if (this$age.equals(other$age)) {
                    break label49;
                }

                return false;
            }
            Object this$name = this.getName();
            Object other$name = other.getName();
            if (this$name == null) {
                if (other$name != null) {
                    return false;
                }
            } else if (!this$name.equals(other$name)) {
                return false;
            }

            Object this$email = this.getEmail();
            Object other$email = other.getEmail();
            if (this$email == null) {
                if (other$email != null) {
                    return false;
                }
            } else if (!this$email.equals(other$email)) {
                return false;
            }

            return true;
        }
    }
    public int hashCode() {
        int PRIME = true;
        int result = 1;
        Object $id = this.getId();
        int result = result * 59   ($id == null ? 43 : $id.hashCode());
        Object $age = this.getAge();
        result = result * 59   ($age == null ? 43 : $age.hashCode());
        Object $name = this.getName();
        result = result * 59   ($name == null ? 43 : $name.hashCode());
        Object $email = this.getEmail();
        result = result * 59   ($email == null ? 43 : $email.hashCode());
        return result;
    }
    public String toString() {
        Long var10000 = this.getId();
        return "User(id="   var10000   ", name="   this.getName()   ", age="   this.getAge()   ", email="   this.getEmail()   ")";
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.Value;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */

@Value
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@AllArgsConstructor

注解在 类 上:为类提供一个 全参构造方法,但此时不再提供默认构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;

    public User(final Long id, final String name, final Integer age, final String email) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.email = email;
    }
}

使用后:

package com.cunyu.user.entity;

import lombok.AllArgsConstructor;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@AllArgsConstructor
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@NoArgsConstructor

注解在 类 上:为类提供一个 无参构造方法;

使用前:

package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
    public User() {
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.NoArgsConstructor;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@NoArgsConstructor
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@RequiredArgsConstructor

注解在 类 上:使用类中所有带 @NonNull 注解的或带有 final 修饰的成员变量生成对应构造方法;

使用前:

package com.cunyu.user.entity;
import lombok.NonNull;
public class User {
    @NonNull
    private Long id;
    private String name;
    private Integer age;
    @NonNull
    private String email;

    public User(@NonNull final Long id, @NonNull final String email) {
        if (id == null) {
            throw new NullPointerException("id is marked non-null but is null");
        } else if (email == null) {
            throw new NullPointerException("email is marked non-null but is null");
        } else {
            this.id = id;
            this.email = email;
        }
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.RequiredArgsConstructor;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */
@RequiredArgsConstructor
public class User {
    @NonNull
    private Long id;
    private String name;
    private Integer age;
    @NonNull
    private String email;
}

@NonNull

注解在 属性 上,自动生成一个关于该参数的非空检查,若参数为 null,则抛出一个空指针异常,同时提供 默认构造方法,具体用法可以参照上面的例子;

@EqualsAndHashCode

注解在 类 上,生成 equals、canEquals、hasnCode 方法,同时会生成默认构造方法;

使用前:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.cunyu.user.entity;
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;

    public User() {
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof User)) {
            return false;
        } else {
            User other = (User)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$id = this.id;
                    Object other$id = other.id;
                    if (this$id == null) {
                        if (other$id == null) {
                            break label59;
                        }
                    } else if (this$id.equals(other$id)) {
                        break label59;
                    }

                    return false;
                }

                Object this$age = this.age;
                Object other$age = other.age;
                if (this$age == null) {
                    if (other$age != null) {
                        return false;
                    }
                } else if (!this$age.equals(other$age)) {
                    return false;
                }

                Object this$name = this.name;
                Object other$name = other.name;
                if (this$name == null) {
                    if (other$name != null) {
                        return false;
                    }
                } else if (!this$name.equals(other$name)) {
                    return false;
                }

                Object this$email = this.email;
                Object other$email = other.email;
                if (this$email == null) {
                    if (other$email != null) {
                        return false;
                    }
                } else if (!this$email.equals(other$email)) {
                    return false;
                }

                return true;
            }
        }
    }
    protected boolean canEqual(final Object other) {
        return other instanceof User;
    }
    public int hashCode() {
        int PRIME = true;
        int result = 1;
        Object $id = this.id;
        int result = result * 59   ($id == null ? 43 : $id.hashCode());
        Object $age = this.age;
        result = result * 59   ($age == null ? 43 : $age.hashCode());
        Object $name = this.name;
        result = result * 59   ($name == null ? 43 : $name.hashCode());
        Object $email = this.email;
        result = result * 59   ($email == null ? 43 : $email.hashCode());
        return result;
    }
}

使用后:

package com.cunyu.user.entity;
import lombok.EqualsAndHashCode;
/**
 * Created with IntelliJ IDEA.
 *
 * @author : zhangliang
 * @version : 1.0
 * @project : User
 * @package : com.cunyu.user.entity
 * @className : User
 * @createTime : 2021/8/6 17:14
 * @description : 用户实体类
 */

@EqualsAndHashCode
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

@Cleanup

注解在 局部变量 前,保证该变量代表的资源使用后自动关闭,默认调用资源的 close() 方法,若该资源有其它关闭方法,可用 @Cleanup("方法名") 来指定要调用的方法,同时提供 默认构造方法;

使用前:

import java.io.*;

public class CleanupExample {
    public static void main(String[] args) throws IOException {
        InputStream in = new FileInputStream(args[0]);
        try {
            OutputStream out = new FileOutputStream(args[1]);
            try {
                byte[] b = new byte[10000];
                while (true) {
                    int r = in.read(b);
                    if (r == -1) break;
                    out.write(b, 0, r);
                }
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
}

使用后:

import lombok.Cleanup;
import java.io.*;

public class CleanupExample {
    public static void main(String[] args) throws IOException {
        @Cleanup InputStream in = new FileInputStream(args[0]);
        @Cleanup OutputStream out = new FileOutputStream(args[1]);
        byte[] b = new byte[10000];
        while (true) {
            int r = in.read(b);
            if (r == -1) break;
            out.write(b, 0, r);
        }
    }
}

@Synchronized

注解在 类方法 或 实例方法:效果与 synchronized 关键字相同,区别在于锁对象不同,对于类方法和实例方法,synchronized 关键字的锁对象分别是 类的 class 对象和 this 对象,而 @Synchronized 的锁对象分别是 私有静态 final 对象 lock 和 私有 final 对象 lock,也可以自己指定锁对象,同时提供默认构造方法;

使用前:

public class SynchronizedExample {
    private static final Object $LOCK = new Object[0];
    private final Object $lock = new Object[0];
    private final Object readLock = new Object();
    public static void hello() {
        synchronized($LOCK) {
            System.out.println("world");
        }
    }
    public int answerToLife() {
        synchronized($lock) {
            return 42;
        }
    }

    public void foo() {
        synchronized(readLock) {
            System.out.println("bar");
        }
    }
}

使用后:

import lombok.Synchronized;
public class SynchronizedExample {
    private final Object readLock = new Object();
    @Synchronized
    public static void hello() {
        System.out.println("world");
    }
    @Synchronized
    public int answerToLife() {
        return 42;
    }
    @Synchronized("readLock")
    public void foo() {
        System.out.println("bar");
    }
}

@SneakyThrows

注解在 方法 上:将方法中的代码用 try-catch 语句包裹,捕获异常并在 catch 中用 Lombok.sneakyThrow(e) 将异常抛出,还可以用 @SneakyThrows(Exception.class) 的形式指定抛出异常类型,同时提供 默认构造方法;

使用前:

import lombok.Lombok;
public class SneakyThrowsExample implements Runnable {
    public String utf8ToString(byte[] bytes) {
        try {
            return new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw Lombok.sneakyThrow(e);
        }
    }
    public void run() {
        try {
            throw new Throwable();
        } catch (Throwable t) {
            throw Lombok.sneakyThrow(t);
        }
    }
}

使用后:

import lombok.SneakyThrows;
public class SneakyThrowsExample implements Runnable {
    @SneakyThrows(UnsupportedEncodingException.class)
    public String utf8ToString(byte[] bytes) {
        return new String(bytes, "UTF-8");
    }
    @SneakyThrows
    public void run() {
        throw new Throwable();
    }
}

@Log

注解在 类 上:主要用于我们记录日志信息,同时提供 默认构造方法。它封装了多个主流 Log 库,主要有如下几个;

  • @Log
  • @Slf4j
  • Log4j
  • Log4j2

总结:

到此这篇关于Lombok 安装和使用小技巧的文章就介绍到这了,更多相关Lombok 内容请搜索Devmax以前的文章或继续浏览下面的相关文章希望大家以后多多支持Devmax!

Lombok 安装和使用小技巧的更多相关文章

  1. 如何在PHP环境中使用ProtoBuf数据格式

    这篇文章主要介绍了如何在PHP环境中使用ProtoBuf数据格式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

  2. php-7.3.6 编译安装过程

    这篇文章主要介绍了php-7.3.6 编译安装过程,本文通过实例文字相结合给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

  3. 使用sockets:从新闻组中获取文章(三)

    >我们从服务器的这个新闻组中读取了最后的十篇文章,。也可以通过使用HEAD命令读取文章的头信息,或者使用BODY命令读取文章内容。>关于fclose()的更多信息,请参考http://www.php.net/manual/function.fclose.php结论在上文中,我们看到了怎样打开、使用然后关闭一个socket:连接到一个NNTP服务器,取回一些文章。使用POST命令发表文章也复杂不到哪儿去。下一步就是编写一个基于WEB的新闻组客户端了。这样,你有了一个基于web的搜索新闻组的程序了。

  4. PHP默认安装产生系统漏洞

    当你下载PHP後,在它内含的安装文件中帮助了PHP在NTApacheWebServer的安装方式,其中的安装帮助会要你将底下这几行设置加到apache的httpd.conf设置文件中,而这个安装文件将导引你将你的系统门户大开。

  5. 怎样在UNIX系统下安装php3

    #cd/usr/src#tarxvzfapache_1.3.6.tar.gz(产生apache_1.3.6目录)#tarxvzfphp-3.0.8.tar.gz(产生php-3.0.8目录)#cdapache_1.3.6#./configure--prefix=/usr/local/apache(把Apache的安装目录定为/usr/local/apache)#cdphp-3.0.8#./conf

  6. JavaScript中Webpack的使用教程

    Webpack 是一个前端资源加载/打包工具。它将根据模块的依赖关系进行静态分析,然后将这些模块按照指定的规则生成对应的静态资源,这篇文章主要介绍了JavaScript中Webpack的使用,需要的朋友可以参考下

  7. vue3中$attrs的变化与inheritAttrs的使用详解

    $attrs现在包括class和style属性。 也就是说在vue3中$listeners不存在了,vue2中$listeners是单独存在的,在vue3 $attrs包括class和style属性, vue2中 $attrs 不包含class和style属性,这篇文章主要介绍了vue3中$attrs的变化与inheritAttrs的使用 ,需要的朋友可以参考下

  8. PHP中GET变量的使用

    自PHP4.1.0以后将HTTP_GET_VARS使用GET变量来保存,GET的变量主要来自以下的方法对服务器以获取资料信息为请求方法的例如,URL,使用FORM的METHOD为GET方式。这样所有的请求变量将通过URL传递给服务器,服务器根据配置调用相关的解释器来处理这些GET出来的变量。arg_separator.input=";,"————二、自己编写解释语法list=$_GET;//将GET变量分解出来$tmp=explode;//将数据分出这个用法的优点在于,别人无法知道您传递的值是被谁使用,您

  9. Python数据分析 Numpy 的使用方法

    这篇文章主要介绍了Python数据分析 Numpy 的使用方法,Numpy 是一个Python扩展库,专门做科学计算,也是大部分Python科学计算库的基础,关于其的使用方法,需要的小伙伴可以参考下面文章内容

  10. 关于@RequestLine的使用及配置

    这篇文章主要介绍了关于@RequestLine的使用及配置方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

随机推荐

  1. 基于EJB技术的商务预订系统的开发

    用EJB结构开发的应用程序是可伸缩的、事务型的、多用户安全的。总的来说,EJB是一个组件事务监控的标准服务器端的组件模型。基于EJB技术的系统结构模型EJB结构是一个服务端组件结构,是一个层次性结构,其结构模型如图1所示。图2:商务预订系统的构架EntityBean是为了现实世界的对象建造的模型,这些对象通常是数据库的一些持久记录。

  2. Java利用POI实现导入导出Excel表格

    这篇文章主要为大家详细介绍了Java利用POI实现导入导出Excel表格,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  3. Mybatis分页插件PageHelper手写实现示例

    这篇文章主要为大家介绍了Mybatis分页插件PageHelper手写实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  4. (jsp/html)网页上嵌入播放器(常用播放器代码整理)

    网页上嵌入播放器,只要在HTML上添加以上代码就OK了,下面整理了一些常用的播放器代码,总有一款适合你,感兴趣的朋友可以参考下哈,希望对你有所帮助

  5. Java 阻塞队列BlockingQueue详解

    本文详细介绍了BlockingQueue家庭中的所有成员,包括他们各自的功能以及常见使用场景,通过实例代码介绍了Java 阻塞队列BlockingQueue的相关知识,需要的朋友可以参考下

  6. Java异常Exception详细讲解

    异常就是不正常,比如当我们身体出现了异常我们会根据身体情况选择喝开水、吃药、看病、等 异常处理方法。 java异常处理机制是我们java语言使用异常处理机制为程序提供了错误处理的能力,程序出现的错误,程序可以安全的退出,以保证程序正常的运行等

  7. Java Bean 作用域及它的几种类型介绍

    这篇文章主要介绍了Java Bean作用域及它的几种类型介绍,Spring框架作为一个管理Bean的IoC容器,那么Bean自然是Spring中的重要资源了,那Bean的作用域又是什么,接下来我们一起进入文章详细学习吧

  8. 面试突击之跨域问题的解决方案详解

    跨域问题本质是浏览器的一种保护机制,它的初衷是为了保证用户的安全,防止恶意网站窃取数据。那怎么解决这个问题呢?接下来我们一起来看

  9. Mybatis-Plus接口BaseMapper与Services使用详解

    这篇文章主要为大家介绍了Mybatis-Plus接口BaseMapper与Services使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  10. mybatis-plus雪花算法增强idworker的实现

    今天聊聊在mybatis-plus中引入分布式ID生成框架idworker,进一步增强实现生成分布式唯一ID,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

返回
顶部