J2EE模式

news/2024/9/23 22:36:52/

系列文章目录

J2EE模式特别关注表示层,这些模式是由 Sun Java Center 鉴定的,
包括:

1、 MVC模式(MVCPattern);
2、 业务代表模式(BusinessDelegatePattern);
3、 组合实体模式(CompositeEntityPattern);
4、 数据访问对象模式(DataAccessObjectPattern);
5、 前端控制器模式(FrontControllerPattern);
6、 拦截过滤器模式(InterceptingFilterPattern);
7、 服务定位器模式(ServiceLocatorPattern);
8、 传输对象模式(TransferObjectPattern);

J2EE模式

  • 系列文章目录
  • MVC 模式
  • 业务代表模式(Business Delegate Pattern)
  • 组合实体模式 (Composite Entity Pattern)
  • 数据访问对象模式 ( Data Access Object )
  • 前端控制器模式(Front Controller Pattern)
  • 拦截过滤器模式 ( Intercepting Filter )
  • 服务定位器模式 (Service Locator Pattern)
  • 传输对象模式 ( Transfer Object Pattern )

MVC 模式

MVC模式代表 Model-View-Controller(模型-视图-控制器) 模式

MVC模式用于应用程序的分层开发

java">Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO 它也可以带有逻辑,在数据变化时更新控制器
View(视图) - 视图代表模型包含的数据的可视化
Controller(控制器) - 控制器作用于模型和视图上。它控制数据流向模型对象,并在数据变化时更新视图。它使视图与模型分离开

实现
1、 定义一个作为模型的Student对象;
2、 StudentView是一个把学生详细信息输出到控制台的视图类;
3、 StudentController是负责存储数据到Student对象中的控制器类,并相应地更新视图StudentView;
4、 最后类MVCPatternDemo使用StudentController来演示MVC模式的用法;

范例

  1. 定义模型
    Student.java
java">public class Student {private String rollNo;private String name;public String getRollNo() {return rollNo;}public void setRollNo(String rollNo) {this.rollNo = rollNo;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}
  1. 定义视图
    StudentView.java
java">public class StudentView {public void printStudentDetails(String studentName, String studentRollNo){System.out.println("Student: ");System.out.println("Name: " + studentName);System.out.println("Roll No: " + studentRollNo);}
}
  1. 定义控制器
    StudentController.java
java">public class StudentController {private Student model;private StudentView view;public StudentController(Student model, StudentView view){this.model = model;this.view = view;}public void setStudentName(String name){model.setName(name);      }public String getStudentName(){return model.getName();       }public void setStudentRollNo(String rollNo){model.setRollNo(rollNo);      }public String getStudentRollNo(){return model.getRollNo();     }public void updateView(){                view.printStudentDetails(model.getName(), model.getRollNo());}    
}
  1. 使用 StudentController 方法来演示 MVC 设计模式的用法
    MVCPatternDemo.java
java">public class MVCPatternDemo {public static void main(String[] args) {//从数据可获取学生记录Student model  = retriveStudentFromDatabase();//创建一个视图:把学生详细信息输出到控制台StudentView view = new StudentView();StudentController controller = new StudentController(model, view);controller.updateView();//更新模型数据controller.setStudentName("John");controller.updateView();}private static Student retriveStudentFromDatabase(){Student student = new Student();student.setName("Robert");student.setRollNo("10");return student;}
}

编译运行以上 Java 范例,输出结果如下

java">Student: 
Name: Robert
Roll No: 10
Student: 
Name: John
Roll No: 10

业务代表模式(Business Delegate Pattern)

业务代表模式(Business Delegate Pattern)用于对表示层和业务层解耦

业务代表模式用来减少通信或对表示层代码中的业务层代码的远程查询功能

在业务层中我们有以下实体:

