Database:
Table Sys_dict
Table T_department
Dicttag.java
public class Dicttag extends bodytagsupport{/** * Create log Object/private static final Logger Logger = Logger.getlogger (D
Icttag.class);;
/** * Whether to have permission */private String Dictcode; /** * {@inheritDoc} * @see Javax.servlet.jsp.tagext.bodytagsupport#setbodycontent (javax.servlet.jsp.tagext.BodyCont
ENT) */public void setbodycontent (bodycontent BC) {super.setbodycontent (BC); /** * {@inheritDoc} * @see Javax.servlet.jsp.tagext.bodytagsupport#doafterbody ()/public int doafterbody ()
{try {getbodycontent (). Getenclosingwriter (). println (Getbodycontent (). getString ());
catch (IOException ee) {ee.printstacktrace ();
return eval_page; /** * {@inheritDoc} * @throws jspexception * @throws Exception * @see Javax.servlet.jsp.tagext.BodyTagSupp
Ort#dostarttag () */public int doStartTag () throws jspexception{try {jspwriter out = Pagecontext.getout (); if (Stringutils.isnotempty (Dictcode)) {String Dictvalue = dictutils. Getdictvalue (This.dictcode);
Out.print (Dictvalue);
}else {out.print ("");
} catch (Exception e) {e.printstacktrace ();
return skip_body;
Public String Getdictcode () {return dictcode;
} public void Setdictcode (String dictcode) {this.dictcode = Dictcode;
public static void Main (string args[]) {String a = ' AAA.BBB.CCC ';
string[] Dickkeys = A.split ("\;");
String Dictkey = dickkeys[0] + "." + dickkeys[1];
System.out.print (Dictkey);
}
}
Dictionary Table Tools Dictutils.java
public class Dictutils {public static map<string,object> Dictmap = new hashmap<string,object> ();
public static map<string, object> Getdictmap () {return dictmap;
public static void Setdictmap (Map<string, object> dictmap) {dictutils.dictmap = Dictmap; /** * Get Dictionary value * @param dictlist * @param key * @return/public static String Getdictvalue by Dictionary key (List
<SysDict> dictlist,string key) {String dictvalue = "";
if (Listutil.isnotnull (dictlist)) {for (int i=0;i<dictlist.size (); i++) {Sysdict dict = Dictlist.get (i);
if (Dict.getdictcode (). Equals (key)) {Dictvalue = Dict.getdictvalue ();
Break
}} return dictvalue;
public static string Getdictvalue (String dictcode) {string[] Dickkeys = Dictcode.split ("\.");
String Dictkey = dickkeys[0] + "." + dickkeys[1];
List<sysdict> dictlist = (list<sysdict>) dictutils.getdictmap (). get (Dictkey); String Dictvalue = DICTUTILS.GETDICTVAlue (Dictlist, Dictcode);
return dictvalue;
}
}
Introduced in the Hnpd-tags.tld file:
<span style= "White-space:pre" > </span><tag>
<name>dictValue</name>
<tag-class>
com.rmyy.web.common.tag.DictTag
</tag-class>
<body-content>empty< /body-content>
<attribute>
<name>dictCode</name>
<required>false</ required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
In Web.xml:
<span style= "White-space:pre" > </span><jsp-config>
<taglib>
< Taglib-uri>/web-inf/hnpd-tags.tld</taglib-uri>
<taglib-location>/WEB-INF/hnpd-tags.tld< /taglib-location>
</taglib>
</jsp-config>
1. Query a single information, in the controller to get to the T_department table in the category_id content, in the page through the following custom label PH will dict_code converted to the corresponding Dict_value
<ph:dictvalue dictcode= "${dept.categoryid}"/>
2. In controller, the dictionary tool is used to get the list of each section under the category, to the Drop-down box of the page.
@RequestMapping (value= "/m/department/add") public
String Add (@ModelAttribute Department department,@ Requestparam int Curpage,modelmap model) {
<span style= "color: #ff0000;" >List<SysDict> dictlist = (list<sysdict>) dictutils.getdictmap (). Get ("Department.category"); </ span>
model.addattribute ("Curpage", curpage);
Model.addattribute ("Dictlist", dictlist);
return "M/department/add";
}
In the page through the Drop-down box, select the section classification.
Itemlabel is for the user to see <pre name= "code" class= "HTML" >itemvalue is to be stored in the database
<tr>
<td width= "10%" align= "right" bgcolor= "#ffffff" >
<span class= "Fontts" > * </span> Select category:</td> <td width= "40%"
align= "left" bgcolor= "#FFFFFF" >
<sf:select path= "CategoryID" checkitems= "N" >
<option value= "" >-Please select-</option>
<sf:options items= "${dictlist}" itemlabel= "Dictvalue" itemvalue= "Dictcode"/>
</sf:select>
</td>
</tr>