-------------------- 剩下的时间不多了,全力做一些自己喜欢的东西
SpringBoot JPA :
默认使用的orm 框架是 hirbernate, 所以具备一些常见的hibernate 的功能,
不用手写数据库中的表,简单的crud 也不需要自己去写,只需继承一个接口就可以了。
@Entity @Table(name = "AUTH_ROLE") public classRoleDO { @Id privateLong id; @Column(length = 32) privateString name; @Column(length = 64) privateString note; publicLong getId() { returnid; } public voidsetId(Long id) { this.id =id; } publicString getName() { returnname; } public voidsetName(String name) { this.name =name; } publicString getNote() { returnnote; } public voidsetNote(String note) { this.note =note; } }
上面的注解都是jpa 所带有的
package com.yanggaochao.springboot.learn.springbootjpalearn.security.dao; import com.yanggaochao.springboot.learn.springbootjpalearn.security.domain.dao.UserDO; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; /** * 用户服务数据接口类 * * @author 杨高超 * @since 2018-03-12 */ @Repository package com.yanggaochao.springboot.learn.springbootjpalearn.security.dao; import com.yanggaochao.springboot.learn.springbootjpalearn.security.domain.dao.UserDO; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; /** * 用户服务数据接口类 * * @author 杨高超 * @since 2018-03-12 */ @Repository public interface UserDao extends JpaRepository<UserDO, Long>{ }
只需要继承上面红色标注的接口就可以了, 其中UserDo 是实体类的名称, long 是 数据表id 的类型