java">客户端(Client- 表示层代码可以是 JSP、servlet 或 UI java 代码
业务代表(Business Delegate- 一个为客户端实体提供的入口类,它提供了对业务服务方法的访问
查询服务(LookUp Service- 查找服务对象负责获取相关的业务实现,并提供业务对象对业务代表对象的访问
业务服务(Business Service- 业务服务接口。实现了该业务服务的实体类,提供了实际的业务实现逻辑

实现
1、 创建Client、BusinessDelegate、BusinessService、LookUpService、JMSService和EJBService来表示业务代表模式中的各种实体;
2、 定义类BusinessDelegatePatternDemo使用BusinessDelegate和Client来演示业务代表模式的用法;

范例

  1. 创建 BusinessService 接口
    BusinessService.java
java">public interface BusinessService {public void doProcessing();
}
  1. 创建实体服务类
    EJBService.java
java">public class EJBService implements BusinessService {@Overridepublic void doProcessing() {System.out.println("Processing task by invoking EJB Service");}
}

JMSService.java

java">public class JMSService implements BusinessService {@Overridepublic void doProcessing() {System.out.println("Processing task by invoking JMS Service");}
}
  1. 创建业务查询服务
    BusinessLookUp.java
java">public class BusinessLookUp {public BusinessService getBusinessService(String serviceType){if(serviceType.equalsIgnoreCase("EJB")){return new EJBService();}else {return new JMSService();}}
}
  1. 创建业务代表
    BusinessDelegate.java
java">public class BusinessDelegate {private BusinessLookUp lookupService = new BusinessLookUp();private BusinessService businessService;private String serviceType;public void setServiceType(String serviceType){this.serviceType = serviceType;}public void doTask(){businessService = lookupService.getBusinessService(serviceType);businessService.doProcessing();       }
}
  1. 创建客户端
    Client.java
java">public class Client {BusinessDelegate businessService;public Client(BusinessDelegate businessService){this.businessService  = businessService;}public void doTask(){        businessService.doTask();}
}
  1. 使用 BusinessDelegate 和 Client 类来演示业务代表模式
    BusinessDelegatePatternDemo.java
java">public class BusinessDelegatePatternDemo {public static void main(String[] args) {BusinessDelegate businessDelegate = new BusinessDelegate();businessDelegate.setServiceType("EJB");Client client = new Client(businessDelegate);client.doTask();businessDelegate.setServiceType("JMS");client.doTask();}
}

编译运行以上 Java 范例,输出结果如下

java">Processing task by invoking EJB Service
Processing task by invoking JMS Service

组合实体模式 (Composite Entity Pattern)

组合实体模式(Composite Entity Pattern)用在 EJB 持久化机制中

一个组合实体是一个 EJB 实体 bean,代表了对象的图解

当更新一个组合实体时,内部依赖对象 beans 会自动更新,因为它们是由 EJB 实体 bean 管理的

以下是组合实体 bean 的参与者:

java">组合实体(Composite Entity- 它是主要的实体 bean。它可以是粗粒的,或者可以包含一个粗粒度对象,用于持续生命周期
粗粒度对象(Coarse-Grained Object- 该对象包含依赖对象。它有自己的生命周期,也能管理依赖对象的生命周期
依赖对象(Dependent Object- 依赖对象是一个持续生命周期依赖于粗粒度对象的对象
策略(Strategies- 策略表示如何实现组合实体

实现
1、 定义作为组合实体的CompositeEntity对象;
2、 定义CoarseGrainedObject是一个包含依赖对象的类;
3、 定义类CompositeEntityPatternDemo使用Client类来演示组合实体模式的用法;

范例

  1. 创建依赖对象
    DependentObject1.java
java">public class DependentObject1 {private String data;public void setData(String data){this.data = data; } public String getData(){return data;}
}

DependentObject2.java

java">public class DependentObject2 {private String data;public void setData(String data){this.data = data; } public String getData(){return data;}
}
  1. 创建粗粒度对象
    CoarseGrainedObject.java
java">public class CoarseGrainedObject {DependentObject1 do1 = new DependentObject1();DependentObject2 do2 = new DependentObject2();public void setData(String data1, String data2){do1.setData(data1);do2.setData(data2);}public String[] getData(){return new String[] {do1.getData(),do2.getData()};}
}
  1. 创建组合实体
    CompositeEntity.java
