mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
test: 测试自动添加别名。
This commit is contained in:
parent
24ebbdffe6
commit
70c97ada72
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Table;
|
||||
|
||||
/**
|
||||
* @author 王帅
|
||||
* @since 2023-07-01
|
||||
*/
|
||||
@Table("tb_inner")
|
||||
public class Inner {
|
||||
|
||||
private Integer id;
|
||||
private String type;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Inner{" +
|
||||
"id=" + id +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.entity;
|
||||
|
||||
import com.mybatisflex.annotation.As;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.test.model.IdEntity;
|
||||
|
||||
/**
|
||||
* @author 王帅
|
||||
* @since 2023-06-16
|
||||
*/
|
||||
@Table("tb_outer")
|
||||
public class Outer extends IdEntity<Integer> {
|
||||
|
||||
private String name;
|
||||
private Inner inner;
|
||||
|
||||
@Override
|
||||
@As("test_id")
|
||||
public void setId(Integer id) {
|
||||
super.setId(id);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Inner getInner() {
|
||||
return inner;
|
||||
}
|
||||
|
||||
public void setInner(Inner inner) {
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Outer{" +
|
||||
"name='" + name + '\'' +
|
||||
", inner=" + inner +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,6 @@ public class AccountVO2 extends IdEntity<Long> {
|
||||
|
||||
private Integer age;
|
||||
@As("account_name")
|
||||
@As("1_account_name")
|
||||
private String userName;
|
||||
private UserVO4 user;
|
||||
|
||||
|
||||
@ -3,16 +3,16 @@ spring:
|
||||
# h2:
|
||||
# console:
|
||||
# enabled: true
|
||||
# datasource:
|
||||
## driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/flex_test
|
||||
# username: root
|
||||
# password: 12345678
|
||||
# driver-class-name:
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: test
|
||||
password: 12345678
|
||||
# driver-class-name:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
# username: root
|
||||
# password: test
|
||||
sql:
|
||||
init:
|
||||
schema-locations: classpath:schema.sql
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.mapper;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.test.entity.Inner;
|
||||
import com.mybatisflex.test.entity.Outer;
|
||||
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.entity.table.InnerTableDef.INNER;
|
||||
import static com.mybatisflex.test.entity.table.OuterTableDef.OUTER;
|
||||
|
||||
/**
|
||||
* @author 王帅
|
||||
* @since 2023-07-01
|
||||
*/
|
||||
@SpringBootTest
|
||||
class OuterMapperTest {
|
||||
|
||||
@Autowired
|
||||
private OuterMapper outerMapper;
|
||||
|
||||
@Autowired
|
||||
private InnerMapper innerMapper;
|
||||
|
||||
@Test
|
||||
void testInsert() {
|
||||
Outer outer = new Outer();
|
||||
outer.setName("outer 01");
|
||||
outerMapper.insertSelective(outer);
|
||||
|
||||
Inner inner = new Inner();
|
||||
inner.setId(2);
|
||||
inner.setType("inner type");
|
||||
innerMapper.insertWithPk(inner);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSelect() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(OUTER.ID,
|
||||
OUTER.NAME,
|
||||
INNER.ID,
|
||||
INNER.TYPE)
|
||||
.from(OUTER.as("o"))
|
||||
.leftJoin(INNER).as("i").on(INNER.ID.eq(2));
|
||||
Outer outer = outerMapper.selectOneByQuery(queryWrapper);
|
||||
System.out.println(outer);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user