zoukankan      html  css  js  c++  java
  • 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();
            
            
        }
    复制代码
  • 相关阅读:
    Mysql安装(msi版的安装)
    001 springBoot的数据库操作
    使用IDEA搭建spring
    spring简介
    rabbitMQ的安装(Windows下)
    mysql过滤数据
    mysql查询数据
    均值滤波,中值滤波,最大最小值滤波
    图像运动去模糊(Motion Deblurring)代码
    数字图像处理,图像锐化算法的C++实现
  • 原文地址:https://www.cnblogs.com/lowerma/p/11658230.html
Copyright © 2011-2022 走看看