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

可以写个注解方式的mybatis学习笔记 #3

Open
bestfc opened this issue May 11, 2017 · 10 comments
Open

可以写个注解方式的mybatis学习笔记 #3

bestfc opened this issue May 11, 2017 · 10 comments

Comments

@bestfc
Copy link

bestfc commented May 11, 2017

:)

@brianway
Copy link
Owner

注解方式?能具体点吗?

@bestfc
Copy link
Author

bestfc commented May 11, 2017

这个列子展示了多参数使用@sqlProvider:

@SelectProvider(type = UserSqlBuilder.class, method = "buildGetUsersByName")
List getUsersByName(
@param("name") String name, @param("orderByColumn") String orderByColumn);

class UserSqlBuilder {

// If not use @param, you should be define same arguments with mapper method
public String buildGetUsersByName(
final String name, final String orderByColumn) {
return new SQL(){{
SELECT("*");
FROM("users");
WHERE("name like #{name} || '%'");
ORDER_BY(orderByColumn);
}}.toString();
}

// If use @param, you can define only arguments to be used
public String buildGetUsersByName(@param("orderByColumn") final String orderByColumn) {
return new SQL(){{
SELECT("*");
FROM("users");
WHERE("name like #{name} || '%'");
ORDER_BY(orderByColumn);
}}.toString();
}
}

@bestfc
Copy link
Author

bestfc commented May 11, 2017

http://www.mybatis.org/mybatis-3/zh/java-api.html
官方说明算是一笔带过,比较粗糙

@brianway
Copy link
Owner

懂了,我也不知道企业现在主要是用 xml 还是注解,如果注解是趋势的话,我有空写一写。如果 xml 是趋势,那就不写了。我暑假看看

@wangshuai12345
Copy link

老哥,你这不是原创啊

@imooni
Copy link

imooni commented May 30, 2017

是啊,我点赞的

@brianway
Copy link
Owner

学习笔记性质的文章,大家看的都是一个教程,写不出花来啊,大兄弟。

@1330212641
Copy link

学习笔记性质的文章,大家看的都是一个教程,写不出花来啊,大兄弟。

相较之下,小白两者都喜欢。教程式的用来敲借鉴。笔记式的用来理思绪。

@zc-cris
Copy link

zc-cris commented Mar 15, 2022 via email

@ujavance
Copy link

ujavance commented Mar 16, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants