データ・ディクショナリの統合管理、動的ドロップダウン・ボックス
5770 ワード
フロントエンドxhr js
バックエンドjavaコード
action
service
java bean
util
var buildTag = {
/*
*
*/
getInfoTypeDatas:function(selectId,infoCode,defaultValue){
$.get(basePath+"/tag/build!getInfoTypeDatas.action?infoCode="+infoCode,function(arg){
for(var i=0; i<arg.length; i++){
var selected = "";
if(defaultValue){
if(arg[i].id == defaultValue){
selected = "selected";
}
}
$("<option "+selected+">",{
value:arg[i].id,
text:arg[i].name
}).appendTo($("#"+selectId));
}
},"json");
},
/*
*
*/
selectCity:function(selectId,defaultValue){
this.getInfoTypeDatas(selectId,"city",defaultValue);
},
selectCompanyType:function(selectId,defaultValue){
this.getInfoTypeDatas(selectId,"companyType",defaultValue);
},
selectApplicationType:function(selectId,defaultValue){
this.getInfoTypeDatas(selectId,"applicationType",defaultValue);
},
/**
* feedback type
* @param selectId
* @param defaultValue
*/
selectFeedbackType:function(selectId,defaultValue){
this.getInfoTypeDatas(selectId,"feedbacktype",defaultValue);
}
};
バックエンドjavaコード
action
import java.util.List;
import javax.annotation.Resource;
import com.google.gson.Gson;
import cn.com.qytx.cbb.domain.InfoType;
import cn.com.qytx.cbb.service.IInfoType;
public class BuildTagAction extends BaseAction {
private String infoCode;
@Resource(name="infoTypeImpl")
private IInfoType<InfoType> infoTypeService;
public String getInfoCode() {
return infoCode;
}
public void setInfoCode(String infoCode) {
this.infoCode = infoCode;
}
public String getInfoTypeDatas() throws Exception{
List<InfoType> list = infoTypeService.findByCode(infoCode);
if(list!=null){
Gson gson = new Gson();
ajax(gson.toJson(list));
}else{
ajax("");
}
return null;
}
}
service
public List<InfoType> findByCode(String code){
InfoType it = infoTypeDao.findByCode(code);
Integer parentId = it.getId();
return infoTypeDao.findSysList(parentId);
}
java bean
public class InfoType extends BaseEntity
{
public enum InfoCode{
feedbacktype("feedbacktype");
private InfoCode(String infocode){
this.infocode = infocode;
}
String infocode;
public String getInfoCode(){
return infocode;
}
}
/**
*
*/
private static final long serialVersionUID = 2669727616436832468L;
@Expose
private String name; // key
private String infoCode; //
private Integer recordUserId; //
private Integer parentId;
private Timestamp createDate;
private Timestamp modifyDate;
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
public Timestamp getModifyDate() {
return modifyDate;
}
public void setModifyDate(Timestamp modifyDate) {
this.modifyDate = modifyDate;
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getRecordUserId()
{
return recordUserId;
}
public void setRecordUserId(Integer recordUserId)
{
this.recordUserId = recordUserId;
}
public String getInfoCode() {
return infoCode;
}
public void setInfoCode(String infoCode) {
this.infoCode = infoCode;
}
}
util
package cn.com.qytx.ayzw.util;
import java.util.HashMap;
import java.util.Map;
import cn.com.qytx.cbb.domain.InfoType;
/**
* : ,
* : 1.0
* :
* : 4:40:07
* : 4:40:07
* :
*/
public class InfoTypeUtil {
/******* ********/
private static InfoTypeUtil instance = null;
private InfoTypeUtil(){
}
public static synchronized InfoTypeUtil getInstance(){
if(instance == null){
instance = new InfoTypeUtil();
}
return instance;
}
/******* ********/
private static Map<Integer,InfoType> container = new HashMap<Integer,InfoType>();
/**
* :
* @param
* @return
* @throws
*/
public void putToContainer(Integer id,InfoType infoType){
this.container.put(id, infoType);
}
public static InfoType getInfoTypeById(int infoTypeId){
return container.get(infoTypeId);
}
}
package cn.com.qytx.ayzw.servlet;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import cn.com.qytx.ayzw.util.InfoTypeUtil;
import cn.com.qytx.cbb.domain.InfoType;
import cn.com.qytx.cbb.service.IInfoType;
import cn.com.qytx.cbb.util.spring.SpringUtil;
public class InitInfoTypeServlet extends HttpServlet {
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();
IInfoType<InfoType> infoTypeService = (IInfoType<InfoType>) SpringUtil.getBean("infoTypeImpl");
List<InfoType> list = infoTypeService.findAll();
if(list!=null){
for(int i=0; i<list.size(); i++){
InfoTypeUtil.getInstance().putToContainer(list.get(i).getId(), list.get(i));
}
}
}
}