提交 b6c8bf3e 编写于 作者: 小刘28's avatar 小刘28 💬

feat:完成账号数据存储类的基本功能,系统初始化功能及添加超级管理员账号信息;

上级 c621cc9f
import com.ubitgroup.data.AccountT;
import com.ubitgroup.model.bean.Account;
import com.ubitgroup.view.LoginM.LoginV; import com.ubitgroup.view.LoginM.LoginV;
import java.time.LocalDateTime;
/* /*
* 系统入口 * 系统入口
* */ * */
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
initSys();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
LoginV loginV = new LoginV(); LoginV loginV = new LoginV();
loginV.init(); loginV.init();
} }
private static void initSys(){
System.out.println("系统初始化中...");
Account admin = new Account("1","admin","123456","1032584581@qq.com","0","0", LocalDateTime.now(),LocalDateTime.now());
AccountT accountT = AccountT.getInstance();
accountT.add(admin);
//System.out.println(AccountT.getArrayList().get(0));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("系统初始化成功!");
}
} }
package com.ubitgroup.data; package com.ubitgroup.data;
import com.ubitgroup.model.bean.Account;
import java.util.ArrayList; import java.util.ArrayList;
/* /*
...@@ -7,7 +9,7 @@ import java.util.ArrayList; ...@@ -7,7 +9,7 @@ import java.util.ArrayList;
* */ * */
public class AccountT { public class AccountT {
private static final AccountT instance = new AccountT(); private static final AccountT instance = new AccountT();
private static ArrayList arrayList; private static ArrayList<Account> arrayList;
private AccountT(){ private AccountT(){
init(); init();
} }
...@@ -16,11 +18,66 @@ public class AccountT { ...@@ -16,11 +18,66 @@ public class AccountT {
} }
private static void init(){ private static void init(){
arrayList = new ArrayList(); arrayList = new ArrayList<>();
} }
public static ArrayList getArrayList(){ /*
* 获取全部数据
* */
public static ArrayList<Account> getArrayList() {
return arrayList; return arrayList;
} }
/*
* 查找元素在list中的索引
* */
public Integer getIndex(String id){
int index = -1;
for (int i = 0; i < arrayList.size(); i++) {
Account account = arrayList.get(i);
if (account.getId().equals(id)){
index = i;
break;
}
}
return index;
}
/*
* 增加元素
* */
public Boolean add(Account account){
return arrayList.add(account);
}
/*
* 修改元素
* */
public Boolean set(Account account){
Integer index = getIndex(account.getId());
if (index == -1) {
return false;
}else{
Account oldAccount = arrayList.set(index,account);
return !oldAccount.equals(account);
}
}
/*
* 删除元素
* */
public Integer remove(Account[] accounts){
Integer count = 0;
for (Account account : accounts) {
Integer index = getIndex(account.getId());
if (index != -1) {
boolean flag = arrayList.remove(index);
if (flag) {
count++;
}
}
}
return count;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册