이 기사는 참조를 위해 Java Bookstore 시스템의 졸업 설계의 두 번째 장을 공유합니다. 특정 내용은 다음과 같습니다
1. 사용자 관리 (user.txt)
필드 이름과 순서
참고 : 유형은 int 유형이며 연산자의 유형을 나타내는 데 사용됩니다.
1- 관리자로 표시되면 모든 작업을 수행 할 수 있습니다.
2- 책 모듈을 운영 할 수있는 사람으로서
3- 구매 모듈을 운영 할 수있는 사람으로 표현
4- 판매 모듈을 운영 할 수있는 사람으로 표현
5- 인벤토리 모듈을 운영 할 수있는 사람으로 표현
유형은 열거 구현을 사용합니다
package cn.hncu.bookstore.user.common; public enum usertypeenum {admin (1, "슈퍼 관리자"), Book (2, "Librarian"), in (3, "구매 관리자"), Out (4, "Sales Administrator"), Stock (5, "Inventory Administrator"); 개인 최종 int 유형; 개인 최종 문자열 이름; usertypeenum (int type, string name) {// default private this.name = name; this.type = 유형; } public int gettype () {return type; } public String getName () {return name; } public static int gettypebyName (String name) {for (usertypeenum utm : usertypeenum.values ()) {if (utm.getname (). equals (name.trim ()) {return utm.gettype (); }} 새로운 불법 불법 행위 렉스크 ( "" ""+이름+"/")에 해당하는 사용자 유형 없음} 공개 정적 문자열 getNameBytype (int type) {for (userTypeenum utm : userTypeenum.values ()) {if (utm.getType () ==} {return utm.getname ()} 불법 행정 렉스크 ( "" ""+유형+"/"에 해당하는 사용자 유형 없음; // 불법 매개 변수 예외}}package cn.hncu.bookStore.user.vo;import java.io.Serializable;import cn.hncu.bookStore.user.common.UserTypeEnum;/** * *@author<a href="mailto:[email protected]">xzm</a> */public class UserModel implements Serializable{ private static final long SerialVersionUID = 1L; 개인 문자열 UUID, 이름, pwd; // 사용자 번호, 사용자 이름, 사용자 비밀번호 개인 int 유형; // 사용자 유형 public usermodel () {} public String getUuid () {return uuid; } public void setUuid (String Uuid) {this.uuid = uuid; } public String getName () {return name; } public void setName (문자열 이름) {this.name = 이름; } public String getPwd () {return pwd; } public void setpwd (문자열 pwd) {this.pwd = pwd; } public int gettype () {return type; } public void settype (int type) {this.type = type; } @override public int hashcode () {Final int prime = 31; int result = 1; result = prime * result + ((uuid == null)? 0 : uuid.hashcode ()); 반환 결과; } @override public boolean equals (Object obj) {if (this == obj) return true; if (obj == null) false를 반환합니다. if (getClass ()! = obj.getClass ()) false를 반환합니다. Usermodel Other = (usermodel) obj; if (uuid == null) {if (Other.uuid! = null) false를 반환합니다. } else if (! uuid.equals (기타 .uuid)) false를 반환합니다. 진실을 반환하십시오. } @override public String toString () {return uuid + "," + name + "," + userTypeenum.getNameByType (type); }}
패키지 cn.hncu.bookstore.user.vo; public class userQueryModel 확장 usermodel {private static final long serialversionuid = 1l;}DAO 레이어 :
패키지 cn.hncu.bookstore.user.dao.dao; import java.util.list; import cn.hncu.bookstore.user.vo.usermodel; import cn.hncu.bookstore.user.vo.userquerymodel; public interface userface userdao { /*** 새로운 사용자 등록. 사용자가 존재하는 경우 생성 할 수 없습니다 * @param 사용자 * 사용자를 생성 할 수 없습니다 * @return * 생성이 성공하면 true를 반환합니다. 그렇지 않으면 false */ public boolean create (usermodel user)를 반환합니다. /*** 사용자를 삭제합니다. 사용자가 존재하지 않으면 실패 * @param uuid * 삭제되는 사용자의 uuid * @return * 삭제가 성공하면 true를 반환합니다. /*** 사용자 정보를 업데이트합니다. 사용자가 존재하지 않으면 * @param user * 사용자를 업데이트 할 수 없습니다 * 업데이트가 성공하면 False */ public boolean update (usermodel user); / ** * 사용자의 데이터를 쿼리 * @param uuid * query가 될 정보의 사용자 번호 * @return * 사용자가 존재하는 경우 지정된 UUID의 사용자 개체를 반환하십시오. / *** 쿼리 값 객체 조건의 조건에 따라 사용자를 충족시키는 모든 사용자 객체를 반환하십시오* @param user* 쿼리 값 객체* @return* 쿼리 값 객체 제약 조건을 충족하는 사용자가있는 경우 사용자 객체 수집을 반환하고 그렇지 않으면 빈 세트를 반환하십시오*/ public list <Sermodel> getByCondition (userQueryModel user); / *** 파일에서 모든 사용자 객체를 가져옵니다* @return* 파일의 모든 사용자 객체를 반환*/ public list <Sermodel> getall ();} 패키지 cn.hncu.bookstore.user.dao.impl; import java.util.arraylist; import java.util.list; import cn.hncu.bookstore.user.dao.dao.userdao; import cn.hncu.bookstore.user.vo.usermodel; 수입 cn.hncu.bookstore.user.vo.usequeryModel; import cn.hncu.bookstore.utils.fileioutil; public class userDaofileimpl userDao {private final static string file_name = "a.txt"; @override public boolean create (usermodel user) {if (user == null) {// 등록 할 사용자 정보가 null이면 등록 할 수없고 false return false를 반환합니다. } list <asermodel> list = getall (); // 이미 파일에 이미 존재하는 모든 사용자 객체를 가져옵니다 (usermodel u : list) {// travel if (u.getuuid (). equals (user.getuuid ())) {//이 사용자가 이미 존재하면 등록 할 수 없습니다. }} // 위의 순회 후에는 사용자가 존재하지 않음을 의미하며 list.add (user)를 등록 할 수 있습니다. return fileioutil.writetofile (list, file_name); } @override public boolean delete (string uuid) {list <asermodel> list = getall (); for (int i = 0; i <list.size (); i ++) {// tranquility usermodel u = list.get (i); if (u.getUuid (). Equals (uuid)) {list.remove (i); // return fileioutil.writetofile (list, file_name); }} 거짓을 반환합니다. } @override public boolean update (usermodel user) {list <Sermodel> list = getall (); for (int i = 0; i <list.size (); i ++) {usermodel u = list.get (i); if (u.getUuid (). equals (user.getUuid ())) {list.set (i, user); // user.getUuid () return fileioutil.writetofile (list, file_name)에 번호를 다시 설정합니다. }} 거짓을 반환합니다. } @override public usermodel getSingle (String UUID) {list <Sermodel> list = getAll (); for (usermodel u : list) {if (u.getuuid (). equals (uuid)) {return u; }} return null; } @override public list <Scermodel> getByCondition (userQueryModel user) {list <Sermodel> list = getAll (); List <SCERMODEL> RESLIST = NEW ARRAYLIST <SURMODEL> (); for (usermodel u : list) {if (user.getuuid ()! = null && user.getuuid (). longth ()> 0) {if (! user.getuuid (). trim (). }} if (user.getName ()! = null && user.getName (). trim (). length ()> 0) {if (u.getName (). indexf (user.getName ()) == -1) {계속; }} if (user.getType ()> 0) {if (u.getType ()! = user.getType ()) {계속; }} reslist.add (u); } 리턴리스트리스트; } @override public list <Scermodel> getAll () {return fileioutil.readfromfile (file_name); }} 패키지 cn.hncu.bookstore.user.dao.factory; import cn.hncu.bookstore.user.dao.dao.userdao; import cn.hncu.bookstore.user.dao.impl.userdaofileimpl; public userdaofactory () {) {} {) {} {) getUserDao () {return new userDaofileImpl (); }}비즈니스 로직 계층 :
패키지 CN.hncu.bookstore.user.business.ebi; import java.util.list; import cn.hncu.bookstore.user.vo.usermodel; import cn.hncu.bookstore.user.vo.userquerymodel; public interface userebi {usermodel 사용자); 공개 부울 삭제 (String UUID); 공개 부울 업데이트 (Usermodel User); 공개 usermodel getsingle (String uuid); 공개 목록 <Scermodel> getByCondition (userQueryModel user); 공개 목록 <Surmodel> getall (); 공개 초록 목록 <usermodel> getallin (); 공개 목록 <CERESMODEL> getAllout ();} 패키지 cn.hncu.bookstore.user.business.ebo; import java.util.list; import cn.hncu.bookstore.common.uuidmodelconstance; import cn.hncu.bookstore.common.uuid.dao.factory.uuiddaofactory; import cn.hncu.bookstore.user.business.ebi.userebi; import cn.hncu.bookstore.user.common.usertypeenum; import cn.hncu.bookstore.user.dao.dao.userdao; import cn.hncu.bookstore.user.dao cn.hncu.bookstore.user.vo.usermodel; import cn.hncu.bookstore.user.vo.usquerymodel; public class aserebo empererebi {// userdao dao = userDaofactory.getUserDao (); @override public boolean create (usermodel user) {string uuid = uuiddaofactory.getuuiddao (). getnextnum (uuidmodelconstance.user); user.setuuid (uuid); return dao.create (사용자); } @override public boolean delete (string uuid) {return dao.delete (uuid); } @override public boolean update (usermodel user) {return dao.update (user); } @override public usermodel getsingle (string uuid) {return dao.getsingle (uuid); } @override public list <Scermodel> getByCondition (userQueryModel user) {return dao.getByCondition (user); } @override public list <Scermodel> getAll () {return dao.getall (); } @override public list <Scermodel> getAllin () {userQueryModel user = new userQueryModel (); user.settype (usertypeenum.in.gettype ()); return dao.getByCondition (user); } public list <asermodel> getAllout () {userQueryModel user = new userQueryModel (); user.settype (usertypeenum.out.gettype ()); return dao.getByCondition (user); }} 패키지 cn.hncu.bookstore.user.business.business.business.business.business.business.ebi.userebi; import cn.hncu.bookstore.user.business.ebo.userebo; public class aserebifactory {private userebificatory (public static userebi) getererebi geterbi userebo (); }} 위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.