java">public class CompositeEntity {private CoarseGrainedObject cgo = new CoarseGrainedObject();public void setData(String data1, String data2){cgo.setData(data1, data2);}public String[] getData(){return cgo.getData();}
}
  1. 创建使用组合实体的客户端类
    Client.java
java">public class Client {private CompositeEntity compositeEntity = new CompositeEntity();public void printData(){for (int i = 0; i < compositeEntity.getData().length; i++) {System.out.println("Data: " + compositeEntity.getData()[i]);}}public void setData(String data1, String data2){compositeEntity.setData(data1, data2);}
}
  1. 使用 Client 来演示组合实体设计模式的用法
    CompositeEntityPatternDemo.java
java">public class CompositeEntityPatternDemo {public static void main(String[] args) {Client client = new Client();client.setData("Test", "Data");client.printData();client.setData("Second Test", "Data1");client.printData();}
}

编译运行以上 Java 范例,输出结果如下

java">Data: Test
Data: Data
Data: Second Test
Data: Data1

数据访问对象模式 ( Data Access Object )

数据访问对象模式(Data Access Object Pattern)或 DAO 模式用于把低级的数据访问 API 或操作从高级的业务服务中分离出来

数据访问模式涉及到的参与者有:

java">数据访问对象接口(Data Access Object Interface- 该接口定义了在一个模型对象上要执行的标准操作
数据访问对象实体类(Data Access Object concrete class- 该类实现了上述的接口。该类负责从数据源获取数据,数据源可以是数据库,也可以是 xml,或者是其他的存储机制
模型对象/数值对象(Model Object/Value Object- 该对象是简单的 POJO,包含了 get/set 方法来存储通过使用 DAO 类检索到的数据

实现
1、 创建一个作为模型对象或数值对象的Student对象;
2、 定义StudentDao作为数据访问对象接口;
3、 定义StudentDaoImpl实现了数据访问对象接口的实体类;
4、 定义DaoPatternDemo使用StudentDao来演示数据访问对象模式的用法;

范例

  1. 创建数值对象
    Student.java
java">public class Student {private String name;private int rollNo;Student(String name, int rollNo){this.name = name;this.rollNo = rollNo;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getRollNo() {return rollNo;}public void setRollNo(int rollNo) {this.rollNo = rollNo;}
}
  1. 创建数据访问对象接口
    StudentDao.java
java">public interface StudentDao {public List<Student> getAllStudents();public Student getStudent(int rollNo);public void updateStudent(Student student);public void deleteStudent(Student student);
}
  1. 创建实现了上述接口的实体类
    StudentDaoImpl.java
java">public class StudentDaoImpl implements StudentDao {//列表是当作一个数据库List<Student> students;public StudentDaoImpl(){students = new ArrayList<Student>();Student student1 = new Student("Robert",0);Student student2 = new Student("John",1);students.add(student1);students.add(student2);       }@Overridepublic void deleteStudent(Student student) {students.remove(student.getRollNo());System.out.println("Student: Roll No " + student.getRollNo() +", deleted from database");}//从数据库中检索学生名单@Overridepublic List<Student> getAllStudents() {return students;}@Overridepublic Student getStudent(int rollNo) {return students.get(rollNo);}@Overridepublic void updateStudent(Student student) {students.get(student.getRollNo()).setName(student.getName());System.out.println("Student: Roll No " + student.getRollNo() +", updated in the database");}
}
  1. 使用 StudentDao 来演示数据访问对象模式的用法
    CompositeEntityPatternDemo.java
java">public class DaoPatternDemo {public static void main(String[] args) {StudentDao studentDao = new StudentDaoImpl();//输出所有的学生for (Student student : studentDao.getAllStudents()) {System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");}//更新学生Student student =studentDao.getAllStudents().get(0);student.setName("Michael");studentDao.updateStudent(student);//获取学生studentDao.getStudent(0);System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");      }
}

