MyBatis 智能标签
使用Where 只能标签 检索部门Y2162Dept 数据库已存在表Y2162Dept
实现动态查询 Deptno Deptname
赋值 不赋值
不赋值 赋值
赋值 赋值
不赋值 不赋值
<!-- 使用Where 智能标签实现动态查询 -->
<select id="selectDeptDynamic" parameterType="cn.happy.entity.Dept" resultType="cn.happy.entity.Dept">
select * from Y2162dept
<where>
<if test="deptno!=null">
and deptno=#{deptno}
</if>
<if test="deptname!=null">
and deptname=#{deptname}
</if>
</where> </select>
//智能标签where 动态查询
@Test
public void dynamicWhereTest() throws Exception{
Dept dept=new Dept(); //dept.setDeptname("财务部");
//dept.setDeptno(3); List<Dept> list=session.selectList("selectDeptDynamic",dept);
for (Dept dt : list) {
System.out.println(dt.getDeptname());
}
session.close();
}
运行结果:

使用set智能标签修改数据
<!-- 智能标签set --> <update id="UpdateDept" parameterType="cn.happy.entity.Dept">
Update Y2162Dept
<set>
<if test="deptno!=null">
deptno=#{deptno},
</if>
<if test="deptname!=null">
deptname=#{deptname},
</if> </set>
where deptno=#{deptno} </update>
//使用智能标签set 修改数据
public void updateTest(){
Dept dt=new Dept();
dt.setDeptno(45);
dt.setDeptname("月饼不");
int count = session.update("UpdateDept",dt);
session.commit();
System.out.println(count);
session.close(); }
MyBatis 智能标签的更多相关文章
- Mybatis智能标签
一.ProviderDao层 //智能标签案例 //智能标签多条件查询 public List<Provider> providerTest(@Param("proCode&qu ...
- MyBatis智能标签!
if 语句 <select id="getOne" resultType="com.mybatis.entity.SmbmsProviderEntity" ...
- MyBatis的一系列问题的处理(遍历Map集合和智能标签和属性和字段不一样的解决办法 和sql片段)(三)
一.字段名与属性名(数据库的名字)不一样怎么办? 方案一:在小配置中配置一个resultMapper <!--方案一:resultMapper 字段名与属性名不一致 --> <res ...
- mybatis高级(2)_数据库中的列和实体类不匹配时的两种解决方法_模糊查询_智能标签
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...
- MyBatis系列四 之 智能标签进行查询语句的拼接
MyBatis系列四 之 智能标签进行查询语句的拼接 使用Foreach进行多条件查询 1.1 foreach使用数组进行多条件查询 在MyBatis的映射文件中进行如下配置 <!--根据数组进 ...
- SSM-MyBatis-14:Mybatis中智能标签
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 谈论到智能,有什么要想的没有? 我下面放张图 相信都见过这个吧,你在之前没有学习过框架的时候怎么写的,动态sq ...
- 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】
一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...
- MyBatis初学者配置
小配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC &qu ...
- mybatis大框架
MyBatis 开源的数据持久化层框架 实体类与SQL语句之间建立映射关系 一:MyBatis前身是IBatis,本是Apache的一个开源的项目, 基于SQL语法,简单易学 ,是耦合度降低,方便 ...
随机推荐
- WCF的Restful和TCP方式调用性能比较
1. 实验背景关于WCF提供分布式访问服务,最常用的两种方式Restful方式和Tcp方式,在本地测试了一把.结果显示,还是Rest方式,在压力测试下,性能最佳.而且处于跨平台的考虑,和自动化测试方便 ...
- FASTSOCKET
FASTSOCKET It looks like there are like 3 separate optimizations, but I think the most important one ...
- No.007:Reverse Integer
问题: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321 官方难度: Ea ...
- Understanding glibc malloc【待译】
今天尝试用Valgrind调试程序时,发现堆和栈的一些问题没有理解透彻,于是Google了下"Memory Layout C",接着就通过Memory Layout of C Pr ...
- [翻译]写给精明Java开发者的测试技巧
我们都会为我们的代码编写测试,不是吗?毫无疑问,我知道这个问题的答案可能会从 “当然,但你知道怎样才能避免写测试吗?” 到 “必须的!我爱测试”都有.接下来我会给你几个小建议,它们可以让你编写测试变得 ...
- jQuery演示8种不同的图片遮罩层动画效果
效果预览 下载地址 jQuery插件大全 实例代码 <div class="container"> <h1>jQuery图标和文章动画效果</h1&g ...
- [deviceone开发]-do_ImageView实现正圆的示例
一.简介 我们经常需要用一个正圆形状的图片来设置头像,在do平台这个比较容易,就是通过设置圆角来实现,但是有几个小技巧需要解释一下 主要组件:do_ImageView 二.效果图 三.相关下载 htt ...
- CSS3中flexbox如何实现水平垂直居中和三列等高布局
最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.
- angular源码分析:angular中脏活累活的承担者之$interpolate
一.首先抛出两个问题 问题一:在angular中我们绑定数据最基本的方式是用两个大括号将$scope的变量包裹起来,那么如果想将大括号换成其他什么符号,比如换成[{与}],可不可以呢,如果可以在哪里配 ...
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
