ibatis基础(七):模糊查询实体对象
2011-12-04 17:09
337 查看
在Student.xml中添加:
此处标红特别注意,跟以往写法不同,可以理解为##自动帮你添加引号,而$$不添加引号
进行单元测试:
查看打印结果,发现名字中带有"i"的信息都被查询出来了:
减少了61%的代码量(此处有吹牛的嫌疑)
简单
架构级性能增强
sql语句与代码分离
简化项目中的分工
增强了移植性
参数只能有一个
<select id="selectStudentByName" parameterClass="String" resultClass="Student"> select * from student where name like '%$name$%' </select>
此处标红特别注意,跟以往写法不同,可以理解为##自动帮你添加引号,而$$不添加引号
进行单元测试:
@Test public void queryStudentByName() throws Exception{ Reader reader=Resources.getResourceAsReader("SqlMapConfig.xml");//读取总配置文件 SqlMapClient sqlmapclient=SqlMapClientBuilder.buildSqlMapClient(reader);//创建SqlMapClient来操作数据库 reader.close(); List<Student> students=sqlmapclient.queryForList("selectStudentByName","i");//调用我们写在xml中的sql语句 for(Student student:students){ System.out.println(student); } }
查看打印结果,发现名字中带有"i"的信息都被查询出来了:
1 Billy 70.5 4 brian 100.0
ibatis的优点(与JDBC相比):
减少了61%的代码量(此处有吹牛的嫌疑)简单
架构级性能增强
sql语句与代码分离
简化项目中的分工
增强了移植性
缺点:
sql需要自己写参数只能有一个
相关文章推荐
- 第七课 模糊查询实体对象
- ibatis基础(二):查询所有的对象
- ibatis基础(三):查询指定id的单个对象
- ibatis基础(四):插入一个实体对象
- ibatis基础(六):修改实体对象
- Java中使用hql,sql查询返回的list<Object> 转成需要的实体对象--方法讲解!
- Hibernate查询实体对象
- flex ibatis java 通过sql语句进行多条件模糊查询。
- IBATIS查询 模糊查询分享
- 07--MySQL自学教程:DQL(Data Query Language:数据库查询语言)简介、基础查询、条件查询、模糊查询以及排序(一)
- ADO.NET Entity Framework 对象查询(实体框架)
- ibatis动态多条件查询及模糊查询(oracle,mysql,sql)
- Java_jdbc 基础笔记之八 数据库连接(写一个查询Student对象的方法)
- C#分页面向对象封装[支持多表连接查询分页]-教学示范版--实体模型对象
- Hibernate基础使用:CRUD方法及实体对象的三种状态
- 集合对象与自定义javabean对象接收数据库查询的数据 (基础知识扫盲)
- IBATIS模糊查询
- 《Entity Framework 6 Recipes》中文翻译系列 (41) ------ 第七章 使用对象服务之标识关系中使用依赖实体与异步查询保存
- 一种安全云存储方案设计(下)——基于Lucene的云端搜索与密文基础上的模糊查询
- EF-Linq 将实体对象转换为搜索条件以进行通用动态查询