编译运行以上范例,输出结果如下

java">Student: [RollNo : 0, Name : Robert ]
Student: [RollNo : 1, Name : John ]
Student: Roll No 0, updated in the database
Student: [RollNo : 0, Name : Michael ]

前端控制器模式(Front Controller Pattern)

前端控制器模式(Front Controller Pattern)是用来提供一个集中的请求处理机制,所有的请求都将由一个单一的处理程序处理

该处理程序可以做认证/授权/记录日志,或者跟踪请求,然后把请求传给相应的处理程序

前端控制器模式涉及以下实体

java">前端控制器(Front Controller- 处理应用程序所有类型请求的单个处理程序,应用程序可以是基于 web 的应用程序,也可以是基于桌面的应用程序。
调度器(Dispatcher- 前端控制器可能使用一个调度器对象来调度请求到相应的具体处理程序。
视图(View- 视图是为请求而创建的对象。

实现
1、 定义类FrontController、Dispatcher分别当作前端控制器和调度器;
2、 定义类HomeView和StudentView表示作为前端控制器接收到的请求而创建的视图;
3、 定义类FrontControllerPatternDemo使用FrontController演示前端控制器设计模式;

范例

  1. 创建视图
    HomeView.java
java">public class HomeView {public void show(){System.out.println("Displaying Home Page");}
}

StudentView.java

java">public class StudentView {public void show(){System.out.println("Displaying Student Page");}
}
  1. 创建调度器 Dispatcher
    Dispatcher.java
java">public class Dispatcher {private StudentView studentView;private HomeView homeView;public Dispatcher(){studentView = new StudentView();homeView = new HomeView();}public void dispatch(String request){if(request.equalsIgnoreCase("STUDENT")){studentView.show();}else{homeView.show();} }
}
  1. 创建前端控制器 FrontController
    Context.java
java">public class FrontController {private Dispatcher dispatcher;public FrontController(){dispatcher = new Dispatcher();}private boolean isAuthenticUser(){System.out.println("User is authenticated successfully.");return true;}private void trackRequest(String request){System.out.println("Page requested: " + request);}public void dispatchRequest(String request){//记录每一个请求trackRequest(request);//对用户进行身份验证if(isAuthenticUser()){dispatcher.dispatch(request);} }
}
  1. 使用 FrontController 来演示前端控制器设计模式
    FrontControllerPatternDemo.java
java">public class FrontControllerPatternDemo {public static void main(String[] args) {FrontController frontController = new FrontController();frontController.dispatchRequest("HOME");frontController.dispatchRequest("STUDENT");}
}

编译运行以上 Java 范例,输出结果如下

java">Page requested: HOME
User is authenticated successfully.
Displaying Home Page
Page requested: STUDENT
User is authenticated successfully.
Displaying Student Page

拦截过滤器模式 ( Intercepting Filter )

拦截过滤器模式(Intercepting Filter Pattern)用于对应用程序的请求或响应做一些预处理/后处理

定义过滤器,并在把请求传给实际目标应用程序之前应用在请求上

过滤器可以做认证/授权/记录日志,或者跟踪请求,然后把请求传给相应的处理程序

拦截过滤器模式涉及以下实体:

java">过滤器(Filter- 过滤器在请求处理程序执行请求之前或之后,执行某些任务。
过滤器链(Filter Chain- 过滤器链带有多个过滤器,并在 Target 上按照定义的顺序执行这些过滤器。
Target - Target 对象是请求处理程序。
过滤管理器(Filter Manager- 过滤管理器管理过滤器和过滤器链。
客户端(Client- Client 是向 Target 对象发送请求的对象。

实现
1、 定义类FilterChain、FilterManager、Target、Client作为表示实体的各种对象;
2、 定义类AuthenticationFilter和DebugFilter表示实体过滤器;
3、 定义类InterceptingFilterDemo使用Client来演示拦截过滤器设计模式;

范例

  1. 创建过滤器接口 Filter
    Filter.java
java">public interface Filter {public void execute(String request);
}
  1. 创建实体过滤器
    AuthenticationFilter.java
java">public class AuthenticationFilter implements Filter {public void execute(String request){System.out.println("Authenticating request: " + request);}
}

DebugFilter.java

java">public class DebugFilter implements Filter {public void execute(String request){System.out.println("request log: " + request);}
}
  1. 创建 Target
    Target.java
