mapper.xml中:
<select id="selectShareByName" resultMap="seeShare">
SELECT * FROM Diary
<where>
<!--where标签自动去掉满足条件的第一个and -->
<if test="arg0 != null and arg0 != ''">
and fileName LIKE CONCAT('%',#{arg0 },'%' )
</if>
<if test="arg1 != null and arg1 != ''">
and username = #{arg1}
</if>
</where>
</select>
DAO层:
//多条件查询,动态sql
public List<Diary> selectShareByName(String fileName,String username){
System.out.println(fileName+username);
List<Diary> list = new ArrayList<>();
DiaryMapper diaryMapper = sqlSession.getMapper(DiaryMapper.class);
list = diaryMapper.selectShareByName(fileName,username);
return list;
}
配置springboot+mybaits输出sql语句
在application.properties中加入:
logging.level.com.example.demo.map=debug
可以看到: