Spring Data HelloWorld(三)
在 Spring Data 环境搭建(二) 的基础之上 我们改动 http://www.cnblogs.com/fzng/p/7253068.html
定义个一个接口 继承Repository类 咱们先实现一个根据名字查询
package org.springdata.repository; import org.springdata.domain.Employee; import org.springframework.data.repository.Repository; import org.springframework.data.repository.RepositoryDefinition; /*** * */public interface EmployeeRepository extends Repository<Employee,Integer> { /** * 根据名字找员工 * desc * @param name * @return */ public Employee findByName(String name); }
大家可以发现 我只声明了一个方法 并没有写任何的实现类 哦了 就这样 咱们写个实现类
package org.springdata; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springdata.domain.Employee; import org.springdata.repository.EmployeeRepository; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * 测试类 */ public class SpringDataTest { private ApplicationContext ctx = null; private EmployeeRepository employeeRepository = null; @Before public void setup(){ ctx = new ClassPathXmlApplicationContext("beans.xml"); employeeRepository = (EmployeeRepository)ctx.getBean(EmployeeRepository.class); System.out.println("setup"); } @After public void tearDown(){ ctx = null; System.out.println("tearDown"); } @Test public void testEntityManagerFactory(){ } @Test public void testFindByName(){ System.out.println(employeeRepository); Employee employee = employeeRepository.findByName("zhangsan"); System.out.println("id:" + employee.getId() + " , name:" + employee.getName() + " ,age:" + employee.getAge()); } }
根据用户名查询用户信息
就这样 灰常简单 简缩了jdbc的繁琐操作 ,你们是不是要试一试呢
Spring Data HelloWorld(三)的更多相关文章
- Spring Data MongoDB 三:基本文档查询(Query、BasicQuery)(一)
一.简单介绍 Spring Data MongoDB提供了org.springframework.data.mongodb.core.MongoTemplate对MongoDB的CRUD的操作,上一 ...
- Spring Data MongoDB 三:基本文档查询(Query、BasicQuery
一.简介 spring Data MongoDB提供了org.springframework.data.mongodb.core.MongoTemplate对MongoDB的CRUD的操作,上一篇我 ...
- Spring Data Jpa (三)定义查询方法
本章详细讲解如何利用方法名定义查询方法(Defining Query Methods) (1)定义查询方法的配置方法 由于Spring JPA Repository的实现原理是采用动态代理的机制,所以 ...
- Spring Data MongoDB 四:基本文档改动(update)(一)
Spring Data MongoDB 三:基本文档查询(Query.BasicQuery)(一) 学习MongoDB 二:MongoDB加入.删除.改动 一.简单介绍 Spring Data Mo ...
- Spring Data MongoDB 五:进阶文档查询(分页、Morphia)(二)
Spring Data MongoDB 三:基本文档查询(Query.BasicQuery)(一) 学习MongoDB 六: MongoDB查询(游标操作.游标信息)(三) 一.简单介绍 Spring ...
- Spring Data JPA教程, 第三部分: Custom Queries with Query Methods(翻译)
在本人的Spring Data JPA教程的第二部分描述了如何用Spring Data JPA创建一个简单的CRUD应用,本博文将描述如何在Spring Data JPA中使用query方法创建自定义 ...
- spring-boot (三) spring data jpa
学习文章来自:http://www.ityouknow.com/spring-boot.html spring data jpa介绍 首先了解JPA是什么? JPA(Java Persistence ...
- Spring data JPA 理解(默认查询 自定义查询 分页查询)及no session 三种处理方法
简介:Spring Data JPA 其实就是JDK方式(还有一种cglib的方式需要Class)的动态代理 (需要一个接口 有一大堆接口最上边的是Repository接口来自org.springfr ...
- Spring Data REST不完全指南(三)
上一篇我们介绍了使用Spring Data REST时的一些高级特性,以及使用代码演示了如何使用这些高级的特性.本文将继续讲解前面我们列出来的七个高级特性中的后四个.至此,这些特性能满足我们大部分的接 ...
随机推荐
- unity Editor下自启动
[InitializeOnLoad] 加上这个特性,并且在静态构造函数里写上内容.即可在Unity启动的时候自启动这个Editor脚本
- iOS 图片的属性
UIViewContentModeScaleToFill UIViewContentModeScaleAspectFit UIViewContentModeScaleAspectFill UIView ...
- Git-git 忽略 IntelliJ .idea文件
$ echo ‘.idea’ >> .gitignore $ git rm -rf .idea $ git add .gitignore
- erlang supervisor simple_one_for_one实例
simple_one_for_one vs one_for_one: 相同点: 这种Restart Strategy和one_for_one基本相同(即当一个child process挂掉后,仅仅重启 ...
- InnoDB:表
数据在表中是如何进行组织存放的?下面我们就来看看: InnoDB引擎表的类型 InnoDB表都会有一个主键. 如果没有显示的指定主键,首先会去查找,看是否有非空的唯一索引, 如果有,则该列为主键:如果 ...
- java全局变量使用
1.在多线程的作用下,全局变量可能被多个程序使用,如果有人修改,全局变量就被修改了,导致别人使用的时候,出现问题 2.解决方法: 全局变量改为私有变量. 或者把全局变量改为final类型,只能读取,不 ...
- 扫目录过狗过waf方法
用御剑的朋友都遇到过这个页面吧,装狗了开启保护就会这样 本机搭建安全狗设置发现,默认是过蜘蛛的,所以只要把http头来路改成蜘蛛的useragent就ok了 无奈御剑和wscan 都是无法设置http ...
- JVM Specification 9th Edition (4) Chapter 4. The class File Format
Chapter 4. The class File Format Table of Contents 4.1. The ClassFile Structure 4.2. Names 4.2.1. Bi ...
- java模拟从http上下载文件
1.依赖 Apache httpclient 包. 2.代码 HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = ...
- centos yum安装及手动编译ettercap
眼下流行的软件包有二种形式 ,一种是以rpm包,deb包为代表的智能安装包.还有一种是以file.tar.gz形式的压缩 一 智能安装 以 mysql为例 yum search mysqld 二 手动 ...