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();
            
            
        }
    复制代码
  • 相关阅读:
    Logistic回归
    朴素贝叶斯
    决策树
    K-邻近(KNN)算法
    快速排序
    归并排序
    希尔排序
    插入排序
    选择排序
    浅谈系统服务分发
  • 原文地址:https://www.cnblogs.com/lowerma/p/11658230.html
Copyright © 2011-2022 走看看