Table structure: tmdictionary
CREATE TABLE ts_data_dic
(
ID serial not NULL,
value_name character varying () is not NULL,-the description of the value corresponds to the
valu E_code character varying (20),--the corresponding code value
type_code character varying (a), type_name character varying
(30),
comments character varying (m),
create_by Integer,
create_date timestamp, without time zone,
last_ Update_by Integer,
last_update_date timestamp without time zone,
row_version numeric (14,0) not NULL DEFAULT 0,
IsValid Numeric (1,0) not NULL default 1,
parent_id Integer,
editable integer NOT NULL default 1,
sor t integer,
CONSTRAINT pk_ts_data_dic PRIMARY key (ID),
CONSTRAINT fk_ts_data_dic FOREIGN key (parent_id)
REFERENCES ts_data_dic (ID) MATCH
simple On UPDATE RESTRICT on DELETE RESTRICT
)
The implementation returns a map<valuecode,tmdictionary> based on the incoming TypeCode
Public map<string, Tmdictionary> findbytypecode (string typecode) {
string hql= ' SELECT DISTINCT TM from Tmdictionary TM LEFT Join Tm.parent parent where tm.isvalid=:isvalid and Tm.typecode=:code ";
map<string,object> params = new hashmap<string, object> ();
Params.put ("IsValid", 1);
Params.put ("code", TypeCode);
List<tmdictionary> list= (list<tmdictionary>) dictionarydao.query (HQL, params);
Map<string,tmdictionary> map=new hashmap<string, tmdictionary> ();
For (tmdictionary dic:list) {
if (dic==null) {
continue;
}
Map.put (Dic.getvaluecode (), DIC);
}
return map;
}
Test code:
@Test public
void Findbytypecode () {
map<string, tmdictionary> map= ditionaryservice.findbytypecode (" Lockedname ");
For (entry<string, tmdictionary> entry:map.entrySet ()) {
System.out.println (Entry.getkey () + ":" + Entry.getvalue ());
}
Original link:
List:
School Number
Name
Class
1
Songjl1
Class 1, Level 01.
2
Songjl2
Class 1, Level 02.
3
Songjl3
Class 1, Level 03.
Convert to map
list<student> list = new arraylist<student> ();
Map<integer, student> map = new Hashmap<integer, student> ();
for (Student stu:list) {
if (stu==null) {
continue;
}
The student is a JavaBean object. Data number, name, class
//Number as key.
Map.put (Stu.getstuno (), Stu);
}