mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
test: add unit test for issue_113
This commit is contained in:
parent
8677b0ed13
commit
a49a4b24e9
@ -0,0 +1,7 @@
|
|||||||
|
package com.mybatisflex.test.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.mybatisflex.test.model.TbClass;
|
||||||
|
|
||||||
|
public interface TbClassMapper extends BaseMapper<TbClass> {
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package com.mybatisflex.test.model;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
|
||||||
|
@Table(value = "tb_class")
|
||||||
|
public class TbClass {
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long user_id;
|
||||||
|
|
||||||
|
private String className;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUser_id() {
|
||||||
|
return user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName() {
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser_id(Long user_id) {
|
||||||
|
this.user_id = user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassName(String className) {
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TbClass{" +
|
||||||
|
"id=" + id +
|
||||||
|
", user_id=" + user_id +
|
||||||
|
", className='" + className + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,2 +1,8 @@
|
|||||||
INSERT INTO tb_account
|
INSERT INTO tb_account
|
||||||
VALUES (1, 'Michael Yang', 18, '2020-01-11');
|
VALUES (1, 'Michael Yang', 18, '2020-01-11');
|
||||||
|
|
||||||
|
INSERT INTO tb_class
|
||||||
|
VALUES (1, 1, 'class111');
|
||||||
|
|
||||||
|
INSERT INTO tb_user
|
||||||
|
VALUES (1, 'tom');
|
||||||
|
|||||||
@ -5,3 +5,16 @@ CREATE TABLE IF NOT EXISTS `tb_account`
|
|||||||
`age` Integer,
|
`age` Integer,
|
||||||
`birthday` DATETIME
|
`birthday` DATETIME
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `tb_class`
|
||||||
|
(
|
||||||
|
`id` INTEGER PRIMARY KEY,
|
||||||
|
`user_id` Integer NOT NULL,
|
||||||
|
`class_name` VARCHAR(100)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `tb_user`
|
||||||
|
(
|
||||||
|
`id` INTEGER PRIMARY KEY,
|
||||||
|
`name` VARCHAR(100)
|
||||||
|
);
|
||||||
|
|||||||
@ -0,0 +1,53 @@
|
|||||||
|
package com.mybatisflex.test.issue113;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.test.AppConfig;
|
||||||
|
import com.mybatisflex.test.mapper.TbClassMapper;
|
||||||
|
import com.mybatisflex.test.model.TbClass;
|
||||||
|
import org.assertj.core.api.WithAssertions;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.mybatisflex.test.issue113.def.TClassTableDef.TB_CLASS;
|
||||||
|
import static com.mybatisflex.test.issue113.def.TUserTableDef.TB_USER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Title: Issue113Test. </p>
|
||||||
|
* <p>Date: 2023/8/2 12:02 </p>
|
||||||
|
*
|
||||||
|
* @author loong0306
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = AppConfig.class)
|
||||||
|
public class Issue113Test implements WithAssertions {
|
||||||
|
@Autowired
|
||||||
|
private TbClassMapper tbClassMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQuery() {
|
||||||
|
QueryWrapper query = new QueryWrapper()
|
||||||
|
.select()
|
||||||
|
.from(TB_CLASS);
|
||||||
|
System.out.println(query.toSQL());
|
||||||
|
List<TbClass> list = tbClassMapper.selectListByQuery(query);
|
||||||
|
System.out.println(">>> result = " + list.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issue113() {
|
||||||
|
QueryWrapper query = new QueryWrapper()
|
||||||
|
.select()
|
||||||
|
.from(TB_CLASS)
|
||||||
|
.innerJoin(TB_USER)
|
||||||
|
.on(TB_CLASS.USER_ID.eq(TB_USER.ID))
|
||||||
|
.where(TB_CLASS.USER_ID.eq(1));
|
||||||
|
System.out.println(query.toSQL());
|
||||||
|
List<TbClass> list = tbClassMapper.selectListByQuery(query);
|
||||||
|
System.out.println(">>> result = " + list.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.mybatisflex.test.issue113.def;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
public class TClassTableDef extends TableDef {
|
||||||
|
public static final TClassTableDef TB_CLASS = new TClassTableDef();
|
||||||
|
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
public final QueryColumn USER_ID = new QueryColumn(this, "user_id");
|
||||||
|
|
||||||
|
public final QueryColumn CLASS_NAME = new QueryColumn(this, "class_name");
|
||||||
|
|
||||||
|
public TClassTableDef() {
|
||||||
|
super("", "tb_class");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.mybatisflex.test.issue113.def;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryColumn;
|
||||||
|
import com.mybatisflex.core.table.TableDef;
|
||||||
|
|
||||||
|
public class TUserTableDef extends TableDef {
|
||||||
|
public static final TUserTableDef TB_USER = new TUserTableDef();
|
||||||
|
|
||||||
|
public final QueryColumn ID = new QueryColumn(this, "id");
|
||||||
|
|
||||||
|
public final QueryColumn NAME = new QueryColumn(this, "name");
|
||||||
|
|
||||||
|
public TUserTableDef() {
|
||||||
|
super("", "tb_user");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user