一、结构
二、Repository层
1.
package spittr.db; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import spittr.domain.Spitter; /**
* Repository interface with operations for {@link Spitter} persistence.
* @author habuma
*/
public interface SpitterRepository extends JpaRepository<Spitter, Long>, SpitterSweeper { Spitter findByUsername(String username); List<Spitter> findByUsernameOrFullNameLike(String username, String fullName); }
2.
package spittr.db; public interface SpitterSweeper { int eliteSweep(); }
3.
package spittr.db; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; public class SpitterRepositoryImpl implements SpitterSweeper { @PersistenceContext
private EntityManager em; public int eliteSweep() {
String update =
"UPDATE Spitter spitter " +
"SET spitter.status = 'Elite' " +
"WHERE spitter.status = 'Newbie' " +
"AND spitter.id IN (" +
"SELECT s FROM Spitter s WHERE (" +
" SELECT COUNT(spittles) FROM s.spittles spittles) > 10000" +
")";
return em.createQuery(update).executeUpdate();
} }
4.
package spittr.db; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import spittr.domain.Spittle; /**
* Repository interface with operations for {@link Spittle} persistence.
* @author habuma
*/
public interface SpittleRepository extends JpaRepository<Spittle, Long>, SpittleRepositoryCustom { List<Spittle> findBySpitterId(long spitterId); }
5.
package spittr.db; import java.util.List; import spittr.domain.Spittle; public interface SpittleRepositoryCustom { List<Spittle> findRecent(); List<Spittle> findRecent(int count); }
6.
package spittr.db; import java.util.List; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import spittr.domain.Spittle; public class SpittleRepositoryImpl implements SpittleRepositoryCustom { @PersistenceContext
private EntityManager entityManager; public List<Spittle> findRecent() {
return findRecent(10);
} public List<Spittle> findRecent(int count) {
return (List<Spittle>) entityManager.createQuery("select s from Spittle s order by s.postedTime desc")
.setMaxResults(count)
.getResultList();
} }
三、domain层
1.
package spittr.domain; import java.util.List; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany; @Entity
public class Spitter { private Spitter() {} @Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; @Column(name="username")
private String username; @Column(name="password")
private String password; @Column(name="fullname")
private String fullName; @Column(name="email")
private String email; @Column(name="updateByEmail")
private boolean updateByEmail; @Column(name="status")
private String status; @OneToMany(targetEntity=Spittle.class, fetch=FetchType.EAGER, mappedBy="spitter")
private List<Spittle> spittles; public Spitter(Long id, String username, String password, String fullName,
String email, boolean updateByEmail) {
this.id = id;
this.username = username;
this.password = password;
this.fullName = fullName;
this.email = email;
this.updateByEmail = updateByEmail;
this.status = "Newbie";
} public Long getId() {
return id;
} public String getUsername() {
return username;
} public String getPassword() {
return password;
} public String getFullName() {
return fullName;
} public String getEmail() {
return email;
} public boolean isUpdateByEmail() {
return updateByEmail;
} public String getStatus() {
return status;
} public List<Spittle> getSpittles() {
return spittles;
}
}
2.
package spittr.domain; import java.util.Date; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; @Entity
public class Spittle { @Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; @ManyToOne
@JoinColumn(name="spitter")
private Spitter spitter; @Column
private String message; @Column
private Date postedTime; private Spittle() {} public Spittle(Long id, Spitter spitter, String message, Date postedTime) {
this.id = id;
this.spitter = spitter;
this.message = message;
this.postedTime = postedTime;
} public Long getId() {
return this.id;
} public String getMessage() {
return this.message;
} public Date getPostedTime() {
return this.postedTime;
} public Spitter getSpitter() {
return this.spitter;
} }
四、配置文件及数据库文件
1.
package spittr.db; import javax.sql.DataSource; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; @Configuration
@EnableJpaRepositories(basePackages="spitter.db")
public class SpringDataJpaConfig { @Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.addScript("classpath:spitter/db/jpa/schema.sql")
.addScript("classpath:spitter/db/jpa/test-data.sql")
.build();
} @Bean
public JpaTransactionManager transactionManager() {
return new JpaTransactionManager(); // does this need an emf???
} @Bean
public HibernateJpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.H2);
adapter.setShowSql(false);
adapter.setGenerateDdl(true);
return adapter;
} @Bean
public Object emf() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(dataSource());
emf.setPersistenceUnitName("spitter");
emf.setJpaVendorAdapter(jpaVendorAdapter());
return emf;
} }
2.
package spittr.db.jpa; import javax.inject.Inject;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration
@EnableJpaRepositories(basePackages="spittr.db")
public class JpaConfig { @Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder edb = new EmbeddedDatabaseBuilder();
edb.setType(EmbeddedDatabaseType.H2);
edb.addScript("spittr/db/jpa/schema.sql");
edb.addScript("spittr/db/jpa/test-data.sql");
EmbeddedDatabase embeddedDatabase = edb.build();
return embeddedDatabase;
} @Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(dataSource);
emf.setPersistenceUnitName("spittr");
emf.setJpaVendorAdapter(jpaVendorAdapter);
emf.setPackagesToScan("spittr.domain");
return emf;
} @Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.H2);
adapter.setShowSql(true);
adapter.setGenerateDdl(false);
adapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
return adapter;
} @Configuration
@EnableTransactionManagement
public static class TransactionConfig { @Inject
private EntityManagerFactory emf; @Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
} }
3.RepositoryTest-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <jpa:repositories base-package="spittr.db" /> <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:persistenceUnitName="spitter"
p:jpaVendorAdapter-ref="jpaVendorAdapter" /> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="H2" />
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
</bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="emf" /> <jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="spittr/db/jpa/schema.sql" />
<jdbc:script location="spittr/db/jpa/test-data.sql" />
</jdbc:embedded-database> </beans>
4.schema.sql
drop table if exists spittle;
drop table if exists spitter; create table spitter (
id identity,
username varchar(25) not null,
password varchar(25) not null,
fullName varchar(100) not null,
email varchar(50) not null,
updateByEmail boolean not null,
status varchar(10) not null
); create table spittle (
id integer identity primary key,
spitter integer not null,
message varchar(2000) not null,
postedTime datetime not null,
foreign key (spitter) references spitter(id)
);
5.test-data.sql
insert into Spitter (username, password, fullname, email, updateByEmail, status) values ('habuma', 'password', 'Craig Walls', 'craig@habuma.com', false, 'Newbie');
insert into Spitter (username, password, fullname, email, updateByEmail, status) values ('mwalls', 'password', 'Michael Walls', 'mwalls@habuma.com', true, 'Newbie');
insert into Spitter (username, password, fullname, email, updateByEmail, status) values ('chuck', 'password', 'Chuck Wagon', 'chuck@habuma.com', false, 'Newbie');
insert into Spitter (username, password, fullname, email, updateByEmail, status) values ('artnames', 'password', 'Art Names', 'art@habuma.com', true, 'Newbie'); insert into Spittle (spitter, message, postedTime) values (1, 'This is a test spittle message', '2012-06-09 22:00:00Z');
insert into Spittle (spitter, message, postedTime) values (1, 'This is another test spittle message', '2012-06-09 22:10:00Z');
insert into Spittle (spitter, message, postedTime) values (1, 'This is a third test spittle message', '2012-07-04 23:30:00Z');
insert into Spittle (spitter, message, postedTime) values (2, 'Hello from Chuck!', '2012-03-25 12:15:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Hello from Art!', '2012-03-25 12:15:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Hello again from Art!', '2012-03-25 12:25:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Hola from Arthur!', '2012-03-25 12:35:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Buenos Dias from Art!', '2012-03-25 12:45:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Ni Hao from Art!', '2012-03-25 12:55:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Guten Tag from Art!', '2012-03-25 13:05:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Konnichi wa from Art!', '2012-03-25 13:15:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Buon giorno from Art!', '2012-03-25 13:25:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Bonjour from Art!', '2012-03-25 13:35:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'Aloha from Art!', '2012-03-25 13:45:00Z');
insert into Spittle (spitter, message, postedTime) values (4, 'God dag from Art!', '2012-03-25 13:55:00Z');
6.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n log4j.rootLogger=WARN,stdout log4j.category.org.hibernate=WARN
五、测试文件
1.
package spittr.db.jpa; import static org.junit.Assert.*; import java.util.List; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import spittr.db.SpitterRepository;
import spittr.db.SpringDataJpaConfig;
import spittr.domain.Spitter; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=SpringDataJpaConfig.class)
public class SpitterRepositoryTest { @Autowired
SpitterRepository spitterRepository; @Test
@Transactional
public void count() {
assertEquals(4, spitterRepository.count());
} @Test
@Transactional
public void findAll() {
List<Spitter> spitters = spitterRepository.findAll();
assertEquals(4, spitters.size());
assertSpitter(0, spitters.get(0));
assertSpitter(1, spitters.get(1));
assertSpitter(2, spitters.get(2));
assertSpitter(3, spitters.get(3));
} @Test
@Transactional
public void findByUsername() {
assertSpitter(0, spitterRepository.findByUsername("habuma"));
assertSpitter(1, spitterRepository.findByUsername("mwalls"));
assertSpitter(2, spitterRepository.findByUsername("chuck"));
assertSpitter(3, spitterRepository.findByUsername("artnames"));
} @Test
@Transactional
public void findOne() {
assertSpitter(0, spitterRepository.findOne(1L));
assertSpitter(1, spitterRepository.findOne(2L));
assertSpitter(2, spitterRepository.findOne(3L));
assertSpitter(3, spitterRepository.findOne(4L));
} @Test
@Transactional
public void save_newSpitter() {
assertEquals(4, spitterRepository.count());
Spitter spitter = new Spitter(null, "newbee", "letmein", "New Bee", "newbee@habuma.com", true);
Spitter saved = spitterRepository.save(spitter);
assertEquals(5, spitterRepository.count());
assertSpitter(4, saved);
assertSpitter(4, spitterRepository.findOne(5L));
} @Test
@Transactional
@Ignore
public void save_existingSpitter() {
assertEquals(4, spitterRepository.count());
Spitter spitter = new Spitter(4L, "arthur", "letmein", "Arthur Names", "arthur@habuma.com", false);
Spitter saved = spitterRepository.save(spitter);
assertSpitter(5, saved);
assertEquals(4, spitterRepository.count());
Spitter updated = spitterRepository.findOne(4L);
assertSpitter(5, updated);
} private static void assertSpitter(int expectedSpitterIndex, Spitter actual) {
assertSpitter(expectedSpitterIndex, actual, "Newbie");
} private static void assertSpitter(int expectedSpitterIndex, Spitter actual, String expectedStatus) {
Spitter expected = SPITTERS[expectedSpitterIndex];
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getUsername(), actual.getUsername());
assertEquals(expected.getPassword(), actual.getPassword());
assertEquals(expected.getFullName(), actual.getFullName());
assertEquals(expected.getEmail(), actual.getEmail());
assertEquals(expected.isUpdateByEmail(), actual.isUpdateByEmail());
} private static Spitter[] SPITTERS = new Spitter[6]; @BeforeClass
public static void before() {
SPITTERS[0] = new Spitter(1L, "habuma", "password", "Craig Walls", "craig@habuma.com", false);
SPITTERS[1] = new Spitter(2L, "mwalls", "password", "Michael Walls", "mwalls@habuma.com", true);
SPITTERS[2] = new Spitter(3L, "chuck", "password", "Chuck Wagon", "chuck@habuma.com", false);
SPITTERS[3] = new Spitter(4L, "artnames", "password", "Art Names", "art@habuma.com", true);
SPITTERS[4] = new Spitter(5L, "newbee", "letmein", "New Bee", "newbee@habuma.com", true);
SPITTERS[5] = new Spitter(4L, "arthur", "letmein", "Arthur Names", "arthur@habuma.com", false);
} }
2.
package spittr.db.jpa; import static org.junit.Assert.*; import java.util.Date;
import java.util.List; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional; import spittr.db.SpittleRepository;
import spittr.domain.Spitter;
import spittr.domain.Spittle; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=JpaConfig.class)
public class SpittleRepositoryTest { @Autowired
SpittleRepository spittleRepository; @Test
@Transactional
public void count() {
assertEquals(15, spittleRepository.count());
} @Test
@Transactional
public void findRecent() {
// default case
{
List<Spittle> recent = spittleRepository.findRecent();
assertRecent(recent, 10);
} // specific count case
{
List<Spittle> recent = spittleRepository.findRecent(5);
assertRecent(recent, 5);
}
} @Test
@Transactional
public void findOne() {
Spittle thirteen = spittleRepository.findOne(13L);
assertEquals(13, thirteen.getId().longValue());
assertEquals("Bonjour from Art!", thirteen.getMessage());
assertEquals(1332682500000L, thirteen.getPostedTime().getTime());
assertEquals(4, thirteen.getSpitter().getId().longValue());
assertEquals("artnames", thirteen.getSpitter().getUsername());
assertEquals("password", thirteen.getSpitter().getPassword());
assertEquals("Art Names", thirteen.getSpitter().getFullName());
assertEquals("art@habuma.com", thirteen.getSpitter().getEmail());
assertTrue(thirteen.getSpitter().isUpdateByEmail());
} @Test
@Transactional
public void findBySpitter() {
List<Spittle> spittles = spittleRepository.findBySpitterId(4L);
assertEquals(11, spittles.size());
for (int i = 0; i < 11; i++) {
assertEquals(i+5, spittles.get(i).getId().longValue());
}
} @Test
@Transactional
public void save() {
assertEquals(15, spittleRepository.count());
Spitter spitter = spittleRepository.findOne(13L).getSpitter();
Spittle spittle = new Spittle(null, spitter, "Un Nuevo Spittle from Art", new Date());
Spittle saved = spittleRepository.save(spittle);
assertEquals(16, spittleRepository.count());
assertNewSpittle(saved);
assertNewSpittle(spittleRepository.findOne(16L));
} @Test
@Transactional
public void delete() {
assertEquals(15, spittleRepository.count());
assertNotNull(spittleRepository.findOne(13L));
spittleRepository.delete(13L);
assertEquals(14, spittleRepository.count());
assertNull(spittleRepository.findOne(13L));
} private void assertRecent(List<Spittle> recent, int count) {
long[] recentIds = new long[] {3,2,1,15,14,13,12,11,10,9};
assertEquals(count, recent.size());
for (int i = 0; i < count; i++) {
assertEquals(recentIds[i], recent.get(i).getId().longValue());
}
} private void assertNewSpittle(Spittle spittle) {
assertEquals(16, spittle.getId().longValue());
} }
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-005Spring-Data-JPA例子的代码的更多相关文章
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<;jpa:repositories>;)
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-003编写JPA-based repository( @PersistenceUnit、 @PersistenceContext、PersistenceAnnotationBeanPostProcessor)
一.注入EntityManagerFactory的方式 package com.habuma.spittr.persistence; import java.util.List; import jav ...
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-002设置JPA的EntityManagerFactory(<;persistence-unit>;、<;jee:jndi-lookup>;)
一.EntityManagerFactory的种类 1.The JPA specification defines two kinds of entity managers: Applicatio ...
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-001-使用Hibernate(@Inject、@EnableTransactionManagement、@Repository、PersistenceExceptionTranslationPostProcessor)
一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * ...
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-004JPA例子的代码
一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * ...
-
SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-004-以query parameters的形式给action传参数(@RequestParam、defaultValue)
一. 1.Spring MVC provides several ways that a client can pass data into a controller’s handler method ...
-
SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-005- 异常处理@ResponseStatus、@ExceptionHandler、@ControllerAdvice
No matter what happens, good or bad, the outcome of a servlet request is a servlet response. If an e ...
-
SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-003- 上传文件multipart,配置StandardServletMultipartResolver、CommonsMultipartResolver
一.什么是multipart The Spittr application calls for file uploads in two places. When a new user register ...
-
SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-002- 在xml中引用Java配置文件,声明DispatcherServlet、ContextLoaderListener
一.所有声明都用xml 1. <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...
随机推荐
-
python【4】-函数
一. 定义函数 定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回.如果没有return语句,函数执行完毕后也会返 ...
-
分享php中四种webservice实现的简单架构方法及实例
一:PHP本身的SOAP所有的webservice都包括服务端(server)和客户端(client).要使用php本身的soap首先要把该拓展安装好并且启用.下面看具体的code首先这是服务端实现: ...
-
WEB标准系列-HTML元素嵌套
转:http://www.smallni.com/element-nesting/ 先来看以下这样一段代码: <ul> <li><h4><a href=&qu ...
-
【dedecms】DEDE列表页调用文章内容第一张图片(非缩略图)方法
打开 ../ include/ common.func.php 添加代码 //将缩放图转变为文章第一张图片 function firstimg($str_pic) { $str_sub=substr( ...
-
NOIP 2018 划水记
(此处不应有目录) (本来想咕掉这篇游记) Day -1 今天信心题,这个毒瘤出题人怎么出了一堆垃圾题(smallfat批判这个垃圾题). T2,T3是送分题.T1考了个noip根本不会考得类欧几里德 ...
-
gcd最大生成树模板
出处: ACM International Collegiate Programming Contest, Egyptian Collegiate Programming ContestArab Ac ...
-
luogu P4036 [JSOI2008]火星人
传送门 很久以前xzz大佬就喊我做这题,结果现在才做qwq 因为要在序列中插入,所以直接用\(Splay\)维护这个串的哈希值,插入就直接把那个点插♂进去,修改就把点旋到根,然后修改和pushup,询 ...
-
Linux系统产生随机数/dev/random 和 /dev/urandom
1. 基本介绍 /dev/random和/dev/urandom是Linux系统中提供的随机伪设备,这两个设备的任务,是提供永不为空的随机字节数据流.很多解密程序与安全应用程序(如SSH Keys, ...
-
Android与互联网的交互方式有三种
数据下载:下载网络上的的数据,包括图片.代码文本.XML文件.JSON数据,音/视频等大文件,调用webservice. 数据上传:上传图片.文本.XML.JSON数据.音/视频文件,调用webser ...
-
基于element-ui的后台系统表格、dialog、筛选、自定义按钮、分页的一次性封装
方便基础业务开发封装的一套组件,基于vue2.5.x和element-ui,可以通过配置自动生成表格展示,表格新增.编辑功能.分页.筛选项.自定义显示表格数据等功能. 先上演示图片 --------- ...