Java Bookstore system graduate design user module (2) _java

Source: Internet
Author: User
Tags uuid

This example for you to share the Java Bookstore System graduate design of the second, for your reference, the specific content as follows

1, user management (User.txt)

Field names and order

Description: the type is an int, which is used to represent the type of operation user.
1--is represented as admin, you can do all the things
2--as the person who can manipulate the library module
3--expressed as the person who can operate the inbound module
4--is represented as the person who can manipulate the sales module
5--represented as the person who can manipulate the Inventory module


Type is implemented using an enumeration

 package cn.hncu.bookStore.user.common; public enum Usertypeenum {admin (1, "super admin"), BOO
 K (2, "Librarian"), in (3, "incoming manager"), Out (4, "Sales Manager"), Stock (5, "Inventory manager");
 private final int type;
 Private final String name;
  Usertypeenum (int type,string name) {//default private THIS.name =name;
 This.type=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 (); } throw new IllegalArgumentException ("does not have this \" "+name+" \ "corresponding user type");//illegal parameter exception} public static String getnamebytype (int t
   ype) {for (Usertypeenum utm:UserTypeEnum.values ()) {if (Utm.gettype () ==type) {return utm.getname (); } throw new IllegalArgumentException ("does not have this \" "+type+" \ "corresponding user type");//illegal parameter exception}} 
Package cn.hncu.bookStore.user.vo;
Import java.io.Serializable;
Import Cn.hncu.bookStore.user.common.UserTypeEnum; /** * * @author <a href= "mailto:2402201666@qq.com" >xzm</a> * * public class Usermodel implements Serializable
 {private static final long serialversionuid = 1L; 
  private string uuid,name,pwd;//user number, user name, user password private int type;//user type public Usermodel () {} public string Getuuid () {
 return UUID;
 public void Setuuid (String uuid) {this.uuid = UUID;
 Public String GetName () {return name;
 public void SetName (String name) {this.name = name;
 Public String getpwd () {return pwd;
 } public void SetPwd (String 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 ());
 return result; @Override public boolean equals (Object obj) {if (this = = obj) return true;
  if (obj = null) return false;
  if (GetClass ()!= Obj.getclass ()) return false;
  Usermodel other = (Usermodel) obj;
  if (uuid = null) {if (other.uuid!= null) return false;
  else if (!uuid.equals (Other.uuid)) return false;
 return true;
 @Override public String toString () {return uuid + "," + Name + "," + usertypeenum.getnamebytype (type);

 }
}
Package cn.hncu.bookStore.user.vo;
public class Userquerymodel extends usermodel{
 private static final long serialversionuid = 1L;
}

DAO Layer:

Package 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 Userdao {/** * Register a new user, if the user exists, you cannot create * @param user * To be created * @return * If the creation succeeds, return true, otherwise return F
 Alse * * Public boolean Create (Usermodel user); /** * Delete a user, if the user does not exist, delete failed * @param uuid * To delete the user's UUID * @return * Returns true if the deletion succeeds, otherwise returns false */public Boolean
 Delete (String uuid); /** * Update user information, if the user does not exist, can not update * @param user * To update the information users * @return * If the update successfully returns TRUE, otherwise return false */public boolean UPDA
 Te (Usermodel user); /** * Query A user's data * @param UUID * User ID of the information to be queried * @return * If the user exists, returns the user object of the specified UUID, otherwise returns null/public Usermodel get
 Single (String uuid); 
 /** * Returns all set of user objects that satisfy users, based on query value object constraint * @param user * Query Value Object * @return * If there is a user that satisfies the criteria of the query Value object constraint, return the collection of user objects, otherwise return an empty collection.
 Public list<usermodel> getbycondition (Userquerymodel user); /** * Get all the user objects in the file * @return * Return all users in the fileObject */Public list<usermodel> getAll ();

 }
Package 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;
Import Cn.hncu.bookStore.user.vo.UserQueryModel;

Import Cn.hncu.bookStore.utils.FileIOUtil;
 public class Userdaofileimpl implements Userdao {private final static String file_name= "A.txt";
  @Override public boolean Create (Usermodel user) {if (user==null) {//If the user information to be registered is NULL, you cannot register and return false to false; List<usermodel> List=getall ()//Get all user objects that already exist in the file for (Usermodel u:list) {//Traversal if (U.getuuid (). Equals (User.getuu
   ID ()) {//If this user already exists, you cannot register return false;
  }//through the above traversal, stating that user does not exist, you can register list.add (user);
 return Fileioutil.writetofile (list, file_name);
  @Override public boolean Delete (String uuid) {list<usermodel> list=getall ();
   for (int i=0;i<list.size (); i++) {//Traverse Usermodel u=list.get (i); if (U.getuuid (). Equals (UUID)) {list.remove (i);//delete return FileIoutil.writetofile (list, file_name);
 return false;
  @Override public boolean update (Usermodel user) {list<usermodel> 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), or reset number User.getuuid () return Fileioutil.writetofile (l
   ist, file_name);
 return false;
  @Override public Usermodel Getsingle (String uuid) {list<usermodel> list=getall ();
   for (Usermodel u:list) {if (U.getuuid (). Equals (UUID)) {return u;
 } return null;
  @Override public list<usermodel> getbycondition (Userquerymodel user) {list<usermodel> list=getall ();
  List<usermodel> reslist=new arraylist<usermodel> (); for (Usermodel u:list) {if (User.getuuid ()!=null && user.getuuid (). Trim (). Length () >0) {if (!user.getuuid).
    Trim (). Equals (U.getuuid ())) {continue; } if (User.getname ()!=null && user.getname(). Trim (). Length () >0) {if (U.getname (). IndexOf (User.getname ()) ==-1) {continue;
    } if (User.gettype () >0) {if (U.gettype ()!=user.gettype ()) {continue;
  } reslist.add (U);
 return reslist;
 @Override public list<usermodel> GetAll () {return fileioutil.readfromfile (file_name);

 }

}
Package cn.hncu.bookStore.user.dao.factory;

Import Cn.hncu.bookStore.user.dao.dao.UserDAo;
Import Cn.hncu.bookStore.user.dao.impl.UserDAOFileImpl;
public class Userdaofactory {
 private userdaofactory () {
 } public
 static Userdao Getuserdao () {
  return New Userdaofileimpl ();
 }


Business Logic Layer:

Package 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 {public


 boolean create (Usermodel user);
 public boolean Delete (String uuid);
 public boolean update (Usermodel user);
 Public Usermodel Getsingle (String uuid);
 Public list<usermodel> getbycondition (Userquerymodel user);
 Public list<usermodel> getAll ();
 Public abstract list<usermodel> Getallin ();
 Public list<usermodel> getallout ();
}

Package 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.factory.UserDAOFactory;
Import Cn.hncu.bookStore.user.vo.UserModel;

Import Cn.hncu.bookStore.user.vo.UserQueryModel;
 public class Userebo implements Userebi {//inject Userdao DAO = Userdaofactory.getuserdao (); @Override public boolean Create (Usermodel user) {String Uuid=uuiddaofactory.getuuiddao (). Getnextnum (
  Uuidmodelconstance.user);
  User.setuuid (UUID);
 return dao.create (user);
 @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<usermodel> getbycondition (Userquerymodel user) {return dao.getbycondition (user);
 @Override public list<usermodel> GetAll () {return dao.getall ();
  @Override public list<usermodel> Getallin () {Userquerymodel user=new userquerymodel ();
  User.settype (UserTypeEnum.IN.getType ());
 return dao.getbycondition (user);
  Public list<usermodel> getallout () {Userquerymodel user=new userquerymodel ();
  User.settype (UserTypeEnum.OUT.getType ());
 return dao.getbycondition (user);

 }

}
Package cn.hncu.bookStore.user.business.factory;

Import Cn.hncu.bookStore.user.business.ebi.UserEbi;
Import Cn.hncu.bookStore.user.business.ebo.UserEbo;

public class Userebifactory {

 private userebifactory () {
 } public
 static Userebi Getuserebi () {
  return New Userebo ();
 }


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.