优化RowBound
This commit is contained in:
@@ -2,19 +2,19 @@
|
||||
  ```DataSqlSource```是```DataSource```的SQL扩展类,增强了对原生SQL的操作。
|
||||
|
||||
## SQL模板
|
||||
  Redkale中的SQL模板与Mybatis里的SQL模板用法类似, 最大区别在于不需要写很多```if/else```判断语句,也不用写xml文件, 框架会根据参数存在与否动态生成sql语句, 查询结果时带下划线的sql字段名和类中的驼峰字段名会自动匹配。
|
||||
  Redkale中的SQL模板与Mybatis里的SQL模板用法类似, 最大区别在于不需要写很多```if/else```判断语句,也不用写xml文件, 框架会根据参数存在与否动态生成sql语句, 查询结果时下划线式sql字段名和驼峰式类字段名会自动匹配。
|
||||
```sql
|
||||
SELECT * FROM user WHERE user_id IN ${bean.userIds} OR user_name = ${bean.userName}
|
||||
```
|
||||
  当bean.userIds=null,bean.userName='hello'时,sql语句转换成
|
||||
  当bean.userIds=null,bean.userName='hello'时,sql语句转换成:
|
||||
```sql
|
||||
SELECT * FROM user WHERE user_name = 'hello'
|
||||
```
|
||||
  当bean.userIds=[1,2,3],bean.userName=null时,sql语句转换成
|
||||
  当bean.userIds=[1,2,3],bean.userName=null时,sql语句转换成:
|
||||
```sql
|
||||
SELECT * FROM user WHERE user_id IN (1,2,3)
|
||||
```
|
||||
  IN或者NOT IN语句当参数不为null而是空数组或者空List会进行特殊处理,IN语句会转化成```1=1```, NOT IN语句会转化成```1=2```。 当bean.userIds=空数组,bean.userName='hello'时,sql语句转换成
|
||||
  IN或者NOT IN语句当参数不为null而是空数组或者空List会进行特殊处理,IN语句会转化成```1=1```, NOT IN语句会转化成```1=2```。 当bean.userIds=空数组,bean.userName='hello'时,sql语句转换成:
|
||||
```sql
|
||||
SELECT * FROM user WHERE 1=2 OR user_name = 'hello'
|
||||
```
|
||||
@@ -29,14 +29,14 @@
|
||||
public class ForumInfoService extends AbstractService {
|
||||
|
||||
//查询单个记录的sql
|
||||
private static final String findOneSql = "SELECT f.forum_groupid, s.forum_section_color "
|
||||
private static final String findSql = "SELECT f.forum_groupid, s.forum_section_color "
|
||||
+ "FROM forum_info f, forum_section s "
|
||||
+ " WHERE f.forumid = s.forumid AND "
|
||||
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
|
||||
+ "f.forumid = ${bean.forumid} AND s.forum_section_color = ${bean.forumSectionColor}";
|
||||
|
||||
//查询列表记录的sql
|
||||
private static final String queryListSql = "SELECT f.forum_groupid, s.forum_section_color "
|
||||
private static final String querySql = "SELECT f.forum_groupid, s.forum_section_color "
|
||||
+ "FROM forum_info f, forum_section s "
|
||||
+ " WHERE f.forumid = s.forumid AND "
|
||||
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
|
||||
@@ -46,17 +46,22 @@ public class ForumInfoService extends AbstractService {
|
||||
private DataSqlSource source;
|
||||
|
||||
public ForumResult findForumResultOne(ForumBean bean) {
|
||||
return source.nativeQueryOne(ForumResult.class, findOneSql, Map.of("bean", bean));
|
||||
return source.nativeQueryOne(ForumResult.class, findSql, Map.of("bean", bean));
|
||||
}
|
||||
|
||||
public CompletableFuture<List<ForumResult>> queryForumResultListAsync(ForumBean bean) {
|
||||
return source.nativeQueryListAsync(ForumResult.class, queryListSql, Map.of("bean", bean));
|
||||
return source.nativeQueryListAsync(ForumResult.class, querySql, Map.of("bean", bean));
|
||||
}
|
||||
|
||||
//翻页查询
|
||||
public Sheet<ForumResult> queryForumResult(RowBound bound, ForumBean bean){
|
||||
return source.nativeQuerySheet(ForumResult.class, querySql, round, Map.of("bean", bean));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## DataSqlMapper
|
||||
  DataSqlMapper与MyBatis里的Mapper用法类似。
|
||||
  DataSqlMapper与MyBatis里的Mapper用法类似,且都支持异步方法。
|
||||
```java
|
||||
public interface ForumInfoMapper extends BaseMapper<ForumInfo> {
|
||||
|
||||
@@ -76,6 +81,14 @@ public interface ForumInfoMapper extends BaseMapper<ForumInfo> {
|
||||
+ "AND s.forum_section_color = ${bean.forumSectionColor}")
|
||||
public CompletableFuture<ForumResult> findForumResultOneAsync(ForumBean bean);
|
||||
|
||||
//翻页查询
|
||||
@Sql("SELECT f.forum_groupid, s.forum_section_color "
|
||||
+ "FROM forum_info f, forum_section s "
|
||||
+ " WHERE f.forumid = s.forumid AND "
|
||||
+ "s.forum_sectionid = #{bean.forumSectionid} AND "
|
||||
+ "f.forumid = #{bean.forumid} AND s.forum_section_color = #{bean.forumSectionColor}")
|
||||
public Sheet<ForumResult> queryForumResult(RowBound bound, ForumBean bean);
|
||||
|
||||
@Sql("UPDATE forum_section s "
|
||||
+ " SET s.forum_sectionid = '' "
|
||||
+ " WHERE s.forum_section_color = $${bean.forumSectionColor}")
|
||||
|
||||
Reference in New Issue
Block a user