1、構建實體app
/** * @author beth * @data 2019-10-20 22:30 */ @Data @EqualsAndHashCode(callSuper = false) public class UserInfo extends Model<UserInfo> { private static final long serialVersionUID = 1L; /** * 密碼 */ private String password; /** * 用戶名 */ private String username; /** * 年齡 */ private Integer age; /** * 建立時間 */ private LocalDateTime createTime; /** * 修改時間 */ private LocalDateTime updateTime; /** * 郵箱 */ private String email; /** * 電話 */ private String phone; /** * 上級 */ private String parentId; }
2、必要的mapper測試
@Repository public interface UserInfoMapper extends BaseMapper<UserInfo> { }
3、測試code
/** * @author beth * @data 2019-10-20 22:35 */ public class ARTest { /** * 新增 */ @Test public void insert() { UserInfo userInfo = new UserInfo(); userInfo.setUsername("肖娟"); userInfo.setAge(29); userInfo.setEmail("xj@qq.com"); userInfo.setParentId("445465"); userInfo.setCreateTime(LocalDateTime.now()); boolean insert = userInfo.insert(); } /** * 根據id查詢 */ @Test public void selectById() { UserInfo userInfo = new UserInfo(); UserInfo userInfoSelect = userInfo.selectById("3243543534"); System.out.println(userInfo == userInfoSelect); System.out.println(userInfoSelect); } /** * 根據id查詢 */ @Test public void selectById2() { UserInfo userInfo = new UserInfo(); userInfo.setId("54543545"); UserInfo userInfoSelect = userInfo.selectById(); System.out.println(userInfo == userInfoSelect); System.out.println(userInfoSelect); } /** * 根據id刪除 */ @Test public void deleteById() { UserInfo userInfo = new UserInfo(); userInfo.setId("54543545"); boolean r = userInfo.deleteById(); System.out.println(r); } /** * 新增或修改 */ @Test public void insertOrUpdate() { UserInfo userInfo = new UserInfo(); userInfo.setUsername("肖娟"); userInfo.setAge(29); userInfo.setEmail("xj@qq.com"); userInfo.setParentId("445465"); userInfo.setCreateTime(LocalDateTime.now()); boolean insert = userInfo.insertOrUpdate(); } } ```