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

相关文章

Redis事务与数据持久化方式

《Redis事务与数据持久化方式》该文档主要介绍了Redis事务和持久化机制,事务通过将多个命令打包执行,而持久化则通过快照(RDB)和追加式文件(AOF)两种方式将内存数据保存到磁盘,以防止数据丢失... 目录一、Redis 事务1.1 事务本质1.2 数据库事务与redis事务1.2.1 数据库事务1.

Golang使用minio替代文件系统的实战教程

《Golang使用minio替代文件系统的实战教程》本文讨论项目开发中直接文件系统的限制或不足,接着介绍Minio对象存储的优势,同时给出Golang的实际示例代码,包括初始化客户端、读取minio对... 目录文件系统 vs Minio文件系统不足:对象存储:miniogolang连接Minio配置Min

Node.js 中 http 模块的深度剖析与实战应用小结

《Node.js中http模块的深度剖析与实战应用小结》本文详细介绍了Node.js中的http模块,从创建HTTP服务器、处理请求与响应,到获取请求参数,每个环节都通过代码示例进行解析,旨在帮... 目录Node.js 中 http 模块的深度剖析与实战应用一、引言二、创建 HTTP 服务器:基石搭建(一

网页解析 lxml 库--实战

lxml库使用流程 lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 XPath表达式提供了良好的支 持,因此能够了高效地解析 HTML/XML 文档。本节讲解如何通过 lxml 库解析 HTML 文档。 pip install lxml lxm| 库提供了一个 etree 模块,该模块专门用来解析 HTML/XML 文档,下面来介绍一下 lxml 库

闲置电脑也能活出第二春?鲁大师AiNAS让你动动手指就能轻松部署

对于大多数人而言,在这个“数据爆炸”的时代或多或少都遇到过存储告急的情况,这使得“存储焦虑”不再是个别现象,而将会是随着软件的不断臃肿而越来越普遍的情况。从不少手机厂商都开始将存储上限提升至1TB可以见得,我们似乎正处在互联网信息飞速增长的阶段,对于存储的需求也将会不断扩大。对于苹果用户而言,这一问题愈发严峻,毕竟512GB和1TB版本的iPhone可不是人人都消费得起的,因此成熟的外置存储方案开

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

系统架构师考试学习笔记第三篇——架构设计高级知识(20)通信系统架构设计理论与实践

本章知识考点:         第20课时主要学习通信系统架构设计的理论和工作中的实践。根据新版考试大纲,本课时知识点会涉及案例分析题(25分),而在历年考试中,案例题对该部分内容的考查并不多,虽在综合知识选择题目中经常考查,但分值也不高。本课时内容侧重于对知识点的记忆和理解,按照以往的出题规律,通信系统架构设计基础知识点多来源于教材内的基础网络设备、网络架构和教材外最新时事热点技术。本课时知识

滚雪球学Java(87):Java事务处理:JDBC的ACID属性与实战技巧!真有两下子!

咦咦咦,各位小可爱,我是你们的好伙伴——bug菌,今天又来给大家普及Java SE啦,别躲起来啊,听我讲干货还不快点赞,赞多了我就有动力讲得更嗨啦!所以呀,养成先点赞后阅读的好习惯,别被干货淹没了哦~ 🏆本文收录于「滚雪球学Java」专栏,专业攻坚指数级提升,助你一臂之力,带你早日登顶🚀,欢迎大家关注&&收藏!持续更新中,up!up!up!! 环境说明:Windows 10