1. 程式人生 > >系統引數設計,即使用者詞典,把一些片語單獨放一表中,系統啟動即載入到Application中

系統引數設計,即使用者詞典,把一些片語單獨放一表中,系統啟動即載入到Application中

DictionaryAction.java

package cn.buaa.scm.action;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.buaa.scm.entity.Dictionary;
import cn.buaa.scm.service.DictionaryService;

@Controller
@RequestMapping(value="/dictionary")
public class DictionaryAction extends BaseAction {
	@Resource
	private DictionaryService dictionaryService;
	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}
	
	@RequestMapping(value="/getDictionary")
	public @PostConstruct void getDictionary(){
		System.out.println("-----------------hello看到我了嗎,我是使用者詞典----------------------");
		List<Dictionary> dictionaryList = dictionaryService.select();
		Map<String,Object> sysParam = new LinkedHashMap<>();
		Map<String,Object> supType = new LinkedHashMap<>();
		Map<String,Object> goods_color = new LinkedHashMap<>();
		if(dictionaryList.size()>0){
			for(Dictionary dictionary:dictionaryList){
				if(dictionary.getDicField().equalsIgnoreCase("supType")){
					supType.put(""+dictionary.getDicValue(), dictionary.getDicText());
					System.out.println("供應商"+dictionary.getDicValue()+","+dictionary.getDicText());
				}else if(dictionary.getDicField().equalsIgnoreCase("goods_color")){
					goods_color.put(""+dictionary.getDicValue(), dictionary.getDicText());
					System.out.println("顏色"+dictionary.getDicValue()+","+dictionary.getDicText());
				}
			}
			sysParam.put("supType", supType);
			sysParam.put("goods_color", goods_color);
			//public ServletContext application; baseAction中已經注入
			this.application.setAttribute("sysParam", sysParam);
		}
		
	}
	
}
頁面獲取map的jsp示例
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<%@ include file="/common/common.jsp"%>
<title>My JSP</title>
</head>
<body>

    <form id="ff" method="post">
       <div>
            <label for="supId">供應商編號:</label> <input type="text" name="supId" />
        </div>
        <div>
            <label for="supName">供應商:</label> <input type="text" name="supName" />
        </div>
        <div>
            <label for="supLinkman">聯絡人:</label> <input type="text"
                name="supLinkman" />
        </div>
        <div>
            <label for="supPhone">聯絡電話:</label> <input type="text"
                name="supPhone" />
        </div>
        <div>
            <label for="supAddress">聯絡地址:</label> <input type="text"
                name="supAddress" />
        </div>
                <div>
            <label for="supPay">期初應付:</label> <input type="text"
                name="supPay" />
        </div>
                <div>
            <label for="supType">供應商型別:</label>                                     
                <select id="cc" class="easyui-combobox" name="supType" style="width:200px;">   
                    <c:forEach items="${applicationScope.sysParam.supType}" var="supType">
                        <option value="${supType.key}">${supType.value}</option>   
                    </c:forEach>   
                </select>  
        </div>
        <div>
            <label for="supRemark">備註:</label>
            <textarea name="supRemark"></textarea>
        </div>
        <div>
            <input id="btn" type="button" value="提交" />
        </div>
    </form>

    <script type="text/javascript">
        $(function() {
            var win = parent.$("iframe[title='供應商管理']").get(0).contentWindow;//返回ifram頁面文件(window)
        
            $("[name='supName']").validatebox({
                required : true,
                missingMessage : '請填寫供應商!'
            });
            $("[name='supLinkman']").validatebox({
                required : true,
                missingMessage : '請填寫出聯絡人!'
            });
            $("[name='supPhone']").validatebox({
                required : true,
                missingMessage : '請填寫聯絡電話!'
            });
            //禁用驗證
            $("#ff").form("disableValidation");

            $("#btn").click(function() {
                alert("ddddddddddd");
                $("#ff").form("enableValidation");
                if ($("#ff").form("validate")) {
                    alert("------------");
                    $('#ff').form('submit', {
                        url : '${proPath}/supplier/insert.action',
                        onSubmit : function() {
                            return true;
                        },
                        success : function(count) {                         
                            if(count>0){
                        	//可以定義為對應訊息框
                                alert("成功");
                                parent.$("#win").window("close");
                                win.$("#dg").datagrid("reload");                            
                            } else{
                            	alert("新增失敗!");
                            }  
                        }
                    });

                }

            });

        });
    </script>
</body>
</html>

使用者詞典表格設計
create table dictionary
(
   dic_id               int not null auto_increment,
    dic_field             varchar(20),
    dic_value          varchar(20),
    dic_text            varchar(11),
   primary key ( dic_id)
);