test: 测试链式查询。

This commit is contained in:
Suomm 2023-07-22 13:59:35 +08:00
parent dae42af41a
commit 1314667ee2
5 changed files with 107 additions and 18 deletions

View File

@ -1,17 +0,0 @@
package com.mybatisflex.coretest;
import com.mybatisflex.core.query.QueryChain;
import org.junit.Test;
public class QueryChainTest {
@Test
public void test() {
QueryChain queryChain = new QueryChain();
queryChain.from("aaa")
.leftJoin("bbb").on("aaa.id = bbb.x")
.where(Account::getId).ge(100);
System.out.println(queryChain.toSQL());
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.service;
import com.mybatisflex.core.service.IService;
import com.mybatisflex.test.model.Article;
/**
* @author 王帅
* @since 2023-07-22
*/
public interface ArticleService extends IService<Article> {
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.mybatisflex.test.mapper.ArticleMapper;
import com.mybatisflex.test.model.Article;
import com.mybatisflex.test.service.ArticleService;
import org.springframework.stereotype.Service;
/**
* @author 王帅
* @since 2023-07-22
*/
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
}

View File

@ -7,7 +7,7 @@ spring:
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/flex_test url: jdbc:mysql://localhost:3306/flex_test
username: root username: root
password: 123456 password: 12345678
# driver-class-name: # driver-class-name:
# datasource: # datasource:
# driver-class-name: org.h2.Driver # driver-class-name: org.h2.Driver

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test.service;
import com.mybatisflex.test.model.Article;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static com.mybatisflex.test.model.table.ArticleTableDef.ARTICLE;
/**
* @author 王帅
* @since 2023-07-22
*/
@SpringBootTest
class ArticleServiceTest {
@Autowired
ArticleService articleService;
@Test
void testChain() {
articleService.queryChain()
.select(ARTICLE.ALL_COLUMNS)
.from(ARTICLE)
.where(Article::getAccountId).eq(1)
.list()
.forEach(System.out::println);
}
}