在实际开发中的SQL语句没有之前的这么简单,很多时候需要根据传入的参数情况动态的生成SQL语句。 Mybatis提供了动态SQL相关的标签让我们使用。
具体操作可以查看mybats文档:https://mybatis.org/mybatis-3/zh/dynamic-sql.html
接口准备public interface UserDao {
//多个参数(如果是有多个参数的情况下一定要加上@Param来设置参数名)
//if操作
User findByCondition(@Param("id") Integer id, @Param("username") String username);
//trim操作
List findByCondition2(@Param("id") Integer id, @Param("username") String username);
//where操作
List findByCondition3(@Param("id") Integer id, @Param("username") String username);
//set操作
void updateUser(User user);
//foreach操作
List findByIds(@Param("ids") Integer[] ids);
//choose、when、otherwise操作
List selectChose(User user);
}
映射文件



