Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support repeatable annotation on `@Arg` and `@Result` #1698

Conversation

@kazuki43zoo
Copy link
Member

kazuki43zoo commented Oct 27, 2019

I propose to support repeatable annotation on @Arg and @Result as follow:

  @Result(property = "id", column = "AUTHOR_ID", id = true)
  @Result(property = "username", column = "AUTHOR_USERNAME")
  @Result(property = "password", column = "AUTHOR_PASSWORD")
  @Result(property = "email", column = "AUTHOR_EMAIL")
  @Result(property = "bio", column = "AUTHOR_BIO")
  @Select({
    "SELECT ",
    "  ID as AUTHOR_ID,",
    "  USERNAME as AUTHOR_USERNAME,",
    "  PASSWORD as AUTHOR_PASSWORD,",
    "  EMAIL as AUTHOR_EMAIL,",
    "  BIO as AUTHOR_BIO",
    "FROM AUTHOR WHERE ID = #{id}"})
  Author selectAuthor(int id);

and

  @Arg(column = "AUTHOR_ID", javaType = Integer.class, id = true)
  @Arg(column = "AUTHOR_USERNAME", javaType = String.class)
  @Arg(column = "AUTHOR_PASSWORD", javaType = String.class)
  @Arg(column = "AUTHOR_EMAIL", javaType = String.class)
  @Arg(column = "AUTHOR_BIO", javaType = String.class)
  @Select({
    "SELECT ",
    "  ID as AUTHOR_ID,",
    "  USERNAME as AUTHOR_USERNAME,",
    "  PASSWORD as AUTHOR_PASSWORD,",
    "  EMAIL as AUTHOR_EMAIL,",
    "  BIO as AUTHOR_BIO" +
    "FROM AUTHOR WHERE ID = #{id}"})
  Author selectAuthor(int id);

Above is equal to :

  @Results({
      @Result(property = "id", column = "AUTHOR_ID", id = true),
      @Result(property = "username", column = "AUTHOR_USERNAME"),
      @Result(property = "password", column = "AUTHOR_PASSWORD"),
      @Result(property = "email", column = "AUTHOR_EMAIL"),
      @Result(property = "bio", column = "AUTHOR_BIO")
  })
  @Select({
    "SELECT ",
    "  ID as AUTHOR_ID,",
    "  USERNAME as AUTHOR_USERNAME,",
    "  PASSWORD as AUTHOR_PASSWORD,",
    "  EMAIL as AUTHOR_EMAIL,",
    "  BIO as AUTHOR_BIO",
    "FROM AUTHOR WHERE ID = #{id}"})
  Author selectAuthor(int id);
  @ConstructorArgs({
      @Arg(column = "AUTHOR_ID", javaType = Integer.class, id = true),
      @Arg(column = "AUTHOR_USERNAME", javaType = String.class),
      @Arg(column = "AUTHOR_PASSWORD", javaType = String.class),
      @Arg(column = "AUTHOR_EMAIL", javaType = String.class),
      @Arg(column = "AUTHOR_BIO", javaType = String.class)
  })
  @Select({
    "SELECT ",
    "  ID as AUTHOR_ID,",
    "  USERNAME as AUTHOR_USERNAME,",
    "  PASSWORD as AUTHOR_PASSWORD,",
    "  EMAIL as AUTHOR_EMAIL,",
    "  BIO as AUTHOR_BIO" +
    "FROM AUTHOR WHERE ID = #{id}"})
  Author selectAuthor(int id);

By this changes, a develop can be omit the @Results and @ConstructorArgs for none-reusable result mapping.

@mybatis/committers WDYT?

@kazuki43zoo kazuki43zoo requested a review from harawata Oct 27, 2019
@kazuki43zoo kazuki43zoo self-assigned this Oct 27, 2019
Copy link
Member

harawata left a comment

Looks good! Thank you, @kazuki43zoo !

@kazuki43zoo kazuki43zoo added this to the 3.5.4 milestone Oct 31, 2019
@kazuki43zoo kazuki43zoo merged commit 13f8eef into mybatis:master Oct 31, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kazuki43zoo kazuki43zoo deleted the kazuki43zoo:support-repeatable-annotation-on-result-and-arg branch Oct 31, 2019
kazuki43zoo added a commit that referenced this pull request Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.