zoukankan      html  css  js  c++  java
  • 智能标签

    使用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();
            
            
        }
    复制代码
    复制代码
  • 相关阅读:
    lambda表达式
    PAT 1071. Speech Patterns
    PAT 1070. Mooncake
    1069. The Black Hole of Numbers
    PAT 1068. Find More Coins
    背包问题(动态规划)
    PAT 1067. Sort with Swap(0,*)
    PAT 1066. Root of AVL Tree
    PAT 1065. A+B and C
    PAT 1064. Complete Binary Search Tree
  • 原文地址:https://www.cnblogs.com/danxun/p/11658273.html
Copyright © 2011-2022 走看看