Hibernate实战(第二版)笔记----第四章--映射持久化类

2024-06-17 05:48

本文主要是介绍Hibernate实战(第二版)笔记----第四章--映射持久化类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、本章主要介绍了


实体类型: 


该类的实例有OID,一个实例对应表的一条记录,实例的OID就是该记录的主键。 
一个实例可以被多个其他实体对象共享引用。 有独立的生命周期。可以被单独持久化。 


值类型 :没有OID,不能被单独持久化,只能附属到一个依赖对象上,只能被依赖对象引用,有该依赖对象负责其生命周期。(没有OID就是没有主键,当然不能insert到表中了)。 


一句话: 


实体类型,在DB中代表一个表,一个实体代表一行记录;

值类型在DB中没有表,只代表一个column。 


对象模型(域模型)有具体的程序代码写成的,为了提高代码的重用性,可能会把域模型拆分定义成多个类,在这多个类中,那些包含了主键的成员的类就是entity,它的OID对应的就是表中的主键,它可以直接单独insert到表中;而那些只对应包含非主键的成员变量的类,就是值类.值类作为成员变量定义在entity类中,持久化entity类时,entity实例被保存成一个row,它的值类成员被保存成row的column。


几种键


键: 键是唯一标识一个实体的一个或者多个数据属性。在物理数据库中,键可以由表的一个或者多个列组成,它们的值唯一标识关系表中的一行。


复合键: 由两个或者多个属性组成的键。


自然键: 由现实世界中已经存在的属性组成的键。例如,美国公民被分配了一个唯一(不保证一定正确,但实际上非常接近唯一)的社会保险号(SSN)。如果隐私法允许的话,SSN可能被用作Person实体的自然键(假设组织的人员范围仅限于美国)。


代理键: 完全没有商业含义,通常由当下的系统自动生成,都是单键。


自然键: 已经真实存在的键,通常具有商业含义,比如身份证ID,护照编码等等,可以是单键,也可以是复合键。


候选键: 在逻辑数据模型中的实体类型可能具有0或多个候选键,简称为唯一标识(注解:某些人不主张在逻辑数据模型中标识候选键,因此没有固定标准)。例如,假设我们只涉及美国公民,那么SSN是Person实体类型的一个候选键,同时姓名与电话号码的组合(假设组合是唯一的)是第二个可能的候选键。这两个键都被称作候选键是因为它们是物理数据模型中主键、次键或者非键的候选目标。

主键: 实体类型的首选键。


备用键: 也就是次键,是表中行的另一个唯一标识。


外键: 在一个实体类型中表示另一个实体类型的主键或者次键的一个或多个属性。


详解介绍参考这:https://ask.hellobi.com/blog/rayshawn/3257



二、代码


一些实体类:




其中User类中使用了作为包级别元数据配置的Hibernate标识符生成器:


package org.jpwh.model.advanced;import org.jpwh.model.Constants;import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;@Entity
@Table(name = "USERS")
public class User {@Id@GeneratedValue(generator = Constants.ID_GENERATOR)protected Long id;public Long getId() {return id;}protected Address address;public Address getAddress() {return address;}public void setAddress(Address address) {this.address = address;}
}


ID_GENERATOR定义为:


/model/src/main/java/org/jpwh/model/package-info.java

@org.hibernate.annotations.GenericGenerator(name = "ID_GENERATOR",strategy = "enhanced-sequence",parameters = {@org.hibernate.annotations.Parameter(name = "sequence_name",value = "JPWH_SEQUENCE"),@org.hibernate.annotations.Parameter(name = "initial_value",value = "1000")
})
package org.jpwh.model;

而ItemBidSummary类则使用了子查询映射:

package org.jpwh.model.advanced;import javax.persistence.Entity;
import javax.persistence.Id;@Entity
@org.hibernate.annotations.Immutable
@org.hibernate.annotations.Subselect(value = "select i.ID as ITEMID, i.ITEM_NAME as NAME, " +"count(b.ID) as NUMBEROFBIDS " +"from ITEM i left outer join BID b on i.ID = b.ITEM_ID " +"group by i.ID, i.ITEM_NAME"
)// TODO Table names are case sensitive, Hibernate bug HHH-8430
@org.hibernate.annotations.Synchronize({"Item", "Bid"})
public class ItemBidSummary {@Idprotected Long itemId;protected String name;protected long numberOfBids;public ItemBidSummary() {}// Getter methods...public Long getItemId() {return itemId;}public String getName() {return name;}public long getNumberOfBids() {return numberOfBids;}// ...
}


