• Mybatis框架模糊查询+多条件查询


    一、ISmbmsUserDao层

        //根据姓名模糊查询
        public List<Smbms> getUser();
        //多条件查询
        public List<Smbms> getLikeUser(@Param("userName") String userName , @Param("userCode") String userCode );

    二、小配置文件 ISmbmsUserDao.xml

     
    <!--根据姓名模糊查询-->
        <select id="getUser" resultType="com.smbms.entity.Smbms">
            <!--select * from smbms_user where userName like CONCAT('%',#{userName},'%')-->
            select * from smbms_user where userName like '%' #{userName} '%'
        </select>
    
    <!--多条件查询-->
        <select id="getLikeUser" resultType="com.smbms.entity.Smbms">
            <!--select * from smbms_user where userName like CONCAT('%',#{userName},'%')-->
            select * from smbms_user where userName like '%' #{userName} '%' and userCode like '%' #{userCode} '%'
        </select>
     

    三、测试类

     
    //根据姓名模糊查询
            /*List<Smbms> getUser=sqlSession.selectList("getUser","马");
            for (Smbms users:getUser) {
                System.out.println(users.getUserName());
            }*/
    
            //多条件查询
            ISmbmsUserDao mapper=sqlSession.getMapper(ISmbmsUserDao.class);
            List<Smbms> getUser=mapper.getLikeUser("马","yuan");
            for (Smbms users:getUser) {
                System.out.println(users.getUserName()+"================="+users.getUserpwd());
            }
     
  • 相关阅读:
    HashMap 链表插入方式 → 头插为何改成尾插 ?
    MySQL 日志之 binlog 格式 → 关于 MySQL 默认隔离级别的探讨
    Eclipse
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
    Delphi
  • 原文地址:https://www.cnblogs.com/F017/p/11635606.html
Copyright © 2020-2023  润新知