Java program The growth record of the Ape (ii) the combination of the web with the custom label TLD and the Business dictionary __web

Source: Internet
Author: User
Tags tld
  * Bloggers have also done several or large or small web background projects, where the database is necessary to have a dictionary table to store a number of commonly used business dictionaries, page rendering can also be a variety of tags and expressions. When we query the data, the primary table usually stores the primary key of the dictionary table, The corresponding dictionary is then obtained through a table query. Now I want to share a "different way" and talk about learning together

ideas are as follows:
1. When the Web container is initialized, all the data in the dictionary table is cached (HashMap, or Third-party caching).
2. The data query is no longer associated with the dictionary table.
3. Page rendering time with a custom TLD tag for data display.

You may be unfamiliar with TLD tags, but it's not strange to mention the FN function of the JSTL expression. The FN function gives us the method here I no longer carry out one by one elaboration. The implementation is also implemented through Java (is not very familiar with ...). )

The custom TLD is simply a custom extension, less nonsense, back to the point, and start coding

Get dictionary list by type public static list<etldict> getetldictlist (String type) {//Create global cache map<string, List<etldic
    T>> Etldictmap = (map<string, list<etldict>>) cacheutils.get (CACHE_ETLDICT_MAP);
        if (etldictmap==null) {etldictmap = Maps.newhashmap ();  Dictionary tables are stored by type for (Etldict gt:etlDictDao.findAllList (New Etldict ()) {list<etldict> dictlist =
            Etldictmap.get (Gt.gettype ());
            if (dictlist!= null) {dictlist.add (GT);
            }else{Etldictmap.put (Gt.gettype (), lists.newarraylist (GT));
    } cacheutils.put (Cache_etldict_map, Etldictmap);
    } list<etldict> etldictlist = Etldictmap.get (type);
    if (etldictlist = = null) {etldictlist = Lists.newarraylist ();
return etldictlist; ///Get label by type and value public static string Getetldictlabel (string value, String type, string defaultvalue) {if (stringutils). Isnotblank (type) &&Amp  Stringutils.isnotblank (value)) {for (etldict gt:getetldictlist (type)) {if (Type.equals (Gt.gettype ())
            && value.equals (Gt.getvalue ()) {return Gt.getlabel ();
}} return defaultvalue; }

Make custom TLD file creation and definition

<?xml version= "1.0" encoding= "UTF-8"?> <taglib xmlns= "http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "http://" Www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ Ns/j2ee/web-jsptaglibrary_2_0.xsd "version=" 2.0 "> <description>jstl 1.1 Functions library</description&
  Gt <display-name>jstl functions etl</display-name> <tlib-version>1.1</tlib-version> < Short-name>fna</short-name> <uri>http://java.sun.com/jsp/jstl/functionse</uri> <function > <description> Method Description </description> <name> Method Name </name> <function-class> method type < /function-class> <function-signature> return value method name (parameters) </function-signature> <example> application Examples </exam ple> </function> <function> <description> Get Dictionary object list </description> <name>gete Tldictlist</name> <function-class&Gt;gt.com.etl.common.utils.etldictutils</function-class> <function-signature>java.util.list Getetldictlist (java.lang.String) </function-signature> <example>${fna:getetldictlist (type)}</ example> </function> <function> <description> Get tags by type and value </description> <name&gt
    ;getetldictlabel</name> <function-class>gt.com.etl.common.utils.EtlDictUtils</function-class> <function-signature>java.lang.string Getetldictlabel (java.lang.String, java.lang.String, java.lang.String) </function-signature> <example>${fna:getetldictlabel (value, type, defaultvalue)}</example> </ Function>

The custom TLD file reference method and the Jstl label reference are similar

Use a custom TLD tag on a page

<td>
    ${fna:keeptwodecimal (asset.costprice)}
</td>
<td>
    ${fna:keeptwodecimal ( Asset.sellprice)}
</td>
<td>
    ${fna:getetldictlabel (asset.source, ' source ', ')}
< /TD>

Code finished, you understand it?
There are two points to share with you:
1. It is possible to handle the logic of the JSTL itself by providing a label that is not possible by customizing the label 2. Another way to implement the dictionary is to use it, regardless of performance.
Welcome to the exchange of advice ....

Related Article

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.