一、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());