测试类:


/examples/src/test/java/org/jpwh/test/advanced/MappedSubselect.java

package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Bid;
import org.jpwh.model.advanced.Item;
import org.jpwh.model.advanced.ItemBidSummary;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;import static org.testng.Assert.assertEquals;//映射子查询
public class MappedSubselect extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void loadSubselectEntity() throws Exception {long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();{ItemBidSummary itemBidSummary = em.find(ItemBidSummary.class, ITEM_ID);// select * from (//      select i.ID as ITEMID, i.ITEM_NAME as NAME, ...// ) where ITEMID = ?assertEquals(itemBidSummary.getName(), "AUCTION: Some item");}em.clear();{ // Hibernate将在查询之前同步正确的表Item item = em.find(Item.class, ITEM_ID);item.setName("New name");// 在检索标识符之前不刷新!// ItemBidSummary itemBidSummary = em.find(ItemBidSummary.class, ITEM_ID);// 如果同步表受影响,在查询之前自动刷新。Query query = em.createQuery("select ibs from ItemBidSummary ibs where ibs.itemId = :id");ItemBidSummary itemBidSummary =(ItemBidSummary)query.setParameter("id", ITEM_ID).getSingleResult();assertEquals(itemBidSummary.getName(), "AUCTION: New name");}tx.commit();em.close();} finally {TM.rollback();}}public Long storeItemAndBids() throws Exception {UserTransaction tx = TM.getUserTransaction();tx.begin();EntityManager em = JPA.createEntityManager();Item item = new Item();item.setName("Some item");item.setDescription("This is some description.");em.persist(item);for (int i = 1; i <= 3; i++) {Bid bid = new Bid();bid.setAmount(new BigDecimal(10 + i));bid.setItem(item);em.persist(bid);}tx.commit();em.close();return item.getId();}}

/examples/src/test/java/org/jpwh/test/advanced/AccessType.java
package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;import static org.testng.Assert.assertEquals;public class AccessType extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadAccessType() throws Exception {UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item someItem = new Item();someItem.setName("Some item");someItem.setDescription("This is some description.");em.persist(someItem);tx.commit();em.close();Long ITEM_ID = someItem.getId();tx.begin();em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);assertEquals(item.getName(), "AUCTION: Some item");tx.commit();em.close();} finally {TM.rollback();}}}


/examples/src/test/java/org/jpwh/test/advanced/BooleanOverride.java

package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;import static org.testng.Assert.assertTrue;public class BooleanOverride extends JPATest {@BeforeClass@java.lang.Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadOverride() throws Exception {UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item someItem = new Item();someItem.setName("Some item");someItem.setDescription("This is some description.");someItem.setVerified(true);em.persist(someItem);tx.commit();em.close();Long ITEM_ID = someItem.getId();tx.begin();em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);assertTrue(item.isVerified());tx.commit();em.close();} finally {TM.rollback();}}}


/examples/src/test/java/org/jpwh/test/advanced/DerivedProperties.java

package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Bid;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;import static org.testng.Assert.assertEquals;//派生属性
public class DerivedProperties extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadFormula() throws Exception {long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);assertEquals(item.getShortDescription(), "This is some...");tx.commit();em.close();} finally {TM.rollback();}}@Testpublic void storeLoadFormulaSubselect() throws Exception {long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);assertEquals(item.getAverageBidAmount().compareTo(new BigDecimal("12")), 0);tx.commit();em.close();} finally {TM.rollback();}}public Long storeItemAndBids() throws Exception {UserTransaction tx = TM.getUserTransaction();tx.begin();EntityManager em = JPA.createEntityManager();Item item = new Item();item.setName("Some item");item.setDescription("This is some description.");em.persist(item);for (int i = 1; i <= 3; i++) {Bid bid = new Bid();bid.setAmount(new BigDecimal(10 + i));bid.setItem(item);em.persist(bid);}tx.commit();em.close();return item.getId();}}