java">public class Target {public void execute(String request){System.out.println("Executing request: " + request);}
}
  1. 创建过滤器链
    FilterChain.java
java">public class FilterChain {private List<Filter> filters = new ArrayList<Filter>();private Target target;public void addFilter(Filter filter){filters.add(filter);}public void execute(String request){for (Filter filter : filters) {filter.execute(request);}target.execute(request);}public void setTarget(Target target){this.target = target;}
}
  1. 创建过滤管理器
    FilterManager.java
java">public class FilterManager {FilterChain filterChain;public FilterManager(Target target){filterChain = new FilterChain();filterChain.setTarget(target);}public void setFilter(Filter filter){filterChain.addFilter(filter);}public void filterRequest(String request){filterChain.execute(request);}
}
  1. 创建客户端 Client
    Client.java
java">public class Client {FilterManager filterManager;public void setFilterManager(FilterManager filterManager){this.filterManager = filterManager;}public void sendRequest(String request){filterManager.filterRequest(request);}
}
  1. 使用 Client 来演示拦截过滤器设计模式
    FrontControllerPatternDemo.java
java">public class InterceptingFilterDemo {public static void main(String[] args) {FilterManager filterManager = new FilterManager(new Target());filterManager.setFilter(new AuthenticationFilter());filterManager.setFilter(new DebugFilter());Client client = new Client();client.setFilterManager(filterManager);client.sendRequest("HOME");}
}

编译运行以上 Java 范例,输出结果如下

java">Authenticating request: HOME
request log: HOME
Executing request: HOME

服务定位器模式 (Service Locator Pattern)

服务定位器模式(Service Locator Pattern)用于想使用 JNDI 查询定位各种服务的时候

考虑到为某个服务查找 JNDI 的代价很高,服务定位器模式充分利用了缓存技术

在首次请求某个服务时,服务定位器在 JNDI 中查找服务,并缓存该服务对象

当再次请求相同的服务时,服务定位器会在它的缓存中查找,这样可以在很大程度上提高应用程序的性能

以下是这种设计模式的实体

java">服务(Service- 实际处理请求的服务。对这种服务的引用可以在 JNDI 服务器中查找到
Context / 初始的 Context - JNDI Context 带有对要查找的服务的引用
服务定位器(Service Locator- 服务定位器是通过 JNDI 查找和缓存服务来获取服务的单点接触
缓存(Cache- 缓存存储服务的引用,以便复用它们
客户端(Client- Client 是通过 ServiceLocator 调用服务的对象

实现
创建 ServiceLocator 、 InitialContext 、 Cache 、 Service 作为表示实体的各种对象

Service1 和 Service2 表示实体服务

ServiceLocatorPatternDemo ,我们的演示类在这里是作为一个客户端,将使用 ServiceLocator 来演示服务定位器设计模式
范例

  1. 创建服务接口 Service
java">public interface Service
{public String getName();public void execute();
}
  1. 创建实体服务
    Service1
java">public class Service1 implements Service {public void execute(){System.out.println("Executing Service1");}@Overridepublic String getName() {return "Service1";}
}

Service2

java">public class Service2 implements Service {public void execute(){System.out.println("Executing Service2");}@Overridepublic String getName() {return "Service2";}
}
  1. 为 JNDI 查询创建 InitialContext
java">public class InitialContext
{public Object lookup(String jndiName){if(jndiName.equalsIgnoreCase("SERVICE1")){System.out.println("Looking up and creating a new Service1 object");return new Service1();}else if (jndiName.equalsIgnoreCase("SERVICE2")){System.out.println("Looking up and creating a new Service2 object");return new Service2();}return null;      }
}
  1. 创建缓存 Cache
java">public class Cache {private List<Service> services;public Cache(){services = new ArrayList<Service>();}public Service getService(String serviceName){for (Service service : services) {if(service.getName().equalsIgnoreCase(serviceName)){System.out.println("Returning cached  "+serviceName+" object");return service;}}return null;}public void addService(Service newService){boolean exists = false;for (Service service : services) {if(service.getName().equalsIgnoreCase(newService.getName())){exists = true;}}if(!exists){services.add(newService);}}
}
  1. 创建服务定位器 ServiceLocator
