Use SimpleValue to solve the view layer problem when TOP programming (below)

xiaoxiao2021-03-06  42

SimpleValue is a very simple value object, including ID, NAME both attributes

Public Class SimpleValue

{

Public int ID;

Public String Name;

Public String Tostring ()

{

Return Name;

}

Public Boolean Equals (Object O)

{

// Comparison according to ID

}

}

It is used to save some of the complex value objects, the object's horses to ID and key properties, such as department names to Name, you can understand that the key properties in the original object can be taken out to SimpleValue, these SimpleValue will save Cache in

SimpleValue may also have its subclasses, generally two transformations

When you have two health, such as department ID, parent department ID

Public Class TwokeyValue Extends SimpleValue

{

Public int SID; /////

}

Or, when you have both names, such as Chinese name, English name

Public Class TwonameValue Extends SimpleValue

{

Public String Sname; //

}

These will be placed in cache or in a data structure to facilitate calls when they show it. Below, explain examples of using the SimpleValue implementation user detail

First, you have to complete Cache, which is a very important step using SimpleValue.

Public Class Cache

{

Private static cache cache = new cache ();

PRIVATE MAP DEPTMAP = NULL;

Private cache ()

{

LoadDepts ();

}

Public cache instance ()

{

Return cache;

}

// Put all department information

Private void loadingdepts ()

{

Department [] all = department.getAllDept ();

DEPTMAP = new hashmap ()

SimpleValue SV = NULL;

For (int i = 0; i

{

SV = New SimpleValue ();

sv.id = all [i] .id;

sv.name = all [i] .name;

DEPTMAP.PUT (New Integer (SV.ID), SV);

}

}

/ / Get the department name according to the department ID

Public SimpleValue getDept (int ID)

{

Return DeptMap.get (New Integer (ID));

}

// Get all departments

Public SimpleValue [] alldepts ()

{

}

// Refresh Cache, for example, when the administrator modifies a department, you need to synchronize Cache

Public void reloaddept ()

{

SYNCHRONIZED (this)

{

LoadDept ();

}

}

}

In the show layer, you can use SimpleValue to help you display user more information.

id: <% = Employee.ID%>

name: <% = EMPLOYE.NAME%>

dept: <% = cache.instance (). getDept (employee.dptid)%>

转载请注明原文地址:https://www.9cbs.com/read-67089.html

New Post(0)