/examples/src/test/java/org/jpwh/test/advanced/GeneratedProperties.java

package org.jpwh.test.advanced;import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.jpwh.env.DatabaseProduct;
import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Bid;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;import static org.testng.Assert.*;//生成的属性
public class GeneratedProperties extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Overridepublic void afterJPABootstrap() throws Exception {if (!TM.databaseProduct.equals(DatabaseProduct.H2)) return;// LASTMODIFIED测试显示数据库触发器如何生成属性值,我们实际上需要一个触发器try (Session session = JPA.createEntityManager().unwrap(Session.class)) {session.doWork(new Work() {@Overridepublic void execute(Connection connection) throws SQLException {Statement stat = connection.createStatement();stat.execute("drop trigger if exists TRG_ITEM_LASTMODIFIED_INSERT");stat.execute("create trigger TRG_ITEM_LASTMODIFIED_INSERT after insert on ITEM" +" for each row call \"" + org.jpwh.shared.trigger.UpdateLastModifiedTrigger.class.getName() + "\"");stat.execute("drop trigger if exists TRG_ITEM_LASTMODIFIED_UPDATE");stat.execute("create trigger TRG_ITEM_LASTMODIFIED_UPDATE after update on ITEM" +" for each row call \"" + org.jpwh.shared.trigger.UpdateLastModifiedTrigger.class.getName() + "\"");stat.close();}});}}@Test(groups = {"H2"})public void storeLoadLastModified() throws Exception {long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);assertNotNull(item.getCreatedOn());Date lastModified = item.getLastModified();assertNotNull(lastModified);assertTrue(item.getCreatedOn().getTime() < lastModified.getTime());item.setDescription("Some modification.");em.flush();Date newLastModified = item.getLastModified();assertNotEquals(lastModified, newLastModified, "Modification time should have been updated");tx.commit();em.close();} finally {TM.rollback();}}@Testpublic void storeLoadInitialPrice() throws Exception {long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);tx.commit();em.close();assertEquals(item.getInitialPrice().compareTo(new BigDecimal("1")), 0);} finally {TM.rollback();}}public Long storeItemAndBids() throws Exception {UserTransaction tx = TM.getUserTransaction();tx.begin();EntityManager em = JPA.createEntityManager();Item item = new Item();item.setName("Some item");item.setDescription("This is some description.");em.persist(item);for (int i = 1; i <= 3; i++) {Bid bid = new Bid();bid.setAmount(new BigDecimal(10 + i));bid.setItem(item);em.persist(bid);}tx.commit();em.close();return item.getId();}}


/examples/src/test/java/org/jpwh/test/advanced/LazyProperties.java

package org.jpwh.test.advanced;import org.hibernate.Session;
import org.hibernate.engine.jdbc.StreamUtils;
import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.util.Random;import static org.testng.Assert.assertEquals;public class LazyProperties extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadProperties() throws Exception {UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item someItem = new Item();someItem.setName("Some item");someItem.setDescription("This is some description.");byte[] bytes = new byte[131072];new Random().nextBytes(bytes);someItem.setImage(bytes);em.persist(someItem);tx.commit();em.close();Long ITEM_ID = someItem.getId();tx.begin();em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);// Accessing one initializes ALL lazy properties in a single SELECTassertEquals(item.getDescription(), "This is some description.");assertEquals(item.getImage().length, 131072); // 128 kilobytestx.commit();em.close();} finally {TM.rollback();}}@Testpublic void storeLoadLocator() throws Exception {// TODO: This test fails on H2 standalone// http://groups.google.com/group/h2-database/browse_thread/thread/9c6f4893a62c9b1aUserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();byte[] bytes = new byte[131072];new Random().nextBytes(bytes);InputStream imageInputStream = new ByteArrayInputStream(bytes);int byteLength = bytes.length;Item someItem = new Item();someItem.setName("Some item");someItem.setDescription("This is some description.");// Need the native Hibernate APISession session = em.unwrap(Session.class);// You need to know the number of bytes you want to read from the stream!Blob blob = session.getLobHelper().createBlob(imageInputStream, byteLength);someItem.setImageBlob(blob);em.persist(someItem);tx.commit();em.close();Long ITEM_ID = someItem.getId();tx.begin();em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);// You can stream the bytes directly...InputStream imageDataStream = item.getImageBlob().getBinaryStream();// ... or materialize them into memory:ByteArrayOutputStream outStream = new ByteArrayOutputStream();StreamUtils.copy(imageDataStream, outStream);byte[] imageBytes = outStream.toByteArray();assertEquals(imageBytes.length, 131072);tx.commit();em.close();} finally {TM.rollback();}}}

/examples/src/test/java/org/jpwh/test/advanced/NestedComponents.java

package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Address;
import org.jpwh.model.advanced.City;
import org.jpwh.model.advanced.User;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import java.util.Locale;import static org.testng.Assert.assertEquals;//嵌套组件
public class NestedComponents extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeAndLoadUsers() throws Exception {UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();City city = new City();city.setZipcode("12345");city.setName("Some City");city.setCountry(Locale.GERMANY.getCountry());Address address = new Address();address.setStreet("Some Street 123");address.setCity(city);User userOne = new User();userOne.setAddress(address);em.persist(userOne);tx.commit();em.close();tx.begin();em = JPA.createEntityManager();User u = em.find(User.class, userOne.getId());assertEquals(u.getAddress().getStreet(), "Some Street 123");assertEquals(u.getAddress().getCity().getZipcode(), "12345");assertEquals(u.getAddress().getCity().getCountry(), Locale.GERMANY.getCountry());tx.commit();em.close();} finally {TM.rollback();}}}