java">public class ServiceLocator {private static Cache cache;static {cache = new Cache();      }public static Service getService(String jndiName){Service service = cache.getService(jndiName);if(service != null){return service;}InitialContext context = new InitialContext();Service service1 = (Service)context.lookup(jndiName);cache.addService(service1);return service1;}
}
  1. 使用 ServiceLocator 来演示服务定位器设计模式
java">public class ServiceLocatorPatternDemo
{public static void main(String[] args) {Service service = ServiceLocator.getService("Service1");service.execute();service = ServiceLocator.getService("Service2");service.execute();service = ServiceLocator.getService("Service1");service.execute();service = ServiceLocator.getService("Service2");service.execute();        }
}

编译运行以上 Java 范例,输出结果如下

java">Looking up and creating a new Service1 object
Executing Service1
Looking up and creating a new Service2 object
Executing Service2
Returning cached  Service1 object
Executing Service1
Returning cached  Service2 object
Executing Service2

传输对象模式 ( Transfer Object Pattern )

传输对象模式(Transfer Object Pattern)用于从客户端向服务器一次性传递带有多个属性的数据

传输对象也被称为数值对象,没有任何行为

传输对象是一个具有 getter/setter 方法的简单的 POJO 类,它是可序列化的,所以它可以通过网络传输

服务器端的业务类通常从数据库读取数据,然后填充 POJO,并把它发送到客户端或按值传递它

对于客户端,传输对象是只读的

客户端可以创建自己的传输对象,并把它传递给服务器,以便一次性更新数据库中的数值

以下是这种设计模式的实体:

java">业务对象(Business Object- 为传输对象填充数据的业务服务
传输对象(Transfer Object- 简单的 POJO,只有设置/获取属性的方法
客户端(Client- 客户端可以发送请求或者发送传输对象到业务对象

实现
创建一个作为业务对象的 StudentBO 和作为传输对象的 StudentVO ,它们都代表了我们的实体

TransferObjectPatternDemo ,我们的演示类在这里是作为一个客户端,将使用 StudentBO 和 Student 来演示传输对象设计模式
范例

  1. 创建传输对象 StudentVO
java">public class StudentVO
{private String name;private int rollNo;StudentVO(String name, int rollNo){this.name = name;this.rollNo = rollNo;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getRollNo() {return rollNo;}public void setRollNo(int rollNo) {this.rollNo = rollNo;}
}
  1. 创建业务对象 StudentBO
java">public class StudentBO {//列表是当作一个数据库List<StudentVO> students;public StudentBO(){students = new ArrayList<StudentVO>();StudentVO student1 = new StudentVO("Robert",0);StudentVO student2 = new StudentVO("John",1);students.add(student1);students.add(student2);       }public void deleteStudent(StudentVO student) {students.remove(student.getRollNo());System.out.println("Student: Roll No " + student.getRollNo() +", deleted from database");}//从数据库中检索学生名单public List<StudentVO> getAllStudents() {return students;}public StudentVO getStudent(int rollNo) {return students.get(rollNo);}public void updateStudent(StudentVO student) {students.get(student.getRollNo()).setName(student.getName());System.out.println("Student: Roll No " + student.getRollNo() +", updated in the database");}
}
  1. 使用 StudentBO 来演示传输对象设计模式
java">public class TransferObjectPatternDemo {public static void main(String[] args) {StudentBO studentBusinessObject = new StudentBO();//输出所有的学生for (StudentVO student : studentBusinessObject.getAllStudents()) {System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");}//更新学生StudentVO student =studentBusinessObject.getAllStudents().get(0);student.setName("Michael");studentBusinessObject.updateStudent(student);//获取学生studentBusinessObject.getStudent(0);System.out.println("Student: [RollNo : "+student.getRollNo()+", Name : "+student.getName()+" ]");}
}

