通过ip访问网站需要怎么做,博客的网站页面设计,好的买手表网站,成全视频免费高清观看在线动漫#xff08;这与“学生计划”有关#xff0c;稍后我将重新讨论该主题。#xff09; Spring Data在最近的几次采访中获得通过。 什么是Spring Data #xff1f; 为了回答这个问题#xff0c;让我们考虑持久性的标准方法–所有访问都是通过数据访问对象 #xff08;DAO这与“学生计划”有关稍后我将重新讨论该主题。 Spring Data在最近的几次采访中获得通过。 什么是Spring Data 为了回答这个问题让我们考虑持久性的标准方法–所有访问都是通过数据访问对象 DAO进行的。 这将系统的其余部分与持久性机制的特定细节完全隔离开来。 这听起来很容易但是任何曾经做过一个不平凡的项目的人都知道这是一个很大的麻烦。 DAO代码很无聊。 它是单调的它具有很多非常相似的代码并且轻微的错误可能会导致很多损坏。 更糟糕的是它违反了“ 不要自己重复” DRY的原则因为大多数信息已在JPA批注中捕获。 这是一个很大的问题已经有多年的代码生成工具了。 从理论上讲他们解决了问题但在实践中他们介绍了自己的问题。 例如需要自定义配置文件或注释。 将接口用作DRY合同 Java世界中最终的DRY合同是什么 这很简单–它是一个接口。 给定一个接口和一个模板我们可以使用CGLib在应用程序启动过程中即时生成必要的类。 虽然性能略有下降但与优点相比还是比较适中的。 学生.java Entity
public class Student {private Integer id;private String uuid;private String name;private String emailAddress;private Integer creditHours;Idpublic Integer getId() { return id; }public void setId(Integer id) { this.id id; }Column(uniquetrue)public String getUuid() { return uuid; }public void setUuid(String uuid) { this.uuid uuid; }Columnpublic String getName() { return name; }public void setName(String name) { this.name name; }Column(uniquetrue)public String getEmailAddress() { return emailAddress; }public void setEmailAddress(String emailAddress) { this.emailAddress; }Columnpublic Integer getCreditHours() { return creditHours; }public void setCreditHours(Integer creditHours) { this.creditHours creditHours; }
} 我们的界面会是什么样 仓库/StudentRepository.java import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;Repository
public interface StudentRepository extends CrudRepositoryStudent, Integer {// this could also be getByUuid() or fetchByUuid() - all are recognizedStudent findStudentByUuid(String uuid);Student findStudentByEmailAddress(String emailAddress);ListStudent findStudentsByNameLike(String pattern);// we can use a custom queryQuery(select s from Student s where s.creditHours 15)ListStudent findFreshmen();
} 等等。 总共有15个谓词可以单独使用或组合使用。 和 要么 之间 少于 比...更棒 一片空白 IsNotNull 不为空 喜欢 不喜欢 按订单 不 在 不在 忽略大小写 注意没有必要实现此接口 CGLib为我们解决了这一问题。 定制方法 有时我们需要编写我们自己的DAO方法。 它们很容易集成到生成的代码中。 public interface StudentExtras {Student flogStudent(Student student);
}Repository
public interface StudentRepository extends CrudRepositoryStudent, Integer, emStudentExtras/em { }// this class does NOT implement StudentRepository!
public class StudentRepositoryImpl implements StudentExtras {public Student flogStudent(Student student) { ... }
} 自定义方法必须是特定的类由于按约定进行配置但不受其他限制。 NoSQL Spring Data还透明地支持NoSQL数据库Mondo文档Neo4j图形Redis键值Hadoop映射减少和GemFire。 分页 最后我们有分页的问题。 用户界面通常仅查看可用信息的子集例如25个项目的页面。 分页并不困难只是无聊且容易出错。 Spring Data通过扩展PagingAndSortingRepository接口而不是CrudRepository接口来支持分页。 参考 什么是Spring Data 来自Invariant Properties博客的JCG合作伙伴 Bear Giles。 翻译自: https://www.javacodegeeks.com/2013/12/what-is-spring-data.html