• 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());
            }
  • 相关阅读:
    团队冲刺03
    梦断代码 阅读笔记02
    团队冲刺02
    团队冲刺01
    周总结
    团队工作任务
    阅读笔记3
    梦断代码阅读笔记01
    周总结
    NABCD项目分析
  • 原文地址:https://www.cnblogs.com/szhhhh/p/11635617.html
Copyright © 2020-2023  润新知