From 238ac0e9019e31e61f212b162682043ab6f285ab Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Sat, 8 Jul 2023 08:26:34 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=20IF=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/coretest/IfFunctionTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java new file mode 100644 index 00000000..b7843498 --- /dev/null +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IfFunctionTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.coretest; + +import com.mybatisflex.core.query.QueryWrapper; +import org.junit.Test; + +import static com.mybatisflex.core.query.QueryMethods.if_; +import static com.mybatisflex.core.query.QueryMethods.string; +import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT; + +/** + * @author 王帅 + * @since 2023-07-07 + */ +public class IfFunctionTest { + + @Test + public void test01() { + QueryWrapper queryWrapper = QueryWrapper.create() + .select(if_(ACCOUNT.AGE.ge(6), ACCOUNT.IS_NORMAL, ACCOUNT.IS_DELETE).as("type")) + .from(ACCOUNT) + .where(ACCOUNT.ID.eq(1)); + System.out.println(queryWrapper.toSQL()); + } + + @Test + public void test02() { + QueryWrapper queryWrapper = QueryWrapper.create() + .select(if_(ACCOUNT.AGE.ge(18), string("成年人"), + if_(ACCOUNT.AGE.le(8), string("未上学"), string("已上学"))).as("type")) + .from(ACCOUNT) + .where(ACCOUNT.ID.eq(1)); + System.out.println(queryWrapper.toSQL()); + } + +} \ No newline at end of file