From 615933c50a39a4e8df52c89aa4054ef24a3c4531 Mon Sep 17 00:00:00 2001 From: zhai_lw Date: Thu, 10 Jan 2019 21:37:10 +0800 Subject: [PATCH] =?UTF-8?q?1,=E5=90=8E=E7=AB=AF=E6=B3=A8=E5=86=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/user/utils/AccountManagement.java | 4 ++-- src/utils/Utils.java | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/core/user/utils/AccountManagement.java b/src/core/user/utils/AccountManagement.java index 23b738d..7246b15 100644 --- a/src/core/user/utils/AccountManagement.java +++ b/src/core/user/utils/AccountManagement.java @@ -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 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) { diff --git a/src/utils/Utils.java b/src/utils/Utils.java index 1a142d7..a1c7c56 100644 --- a/src/utils/Utils.java +++ b/src/utils/Utils.java @@ -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 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 formatUserInfo(String userType, List userInfo){ + for(int i=0;i