sql_@SelectProvider及使用注意

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SelectProvider {
  Class type();
  String method();
}

RoleDao.java

public interface RoleDao {

    @SelectProvider(type=RoleProvider.class,method="queryRolesByParamsSql")
    List queryRolesByParams(RoleQuery roleQuery);

}

RoleProvider.java

public class RoleProvider {

    public String queryRolesByParamsSql(@Param("roleName") final String roleName){
        return new SQL(){
            {
                SELECT("id,role_name as roleName,role_remark as roleRemark,"
                + "create_date as createDate,update_date as updateDate,"
                + " is_valid as isValid");
                FROM("t_role");
                WHERE("is_valid=1");
                if(StringUtils.isNoneBlank(roleName)){
                    WHERE("role_name like concat('%',#{roleName},'%')");
                }
            }
        }.toString();

    }
}

RoleMapper.xml

<select id="queryRolesByParams" resultType="role">
        select "role_column" /> 
        from t_role
        <where>
            is_valid = 1
            <if test="roleName !=null and roleName !=''">
                 and role_name like concat('%',#{roleName},'%')
            if>

        where> 
  select>

注:

@SelectProvider 和 PageHelper 一起使用可能报错
报错是这样的,点击查看

你可能感兴趣的:(database,ssm)