mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
update test samples
This commit is contained in:
parent
39909a584e
commit
4b75dafacc
@ -17,6 +17,8 @@ public class Account {
|
||||
|
||||
private int sex;
|
||||
|
||||
private Integer age;
|
||||
|
||||
private boolean isNormal;
|
||||
|
||||
public Long getId() {
|
||||
@ -51,6 +53,14 @@ public class Account {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public boolean isNormal() {
|
||||
return isNormal;
|
||||
}
|
||||
|
||||
@ -14,13 +14,52 @@ import static com.mybatisflex.test.table.Tables.ARTICLE;
|
||||
|
||||
public class AccountSqlTester {
|
||||
|
||||
|
||||
@Test
|
||||
public void testJava(){
|
||||
StringBuilder sql = new StringBuilder("select * from xxx");
|
||||
// sql.(7," 你好 ");
|
||||
public void testSelectSql() {
|
||||
QueryWrapper query = new QueryWrapper()
|
||||
.select()
|
||||
.from(ACCOUNT);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(query);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectColumnsSql() {
|
||||
QueryWrapper query = new QueryWrapper()
|
||||
.select(ACCOUNT.ID, ACCOUNT.USER_NAME)
|
||||
.from(ACCOUNT);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(query);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectColumnsAndFunctionsSql() {
|
||||
QueryWrapper query = new QueryWrapper()
|
||||
.select(ACCOUNT.ID, ACCOUNT.USER_NAME, max(ACCOUNT.BIRTHDAY), avg(ACCOUNT.SEX).as("sex_avg"))
|
||||
.from(ACCOUNT);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(query);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectAllColumnsSql() {
|
||||
QueryWrapper query = new QueryWrapper()
|
||||
.select(ACCOUNT.ALL_COLUMNS)
|
||||
.from(ACCOUNT);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(query);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSelectCountSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
@ -35,6 +74,91 @@ public class AccountSqlTester {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhereSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.ID.ge(100))
|
||||
.and(ACCOUNT.USER_NAME.like("michael"));
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhereExistSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.ID.ge(100))
|
||||
.and(
|
||||
exist(
|
||||
selectOne().from(ARTICLE).where(ARTICLE.ID.ge(100))
|
||||
)
|
||||
);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhereAndOrSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.ID.ge(100))
|
||||
.and(ACCOUNT.SEX.eq(1).or(ACCOUNT.SEX.eq(2)))
|
||||
.or(ACCOUNT.AGE.in(18, 19, 20).or(ACCOUNT.USER_NAME.like("michael")));
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.groupBy(ACCOUNT.USER_NAME);
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHavingSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.groupBy(ACCOUNT.USER_NAME)
|
||||
.having(ACCOUNT.AGE.between(18,25));
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select()
|
||||
.from(ACCOUNT)
|
||||
.leftJoin(ARTICLE).on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID))
|
||||
.where(ACCOUNT.AGE.ge(10));
|
||||
|
||||
IDialect dialect = new CommonsDialectImpl();
|
||||
String sql = dialect.forSelectListByQuery(queryWrapper);
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testrSelectLimitSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user