mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
test: 测试实体类泛型的支持。
This commit is contained in:
parent
ac69fe08a3
commit
67dd7d1bcf
@ -15,18 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.mybatisflex.test.model;
|
package com.mybatisflex.test.model;
|
||||||
|
|
||||||
import com.mybatisflex.annotation.Id;
|
|
||||||
import com.mybatisflex.annotation.KeyType;
|
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Table(value = "tb_account",onSet = AccountOnSetListener.class)
|
@Table(value = "tb_account",onSet = AccountOnSetListener.class)
|
||||||
public class Account {
|
public class Account extends BaseEntity<String, Long> {
|
||||||
|
|
||||||
@Id(keyType = KeyType.Auto)
|
/*@Id(keyType = KeyType.Auto)
|
||||||
private Long id;
|
private Long id;*/
|
||||||
private String userName;
|
//private String userName;
|
||||||
private Integer age;
|
private Integer age;
|
||||||
private Date birthday;
|
private Date birthday;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
public class BaseEntity<T, ID> extends IdEntity<ID> {
|
||||||
|
|
||||||
|
protected T userName;
|
||||||
|
|
||||||
|
public T getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(T userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.model;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-13
|
||||||
|
*/
|
||||||
|
public class IdEntity<T> implements Serializable {
|
||||||
|
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
protected T id;
|
||||||
|
|
||||||
|
public T getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(T id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.common;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
|
import com.mybatisflex.test.model.Account;
|
||||||
|
import com.mybatisflex.test.model.BaseEntity;
|
||||||
|
import com.mybatisflex.test.model.UserVO;
|
||||||
|
import org.apache.ibatis.reflection.Reflector;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-13
|
||||||
|
*/
|
||||||
|
class FieldTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() {
|
||||||
|
String genericString = BaseEntity.class.toGenericString();
|
||||||
|
System.out.println(genericString);
|
||||||
|
List<String> genericParameters = StringUtil.getGenericParameters(genericString);
|
||||||
|
System.out.println(genericParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test02() {
|
||||||
|
Class<Account> accountClass = Account.class;
|
||||||
|
Method[] declaredMethods = accountClass.getMethods();
|
||||||
|
Arrays.stream(declaredMethods)
|
||||||
|
.filter(e -> e.getName().startsWith("get"))
|
||||||
|
.forEach(System.out::println);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test03() {
|
||||||
|
Reflector reflector = new Reflector(Account.class);
|
||||||
|
Class<?> id = reflector.getGetterType("id");
|
||||||
|
Class<?> userName = reflector.getGetterType("userName");
|
||||||
|
Class<?> age = reflector.getGetterType("age");
|
||||||
|
System.out.println(id);
|
||||||
|
System.out.println(userName);
|
||||||
|
System.out.println(age);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test04() {
|
||||||
|
Reflector reflector = new Reflector(UserVO.class);
|
||||||
|
Class<?> roleList = reflector.getGetterType("roleList");
|
||||||
|
System.out.println(roleList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.Account;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2023-06-13
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
class AccountMapperTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AccountMapper accountMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testInsert() {
|
||||||
|
Account account = new Account();
|
||||||
|
account.setBirthday(new Date());
|
||||||
|
account.setUserName("张三");
|
||||||
|
account.setAge(18);
|
||||||
|
accountMapper.insert(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdate() {
|
||||||
|
Account account = new Account();
|
||||||
|
account.setId(1L);
|
||||||
|
account.setAge(58);
|
||||||
|
accountMapper.update(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDelete() {
|
||||||
|
accountMapper.deleteById(1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSelect() {
|
||||||
|
accountMapper.selectListByQuery(QueryWrapper.create()).forEach(System.err::println);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user