mybatis参数的问题

时间:2012-09-07 13:04:18

标签: java mysql mybatis

我正在尝试使用更大的SQL语句设置MyBatis接口,该语句使用相同的参数多次。我的代码是:

@Select({
"select cnfp_nr_years, cnfp_nr_credits, cnfp_credits_activities, cnfp_credits_studies, cnfp_credits_professional_evolution, cnfp_credits_programs_first_second, cnfp_credits_programs_third_fourth ",
"from ",
"(select cnfp_parameter_value as cnfp_nr_years ",
"from cnfp_parameters ", 
"where cnfp_parameter_name='PARAM_NR_YEARS' ",
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param1, ",
"(select cnfp_parameter_value as cnfp_nr_credits ",
"from cnfp_parameters ",
"where cnfp_parameter_name='PARAM_NR_CREDITS' ",
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param2, ",
"(select coalesce(sum(cnfp_teacher_activity_cpt_equiv),0) as cnfp_credits_activities ",
"from cnfp_teacher_activities ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_teacher_activity_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE}' ",
"and cnfp_teacher_activity_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as activities, ",
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_studies ",
"from cnfp_teacher_studies ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_institution_id is not null ",
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as studies, ",
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_professional_evolution ",
"from cnfp_teacher_studies ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_professional_level_id is not null ",
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as professional_evolution, ",
"(select coalesce(sum(case when cnfp_program_categories_code in (1,2) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_first_second, ",
"coalesce(sum(case when cnfp_program_categories_code in (3,4) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_third_fourth ",
"from cnfp_teacher_learning_activities ",
"left join cnfp_teacher_learning_activities_x_program_modules on cnfp_teacher_learning_activities.cnfp_teacher_learning_activity_id = cnfp_teacher_learning_activities_x_program_modules.cnfp_teacher_learning_activity_id ",
"left join cnfp_program_modules on cnfp_teacher_learning_activities_x_program_modules.cnfp_program_module_id = cnfp_program_modules.cnfp_program_module_id ",
"left join cnfp_programs on cnfp_program_modules.cnfp_program_id = cnfp_programs.cnfp_program_id ",
"left join cnfp_program_categories on cnfp_programs.cnfp_program_categories_id = cnfp_program_categories.cnfp_program_categories_id ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_STATUS = 1 ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_GRAD_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_EXPIRY_DATE >= #{cnfpProcessingDate,jdbcType=DATE}) as learning_activities"
})
@Results({
    @Result(column="cnfp_nr_years", property="cnfpParamVerifYears", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_nr_credits", property="cnfpParamCreditsAcc", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_activities", property="cnfpCreditsActivities", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_studies", property="cnfpCreditsStudies", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_professional_evolution", property="cnfpCreditsProfessionalEvolution", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_programs_first_second", property="cnfpCreditsProgramsFirstSecondCat", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_programs_third_fourth", property="cnfpCreditsThirdFourthCat", jdbcType=JdbcType.BIGINT)
})
CptCalculator selectResults(@Param("cnfpPersonId")Long cnfpPersonId, @Param("cnfpProcessingDate")Date cnfpProcessingDate);

但我一直得到例外:

java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).] with root cause

java.sql.SQLException:参数索引超出范围(7&gt;参数个数,即6)。

我不知道为什么。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

在结果中,你期待7个元素而你只有6个元素。直接在DB客户端中测试您的查询以检查输出。