Kent Peng
Reprint Please specify source: http://www.cnblogs.com/xieyupeng/p/7145599.html
First, new customers 1. Data dictionary
Dictionary items used to enumerate a limited number of items
(1) The relationship between the data dictionary and other tables in the table:
To build a table statement:
CREATE TABLE' base_dict ' (' dict_id ' )varchar( +) not NULLCOMMENT'Data dictionary ID (primary key)', ' Dict_type_code 'varchar(Ten) not NULLCOMMENT'Data dictionary category codes', ' Dict_type_name 'varchar( -) not NULLCOMMENT'Data dictionary category name', ' Dict_item_name 'varchar( -) not NULLCOMMENT'data dictionary project name', ' Dict_item_code 'varchar(Ten)DEFAULT NULLCOMMENT'data dictionary item (can be empty)', ' Dict_sort 'int(Ten)DEFAULT NULLCOMMENT'Sort Fields', ' dict_enable 'Char(1) not NULLCOMMENT'1: Use 0: Deactivate', ' Dict_memo 'varchar( -)DEFAULT NULLCOMMENT'Notes', PRIMARY KEY(' dict_id ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;
(2) Mapping file configuration
Reference data Dictionary object in the Customer entity:
// referencing the associated data Dictionary object Private // Customer Source cust_source.dict_id Private // Customer Industry Private // Customer Level
To configure the data Dictionary object in the mapping file:
<!--Many-to-one - <Many-to-onename= "Cust_source"column= "Cust_source"class= "Basedict" ></Many-to-one> <Many-to-onename= "Cust_industry"column= "Cust_industry"class= "Basedict" ></Many-to-one> <Many-to-onename= "Cust_level"column= "Cust_level"class= "Basedict" ></Many-to-one>
2. Using AJAX technology in the page load dictionary drop-down
//use AJAX to load a data dictionary, generate a select//parameter 1: Data dictionary type (dict_type_code)//Parameter 2: Label ID to put the drop-down option//Parameter 3: When generating a drop-down, the Name property value of the Select tag//Parameter 4: When you need to echo, select which optionfunctionLoadselect (typecode,positionid,selectname,selectedid) {//1 Create a Select object and specify the Name property var$select = $ ("<select name=" +selectname+ "></select>"); //2 adding prompt options$select. Append ($ ("<option value=" >---Please select---</option> ")); //3 using jquery's Ajax method to access the background action$.post ("${pagecontext.request.contextpath}/basedictaction", {Dict_type_code:typecode},function(data) {//Traverse //4 Returns a JSON array object, iterating over it$.each (data,function(i, JSON) {//Each traversal creates an option object var$option = $ ("<option value= '" +json[' dict_id ']+ "' >" +json["dict_item_name"]+ "</option>"); if(json[' dict_id ') = =Selectedid) { //determine if it needs to be echoed if necessary to make it selected$option. attr ("Selected", "Selected"); } //and add to the Select Object$select. Append ($option); }); },"JSON"); //5 Put the assembled select object in the specified position on the page$("#"+PositionID). Append ($select);}
add.jsp
$ (document). Ready (function() { loadselect ("006", "Level", "cust_level.dict_id"); Loadselect ("001", "Industry", "cust_industry.dict_id"); Loadselect ("009", "source", "cust_source.dict_id"); }); </script>
Basedictaction:
Public classBasedictactionextendsActionsupport {PrivateString Dict_type_code; PrivateBasedictservice Basedictservice; @Override PublicString Execute ()throwsException {//1 Call service to obtain a data Dictionary object based on TypeCode listlist<basedict> list =Basedictservice.getlistbytypecode (Dict_type_code); //2 Convert list to JSON formatString JSON =jsonarray.fromobject (list). ToString (); //3 sending JSON to the browserServletactioncontext.getresponse (). setContentType ("Application/json;charset=utf-8"); Servletactioncontext.getresponse (). Getwriter (). write (JSON); return NULL;//tell struts2 not to process results } PublicString Getdict_type_code () {returnDict_type_code; } Public voidSetdict_type_code (String dict_type_code) { This. Dict_type_code =Dict_type_code; } Public voidSetbasedictservice (Basedictservice basedictservice) { This. Basedictservice =Basedictservice; }}
Basedictserviceimpl:
Public class Implements Basedictservice { private Basedictdao BDD; @Override public list<basedict> getlistbytypecode (String dict_type_code) { return bdd.getlistbytypecode (Dict_type_code); } Public void SETBDD (Basedictdao BDD) { this. BDD = BDD; }}
Basedictdaoimpl:
Public classBasedictdaoimplextendsBasedaoimpl<basedict>ImplementsBasedictdao {@Override PublicList<basedict>Getlistbytypecode (String dict_type_code) {//Criteria//Create an offline query objectDetachedcriteria DC = Detachedcriteria.forclass (basedict.class); //Package ConditionsDc.add (Restrictions.eq ("Dict_type_code", Dict_type_code)); //Execute Querylist<basedict> list = (list<basedict>) Gethibernatetemplate (). Findbycriteria (DC); returnlist; }}
Struts.xml
<!--- < name = "Basedictaction" Class= "Basedictaction" method= "Execute"></Action >
Applicationcontext.xml
<Beanname= "Basedictaction"class= "Cn.xyp.web.action.BaseDictAction"Scope= "Prototype" > < Propertyname= "Basedictservice"ref= "Basedictservice" ></ Property> </Bean> <Beanname= "Basedictservice"class= "Cn.xyp.service.impl.BaseDictServiceImpl" > < Propertyname= "BDD"ref= "Basedictdao" ></ Property> </Bean> </Bean> <Beanname= "Basedictdao"class= "Cn.xyp.dao.impl.BaseDictDaoImpl" > <!--Inject Sessionfactory - < Propertyname= "Sessionfactory"ref= "Sessionfactory" ></ Property> </Bean>
3. Analyze and implement new customers
Ii. adding files to new customers upload 1. File upload Page 3 requirements
<!-- File upload Page 3 requirements: 1. Theform must be post- submitted 2. form submission Type Enctype. Must be multi-segment . 3. File upload using <input type= "file"/> Components-- <form id=form1 name=form1 action= "${ PageContext.request.contextPath}/customeraction_add " method=" POST "enctype=" Multipart/form-data ">
2. Background reception (remember to generate Getset method)
// uploaded files are automatically encapsulated into the file object // provide a property in the background that is the same as the foreground input Type=file component name Private File photo; // the file name is automatically encapsulated in the attribute after the key name is submitted with the fixed suffix filename Private String photofilename; // private String photocontenttype;
Use:
Public throws Exception { if(photo!=null) { System.out.println ("file name:" + Photofilename); System.out.println ("file type:" +photocontenttype); // Save the uploaded file to the specified location Photo.renameto (new File ("e:/upload/haha.jpg")); }
Third, customer modification
Javaee--ssh Project Combat 03: Add Customer, data dictionary, file upload and modify customer