202009-24 Springboot和Jpa实现学生CRUD操作代码实例 前期准备使用idea新建个SpringBoot项目在数据库中建student表建包1.编写entity包下实体类Student(一个Javabean规范)packagecom.example.stu.kudestu.stu.entity;importjavax.persistence.*;@Entity@Table(name="student")//@Entity应用在实体类上@Table(name="student")应用在实体类上,并且name属性为数据库表名publicclassStudent{@Id@GeneratedValue(strategy=GenerationType.IDENTITY)//ID自增private... 继续阅读 >
202009-24 Spring Boot JPA中使用@Entity和@Table的实现 本文中我们会讲解如何在SpringBootJPA中实现class和数据表格的映射。默认实现SpringBootJPA底层是用Hibernate实现的,默认情况下,数据库表格的名字是相应的class名字的首字母大写。命名的定义是通过接口ImplicitNamingStrategy来定义的:/***Determinetheimplicitnameofanentity'sprimarytable.**@paramsourceThesourceinformation**@returnTheimplicittablename.*/publicIdentifi... 继续阅读 >
202009-23 Spring Boot JPA中java 8 的应用实例 上篇文章中我们讲到了如何在SpringBoot中使用JPA。本文我们将会讲解如何在SpringBootJPA中使用java8中的新特习惯如:Optional,StreamAPI和CompletableFuture的使用。Optional我们从数据库中获取的数据有可能是空的,对于这样的情况Java8提供了Optional类,用来防止出现空值的情况。我们看下怎么在Repository中定义一个Optional的方法:publicinterfaceBookRepositoryextendsJpaRepository<Book,Long>{Optiona... 继续阅读 >