Are there plans any plans to provide expand interface for customer scan mapper package to register customering mapper? It`s mean that I want to load myself mapper interface and by myself implement the mapping ,its helpful to implement my custom mapper
Comment From: harawata
I'm sorry, but I couldn't understand. Could you explain it using some example code and/or configuration, please?
Comment From: lyjsh
it like the following code :
`public interface BlogMapper {
@Select("select * from t_blog where id = #{id} and url = #{url}")
List<Blog> selectList(@Param("id") Integer id,@Param("url")String url);
@MySelect("select * from t_blog")
List<Blog> mySelect();
} `
i want to implement my custom annotion to apply to mybatis,I study the source code and there seems is no extension point for me to customer load the class ,Is this explanation understandable?
Comment From: harawata
Thank you for the reply, @lyjsh !
It is unclear what you are trying to achieve (=goal).
What happens if you write @MySelect("select * from t_blog") instead of @Select("select * from t_blog")?
If you want to build SQL statement at runtime, check out @SelectProvider.
https://mybatis.org/mybatis-3/java-api.html
Comment From: lyjsh
I want to make base operation easy, for example ,if I can implement custom annotion,it maybe look like the code:
` public interface BlogMapper {
@MySelect
List
Comment From: harawata
That is what SQL providers are for. Basically, you add a SQL provider annotation like this.
public interface BlogMapper {
@SelectProvider(type = MyProvider.class, method = "selectAll")
List<Blog> selectAll();
MyBatis calls the MyProvider#selectAll() method at runtime and executes the SQL returned from the method.
In that method, you can get the mapper class or method via ProviderContext, so you should be able to calculate the table name and use it to build the SQL.
public class MyProvider {
public StringBuilder selectAll(ProviderContext context) {
StringBuilder sql = new StringBuilder();
Class<?> mapperClass = context.getMapperType();
String tableName = "t_" + mapperClass.getSimpleName()
.replace("Mapper", "").toLowerCase(Locale.ENGLISH);
sql.append("select * from ").append(tableName);
return sql;
}
}
It is also possible to omit the method field if you follow some rules.
public interface BlogMapper {
@SelectProvider(MyProvider.class)
List<Blog> selectAll();
Please read the explanation about ProviderMethodResolver in the doc.
Comment From: harawata
No response.