/examples/src/test/java/org/jpwh/test/advanced/Temporal.java

package org.jpwh.test.advanced;import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;import static org.testng.Assert.*;//临时的
public class Temporal extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadTemporal() throws Exception {UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();Item someItem = new Item();someItem.setName("Some item");someItem.setDescription("This is some description.");// someItem.setReviewedOn(Instant.now().plusSeconds(60)); // A future timeem.persist(someItem);tx.commit();em.close();Long ITEM_ID = someItem.getId();Date ORIGINAL_CREATION_DATE = someItem.getCreatedOn();tx.begin();em = JPA.createEntityManager();Item item = em.find(Item.class, ITEM_ID);// java.util.Date and java.sql.Timestamp are not symmetric!assertFalse(item.getCreatedOn().equals(ORIGINAL_CREATION_DATE));assertFalse(item.getCreatedOn().getClass().equals(ORIGINAL_CREATION_DATE.getClass()));// 这是如何正确比较Java中的时间值...assertEquals(ORIGINAL_CREATION_DATE.getTime(), item.getCreatedOn().getTime());// 或者使用稍微令人讨厌但相当可怕的日历APICalendar oldDate = new GregorianCalendar();oldDate.setTime(ORIGINAL_CREATION_DATE);Calendar newDate = new GregorianCalendar();newDate.setTime(item.getCreatedOn());assertEquals(oldDate, newDate);// Or the Java 8 API// assertTrue(item.getReviewedOn().isAfter(item.getCreatedOn().toInstant()));tx.commit();em.close();} finally {TM.rollback();}}}

/examples/src/test/java/org/jpwh/test/advanced/TransformingColumns.java

package org.jpwh.test.advanced;import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import org.jpwh.env.JPATest;
import org.jpwh.model.advanced.Bid;
import org.jpwh.model.advanced.Item;
import org.testng.annotations.Test;import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;//转换列
public class TransformingColumns extends JPATest {@Overridepublic void configurePersistenceUnit() throws Exception {configurePersistenceUnit("AdvancedPU");}@Testpublic void storeLoadTransform() throws Exception {final long ITEM_ID = storeItemAndBids();UserTransaction tx = TM.getUserTransaction();try {tx.begin();EntityManager em = JPA.createEntityManager();{Item item = em.find(Item.class, ITEM_ID);assertEquals(item.getMetricWeight(), 2.0);final boolean[] tests = new boolean[1];em.unwrap(Session.class).doWork(new Work() {@Overridepublic void execute(Connection connection) throws SQLException {PreparedStatement statement = null;ResultSet result = null;try {statement = connection.prepareStatement("select IMPERIALWEIGHT from ITEM where ID = ?");statement.setLong(1, ITEM_ID);result = statement.executeQuery();while (result.next()) {Double imperialWeight = result.getDouble("IMPERIALWEIGHT");assertEquals(imperialWeight, 4.40924);tests[0] = true;}} finally {if (result != null)result.close();if (statement != null)statement.close();}}});assertTrue(tests[0]);}em.clear();{List<Item> result =em.createQuery("select i from Item i where i.metricWeight = :w").setParameter("w", 2.0).getResultList();assertEquals(result.size(), 1);}em.clear();tx.commit();em.close();} finally {TM.rollback();}}public Long storeItemAndBids() throws Exception {UserTransaction tx = TM.getUserTransaction();tx.begin();EntityManager em = JPA.createEntityManager();Item item = new Item();item.setName("Some item");item.setMetricWeight(2);item.setDescription("This is some description.");em.persist(item);for (int i = 1; i <= 3; i++) {Bid bid = new Bid();bid.setAmount(new BigDecimal(10 + i));bid.setItem(item);em.persist(bid);}tx.commit();em.close();return item.getId();}}


这篇关于Hibernate实战(第二版)笔记----第四章--映射持久化类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1068631

相关文章

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语

Java MQTT实战应用

《JavaMQTT实战应用》本文详解MQTT协议,涵盖其发布/订阅机制、低功耗高效特性、三种服务质量等级(QoS0/1/2),以及客户端、代理、主题的核心概念,最后提供Linux部署教程、Sprin... 目录一、MQTT协议二、MQTT优点三、三种服务质量等级四、客户端、代理、主题1. 客户端(Clien

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

深度解析Spring Boot拦截器Interceptor与过滤器Filter的区别与实战指南

《深度解析SpringBoot拦截器Interceptor与过滤器Filter的区别与实战指南》本文深度解析SpringBoot中拦截器与过滤器的区别,涵盖执行顺序、依赖关系、异常处理等核心差异,并... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实

MySQL中的索引结构和分类实战案例详解

《MySQL中的索引结构和分类实战案例详解》本文详解MySQL索引结构与分类,涵盖B树、B+树、哈希及全文索引,分析其原理与优劣势,并结合实战案例探讨创建、管理及优化技巧,助力提升查询性能,感兴趣的朋... 目录一、索引概述1.1 索引的定义与作用1.2 索引的基本原理二、索引结构详解2.1 B树索引2.2

从入门到精通MySQL 数据库索引(实战案例)

《从入门到精通MySQL数据库索引(实战案例)》索引是数据库的目录,提升查询速度,主要类型包括BTree、Hash、全文、空间索引,需根据场景选择,建议用于高频查询、关联字段、排序等,避免重复率高或... 目录一、索引是什么?能干嘛?核心作用:二、索引的 4 种主要类型(附通俗例子)1. BTree 索引(

Redis的持久化之RDB和AOF机制详解

《Redis的持久化之RDB和AOF机制详解》:本文主要介绍Redis的持久化之RDB和AOF机制,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述RDB(Redis Database)核心原理触发方式手动触发自动触发AOF(Append-Only File)核

Java Web实现类似Excel表格锁定功能实战教程

《JavaWeb实现类似Excel表格锁定功能实战教程》本文将详细介绍通过创建特定div元素并利用CSS布局和JavaScript事件监听来实现类似Excel的锁定行和列效果的方法,感兴趣的朋友跟随... 目录1. 模拟Excel表格锁定功能2. 创建3个div元素实现表格锁定2.1 div元素布局设计2.

Redis 配置文件使用建议redis.conf 从入门到实战

《Redis配置文件使用建议redis.conf从入门到实战》Redis配置方式包括配置文件、命令行参数、运行时CONFIG命令,支持动态修改参数及持久化,常用项涉及端口、绑定、内存策略等,版本8... 目录一、Redis.conf 是什么?二、命令行方式传参(适用于测试)三、运行时动态修改配置(不重启服务