System Design
Open source components and jar packages
Database driver Package
C3P0 Connection Pool Package
Dbutil components
Beanutil components
FileUpload components
development of Cuisine Management module
Core processing Code
PackageCn.cxspace.servlet;ImportCn.cxspace.entity.FoodType;Importcn.cxspace.factory.BeanFactory;ImportCn.cxspace.service.IFoodTypeService;ImportCn.cxspace.service.impl.FoodTypeService;ImportJavax.servlet.RequestDispatcher;Importjavax.servlet.ServletException;ImportJavax.servlet.annotation.WebServlet;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportJavax.servlet.http.Part;Importjava.io.IOException;Importjava.util.List;/*** Created by Cxspace on 16-6-25. * 1. Add cuisines * 2. Menu Table Show * 3. Update cuisines
* 4. Delete cuisines*/ Public classFoodtypeservletextendsHttpServlet {
Factory mode Get Service objectPrivateIfoodtypeservice Foodtypeservice = beanfactory.getinstance ("Foodtypeservice", Ifoodtypeservice.class);
URI that controls forwarding and redirectionPrivateObject URI; protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException { This. Doget (Request,response); } protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {request.setcharacterencoding ("Utf-8"); Response.setcontenttype ("Text/html;charset=utf-8"); //Get operation typeString method = Request.getparameter ("Method"); if("Addfoodtype". Equals (method)) {Addfoodtype (request,response); } Else if("List". Equals (method)) {List (request, response); } Else if("Viewupdate". Equals (method)) {viewupdate (request,response); } Else if("Delete". Equals (method)) {Delete (request,response); } Else if("Update". Equals (method)) {Update (request,response); } } //Add cuisines Public voidAddfoodtype (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {Try { //1. Get Request Data EncapsulationString foodtypename = Request.getparameter ("Foodtypename");
FoodType ft=NewFoodType (); Ft.settypename (Foodtypename); //2. Invoking service processing business logicfoodtypeservice.save (ft); //3. Jump URIURI = Request.getrequestdispatcher ("/foodtype?method=list"); }
Catch(Exception e) {e.printstacktrace (); URI= "/error/error.jsp"; }
Jump to the general processing goTo (Request,response,uri); } //Food Series Table show Public voidList (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {Try { //Call service Query all categorieslist<foodtype> list =Foodtypeservice.getall ();
Save to domain object Request.setattribute ("Listfoodtype", list); //Skip to Menu series table pageURI = Request.getrequestdispatcher ("/sys/type/foodtype_list.jsp"); }Catch(Exception e) {e.printstacktrace (); URI= "/error/error.jsp"; } goTo (Request,response,uri); }
View Updates Public voidViewupdate (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {Try { //GET Request IDString id = request.getparameter ("id"); //querying objects by IDFoodType ft =Foodtypeservice.findbyid (Integer.parseint (id)); //SaveRequest.setattribute ("FoodType", FT); //JumpURI = Request.getrequestdispatcher ("/sys/type/foodtype_update.jsp"); }Catch(Exception e) {e.printstacktrace (); URI= "/error/error.jsp"; } goTo (Request,response,uri); }
Delete Cuisines Public voidDelete (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {Try{String ID= Request.getparameter ("id"); Foodtypeservice.delete (Integer.parseint (id)); URI= "/foodtype?method=list"; }Catch(Exception e) {e.printstacktrace (); URI= "/error/error.jsp"; } goTo (Request,response,uri); }
Update Cuisines Public voidUpdate (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {Try { intid = integer.parseint (request.getparameter ("id"))); String name= Request.getparameter ("Foodtypename"); FoodType FoodType=NewFoodType (); Foodtype.setid (ID); Foodtype.settypename (name); Foodtypeservice.update (FoodType); URI= "/foodtype?method=list"; } Catch(Exception e) {e.printstacktrace (); URI= "/error/error.jsp"; } goTo (Request,response,uri); } Private voidGoTo (HttpServletRequest request, httpservletresponse response, Object URI)throwsservletexception, IOException {if(URIinstanceofRequestDispatcher) {((RequestDispatcher) URI). Forward (Request,response); }Else if(URIinstanceofString) {Response.sendredirect (Request.getcontextpath ()+URI); } }}
Common problems
1. Cuisine Management
If you delete a cuisine
First judge whether the current cuisine has been referenced, if there is no delete
2. When the cuisine is updated, the picture shows
Store the picture name when stored
Display time: Stitching
Relative directory/Picture name
/project name/directory/*.jpg
Note: Image names cannot have special characters
Picture name should not be too long
Hotel Sales Management System-2. System Design and practical development