编译运行以上 Java 范例,输出结果如下

java">Student: [RollNo : 0, Name : Robert ]
Student: [RollNo : 1, Name : John ]
Student: Roll No 0, updated in the database
Student: [RollNo : 0, Name : Michael ]

http://www.ppmy.cn/news/1450612.html

相关文章

C语言-嵌入式-STM32:有哪些接口协议?

STM32微控制器支持多种接口协议以适应不同的通信需求&#xff0c;以下是一些常见的接口协议&#xff1a; USART/UART (Universal Synchronous/Asynchronous Receiver-Transmitter): USART 是同步或异步串行通信接口&#xff0c;常用于设备与PC之间的简单数据传输&#xff0c;如…

社交媒体数据恢复:Tandem

Tandem数据恢复方法 1. 概述 Tandem 是致力於提供語言學習者和母語者交流的語言交換app&#xff0c;已發行iOS及Android版本。 使用者可以透過文字或者語音對談找到語言交換對象。 該應用程序於2020年4月支援超過160種語言&#xff0c;其中包含12種手語。 2. 操作步骤 2.1.…

websocket全局封装使用

WebSocket对象的创建 WebSocket对象的关闭 启用心跳机制&#xff0c;避免断连 消息推送&#xff0c;接收到消息后进行业务逻辑处理 重连机制&#xff0c;如果断连后尝试一定次数的重连&#xff0c;超过最大次数后仍然失败则关闭连接 调用案例如下&#xff1a; const socketMana…

llamaindex 中GPTVectorStoreIndex 和 VectorStoreIndex区别

在 llama_index 库中,GPTVectorStoreIndex 和 VectorStoreIndex 都是用于创建向量存储索引的类,但它们在某些方面有所不同。 底层模型: GPTVectorStoreIndex 使用 GPT (Generative Pre-trained Transformer) 模型来生成文本的向量表示。它利用 GPT 模型的上下文理解能力来捕获…

centos学习-压缩和解压缩命令

CentOS 压缩与解压缩命令详解 在CentOS操作系统中&#xff0c;压缩和解压缩命令是极为常用的工具&#xff0c;用于对文件进行打包、压缩和解压缩操作。这些命令能够方便地处理大量的文件&#xff0c;使其更易于拷贝、移动和存储。本文将详细介绍CentOS中常见的压缩解压缩命令的…

身份证号对应地区信息-MySQL

这里写自定义目录标题 MySQL表结构MySQL表对应数据 MySQL表结构 CREATE TABLE idcard_contrast (code varchar(2000) NOT NULL COMMENT 身份证前六位,value varchar(3000) DEFAULT NULL COMMENT 对应地址 ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COMMENT身份证对照表;MySQL表对…

Java虚拟机(JVM)之字节码文件

让我们先来简单了解一下JVM。 JVM功能&#xff1a; 1、解释和运行&#xff1a;对字节码文件中的指令&#xff0c;实时的解释成机器码让计算机执行。 2、内存管理&#xff1a;自动为对象、方法等分配内存&#xff1b;自动的垃圾回收机制&#xff0c;回收不再使用的对象。 3、即…

Linux专栏07:Linux基本指令之文件搜索指令

博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;Linux专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ Linux基本指令之文件搜索指令 编号&#xff1a;07 文章目录 Linux基…