美文网首页
做个单选择框

做个单选择框

作者: 螃蟹和骆驼先生Yvan | 来源:发表于2020-08-17 16:40 被阅读0次

效果图


效果图

跳转页面接口

    /**
     * 短信模板管理页面
     * @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 "";
    }
}

相关文章

  • 做个单选择框

    效果图 跳转页面接口 页面 改配置文件

  • layui的laydate点击闪退

    个人没有用到该 UI 框架,临时帮同事处理问题,做个记录。问题描述:点击input框时,时间选择框会出现闪退的情况...

  • Ps—打开文件(21)

    执行“文件>打开”命令,可以弹出“打开”对话框,选择一个文件(如果要选择多个文件,可以按住Ctrl键单击它们) 单...

  • ListView点击item底部弹出popupWindow删除、

    先看一下效果:点击单个item弹出选择框,可以选择删除或者修改。删除单条item,或者跳转到修改页面。 listv...

  • UIPickView 去掉选择框

    UIPickView 去掉选择框 UIPickerView//去掉选择框

  • 实现级联选择器组件

    开始造中级轮子级联选择器组件,遇到一个难题就是无法确定有几级弹出框供选择,例如以下的数据结构。 因此得做个递归组件...

  • 智能表单

    新增的类型: Color 颜色选择器 Date 日期选择框 Datetime 日期时间选择框 ...

  • 第二十四章 对话框

    一、系统对话框&自定义对话框 1.系统对话框 AlertDialog 普通对话框 多按钮普通对话框 列表对话框 单...

  • 购物车动画

    解决数字选择框不能正常加减数字的问题 初始化数字选择框,在数字选择框组件goodsinfo-numbox.vue中...

  • Swing对话框JOptionPane

    消息对话框 确认取消对话框 输入框对话框 选择对话框

网友评论

      本文标题:做个单选择框

      本文链接:https://www.haomeiwen.com/subject/mzpqjktx.html