做个单选择框

效果图


效果图

跳转页面接口

    /**
     * 短信模板管理页面
     * @return
     */
    @RequestMapping("messageConfigPage")
    @Token(create=true)
    public String bondManagePage(Model model) {
               //取配置文件短信服务商
        String configFileName = "msgPlat.properties";
        Integer SMS_PLAT_TYPE = Integer.valueOf(ResourceUtil.getConfigNoCache(configFileName,"SMS_PLAT_TYPE"));
        model.addAttribute("SMS_PLAT_TYPE", SMS_PLAT_TYPE);
        return "user/messageConfig";
    }

/**
     * 修改短信服务商接口
     */
    @RequestMapping(value = "/update/{type}")
    @ResponseBody
    private  String update(HttpServletResponse resp,@PathVariable String type){
        try {
            String configFileName = "msgPlat.properties";
            ResourceUtil.setConfigNoCache(configFileName,"SMS_PLAT_TYPE",type);
            //resp.getWriter().print("success");
            return "{\"success\":true}";
        } catch (Exception e) {
            e.printStackTrace();
            return "{\"success\":false}";
        }
    }

页面

    

注意:当用户点击一个单选按钮时,对应短信服务商会发生变动。


短信服务商:

改配置文件

package com.yc.ssm.framwork.utils;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class ResourceUtil {
    private static Properties sysConfig = new Properties();
    private static Properties urlConfig = new Properties();
    
    private static Map configs = new HashMap();
    private static String CLASSPATH = ResourceUtil.class.getResource("/").getPath();
    
    static {
        try {
            System.out.println("context:" + getContextRealPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private static void getResource(Properties config, String file) throws Exception {
        FileReader fr = new FileReader(CLASSPATH + file);
        config.load(fr);
    }
    
    public static String getSystemCfg(String key) {
        return sysConfig.getProperty(key, null);
    }
    
    public static String getUrlCfg(String key) {
        return urlConfig.getProperty(key, null);
    }
    
    public static Properties getProperties(String file) {
        try {
            Properties _sysConfig;
            if(!file.endsWith(".properties")) {
                file += ".properties";
            }
            _sysConfig = configs.get(file);
            if(_sysConfig == null) {
                _sysConfig = new Properties();
                getResource(_sysConfig, file);
                configs.put(file, _sysConfig);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return configs.get(file);
    }
    
    public static Properties getUrlCfgProperties() {
        return urlConfig;
    }
    
    public static Properties getDBMapCfgProperties() {
        return getProperties("dbmap-config.properties");
    }
    
    /**
     * 从指定配置文件中获取指定key的
     * @param file 可以是全名,也可以是不带后缀名的
     * @param key
     * @return
     */
    public static String getConfig(String file, String key) {
        Properties _sysConfig;
        try {
            if(!file.endsWith(".properties")) {
                file += ".properties";
            }
            
            _sysConfig = configs.get(file);
            if(_sysConfig == null) {
                _sysConfig = new Properties();
                getResource(_sysConfig, file);
                configs.put(file, _sysConfig);
            }
            
            return _sysConfig.getProperty(key, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    public static String getConfigNoCache(String file, String key) {
        String CLASSPATH1 = CLASSPATH.substring(0, CLASSPATH.length() - 8);
        Properties _sysConfig;
        try {
            if(!file.endsWith(".properties")) {
                file += ".properties";
            }
            _sysConfig = new Properties();
            FileReader fr = new FileReader(CLASSPATH1 + file);
            _sysConfig.load(fr);
            
            return _sysConfig.getProperty(key, null);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void setConfigNoCache(String file, String key,String value) {
        String CLASSPATH1 = CLASSPATH.substring(0, CLASSPATH.length() - 8);
        Properties _sysConfig;
        try {
            if(!file.endsWith(".properties")) {
                file += ".properties";
            }
            File file1 = new File(CLASSPATH1 + file);
            _sysConfig = new Properties();
            _sysConfig.load(new FileInputStream(file1));
            _sysConfig.setProperty(key, value);
            FileOutputStream fr = new FileOutputStream(CLASSPATH1 + file);
            _sysConfig.store(fr,null);
             fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getContextRealPath() {
        //return CLASSPATH.substring(0, CLASSPATH.indexOf("/WEB-INF"));
        return "";
    }
}

你可能感兴趣的:(做个单选择框)