首页 > 代码库 > MyBatis动态SQL

MyBatis动态SQL

public interface UserMapper

{
  @SelectProvider(type="UserSqlProvider.class" method="selectWithParam")

  List<User> selectWithParam(Map<String,Object> param);
}

 

public classUserSqpProvider

{

  public String selectWithParam(Map<String,Object> param)

  {

  return new SQL(){

    {

      SELECT("*")

      FROM("User")

      if(param.get("id") != null)

      {

        WHERE(" id=#{id}")

      }

      ...

    }.toString();

  };

  }

}

 

MyBatis动态SQL