Merge remote-tracking branch 'remotes/origin/master' into hechu1

zgl
何楚 6 years ago
commit c2cea81958

@ -1,6 +1,5 @@
package core.user.utils;
import core.user.Administrator;
import core.user.User;
import dao.DBManagement;
import error.GExcptAccount;
@ -53,6 +52,7 @@ public interface AccountManagement {
return null;
}
static User register(String userType, List<String> necessaryInfo) throws GExcptSQL {
necessaryInfo = Utils.formatUserInfo(userType,necessaryInfo);
String sql = "INSERT INTO "+userType+" VALUES(\'";
for(String info:necessaryInfo){
sql+=info+"\', \'";
@ -69,7 +69,7 @@ public interface AccountManagement {
}
static User getUser(String userType){
try {
return (User) Class.forName("core.user."+ Utils.toUpperFristChar(userType)).getDeclaredConstructor().newInstance();
return (User) Class.forName("core.user."+ Utils.toUpperFirstChar(userType)).getDeclaredConstructor().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {

@ -1,9 +1,28 @@
package utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface Utils {
public static String toUpperFristChar(String string) {
public static Map<String,Integer> userAttrNum =new HashMap<>()
{
{
userAttrNum.put("administrator",5);
userAttrNum.put("student",7);
userAttrNum.put("teacher",8);
}
};
public static String toUpperFirstChar(String string) {
char[] charArray = string.toCharArray();
charArray[0] -= 32;
return String.valueOf(charArray);
}
public static List<String> formatUserInfo(String userType, List<String> userInfo){
for(int i=0;i<userAttrNum.get(userType)-userInfo.size();i++){
userInfo.add("");
}
return userInfo;
}
}

Loading…
Cancel
Save