ustate校园圈设计与实现【字数:23878】
查看目录结构,选择启动项目的类,直接启动运行。
方式二、使用IDEA构建项目
打开IntelliJ IDEA,创建项目。
左侧列表框中选择Spring Initializr。
输入Artifact,Group,选择Dependen *景先生毕设|www.jxszl.com +Q: #351916072#
cies依赖选择Web。
点击finish生成,打开启动类启动项目。
2.3.5 Spring Data
SpringData目的是为了简化构建基于Spring框架应用的数据访问技术,包括非关系型数据库、MapReduce框架、云数据服务等,另外也包含对关系型数据库的支持。
旨在统一和简化对各类型持久化存储,而不拘泥于是关系型数据库还是NoSQL数据存储。另外,SpringData能使得数据库的访问变得更加方便快捷。
无论哪种持久化存储,数据访问对象(Data Access Objects,DAO)通常都会对提供对单一域对象的CRUD(创建、读取、更新、删除)操作、查询方法、排序和分页方法等。Spring Data则提供了基于这些层面的统一接口(CurdRepository,PagingAndSortingRepository)以及对持久化存储的实现。
2.3.5.1 Spring Data JPA
Spring Data JPA是Spring Data系列的一部分,可以轻松实现基于JPA的存储库。此模的处理对基于JPA的数据访问层的增强支持。它使得构建使用数据访问技术的Spring驱动应用程序变得更加容易[7] 。借助Spring Data,以接口定义的方式创建Repository,其实现代码如下所示。
public interface SpitterRepository extends JpaRepository
}
此时SpitterRepository扩展了Spring Data JPA的JpaRepository,用来持久化Spitter对象的Repository,并且Spitter的ID类型为Long。此外,它还继承了JpaRepository、PagingAndSortingRepository和CrudRepository的18个方法。
定义查询方法,根据readSpitterByFirstnameOrLastnameOrderByLastname()方法,分析方法中各个部分是如何映射的。图26展现了这个方法是如何拆分的。
图26 自定义查询方法映射
Repository主题可选且可以被忽略。断言限制结果集的属性,图26中lastname属性或lastname属性限制了方法的结果。在断言中,会有一个或多个限制条件。每个条件必须引用一个属性,并且可以指定一种比较操作。
方法命名
sql where字句
And
findByNameAndPwd
where name= ? and pwd =?
Or
findByNameOrSex
where name= ? or sex=?
Is,Equals
findById,findByIdEquals
where id= ?
Between
findByIdBetween
where id between ? and ?
LessThan
findByIdLessThan
where id < ?
LessThanEquals
findByIdLessThanEquals
where id <= ?
GreaterThan
findByIdGreaterThan
where id > ?
GreaterThanEquals
findByIdGreaterThanEquals
where id > = ?
After
findByIdAfter
where id > ?
Before
findByIdBefore
where id < ?
IsNull
findByNameIsNull
where name is null
isNotNull,NotNull
findByNameNotNull
where name is not null
Like
findByNameLike
where name like ?
NotLike
findByNameNotLike
where name not like ?
StartingWith
原文链接:http://www.jxszl.com/jsj/jsjkxyjs/82834.html