效果图

跳转页面接口
/**
* 短信模板管理页面
* @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}";
}
}
页面
<div class="input-group" style="text-align: center;margin:100px">
<p style="color:red"><b>注意:</b>当用户点击一个单选按钮时,对应短信服务商会发生变动。</p>
<br>
短信服务商:
<label><input id="inc1" type="radio" name="type" value="1" class="custom-control-input" ${SMS_PLAT_TYPE == 1 ? 'checked' : ''}>掌中宝</label>
<label><input id="inc0" type="radio" name="type" value="2" class="custom-control-input" ${SMS_PLAT_TYPE == 2 ? 'checked' : ''}>示远</label>
</div>
<script>
$(document).ready(function() {
$('input[type=radio][name=type]').change(function() {
var value = this.value;
$.ajax({
url : '${basePath}/orderSys/message/update/'+value,
type : 'post',
dataType : 'json',
success : function(r) {
if (r.success) {
if (value == '1') {
$.messager.alert('提示',"现在选择短信服务商是掌中宝");
}
else if (value == '2') {
$.messager.alert('提示',"现在选择短信服务商是示远");
}
} else {
$.messager.alert('提示', '修改失败');
}
}
});
});
});
</Script>
改配置文件
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<String, Properties> configs = new HashMap<String, Properties>();
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 "";
}
}
网友评论