使用bootbox.js(二级务必提交书面和数字到数字中国)

使用bootbox.js(二级务必提交书面和数字到数字中国)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

页面文件

<#-- 页头 -->
<#assign currNav = "deposit">
<#assign title="网校充值">
<#include "/root/commons/header.ftl">
    
    <div class="container">
        
        <form id="depositForm" name="depositForm" role="form" action="/root/depositlog/${schoolId}/deposit" method="post">
          <div class="form-group">
            <label for="schoolId">网校ID</label>
            <input type="text" class="form-control" id="schoolId" name="schoolId" placeholder="比如。udemy" value="${school.schoolId!''}" readonly="readonly">
            <p class="help-block">全局唯一,不能和其它网校的ID同样</p>
          </div>
          <div class="form-group">
            <label for="name">网校名称</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="请填写网校名称" value="${school.name!''}" readonly="readonly">
          </div>
          
          
          <div class="form-group">
            <label for="duration">充值分钟数  <span id="chinaText" class="text-muted text-sm" style="margin-left:60px;font-size:12px;"> </span></label>
            <input type="number" class="form-control" id="duration" name="duration" placeholder="">
            <p class="help-block">单位:分钟</p>
          </div>
          <div class="form-group">
            <label for="amount">充值金额  <span id="moneyText" class="text-muted text-sm" style="margin-left:60px;font-size:12px;"> </span></label>
            <input type="text" class="form-control" id="amount" name="amount" placeholder="">
            <p class="help-block">单位:元</p>
          </div>
          <div class="form-group">
            <label for="note">备注</label>
            <input type="text" class="form-control" id="note" name="note" placeholder="">
          </div>          
          
        </form>
        
          <button  id="submitBtn" class="btn btn-primary">提交充值数据</button>
      
    </div> <!-- /container -->

<#-- 页脚開始 -->
<#include "/root/commons/footerBegin.ftl">

<script src="/resources/js/bootbox.js"></script>

<script>
    //在输入框内容变化的时候触发change
	  $("#duration").on('input',function(e){
		  var value=$("#duration").val();
		   
		   $.get("/root/depositlog/input/change",{number:value},function(data){
			   $("#chinaText").text(data+" 分钟");
		   });
	  });
	  
	  $("#amount").on('input',function(e){
		  var value=$("#amount").val();
		   
		   $.get("/root/depositlog/input/change",{number:value},function(data){
			   $("#moneyText").text(data+" 元");
		   });
	  });
	  
	  $("#submitBtn").click(function(){
	        var schoolId=$("#schoolId").val();
	        var name=$("#name").val();
	        var duration=$("#duration").val();
	        var amount=$("#amount").val();
	        
	        
	      	bootbox.dialog({
			  message: "<div id='schoolName'>网校名称:<span>"+name+"</span><span style='margin-left:10px'>schoolId-("+schoolId+")</span></div>"+
			           "<div>充值时长:<span>"+duration+" 分钟</span></div>"+
			           "<div>充值金额:<span>"+amount+" 元</span></div>",
			  title: "充值确认",
			  buttons: {
				    success: {
				      label: "确定",
				      className: "btn-success",
				      callback: function() {
				        document.depositForm.submit();
				      }
				    },
				   danger: {
				      label: "取消",
				      className: "btn-danger",
				      callback: function() {
				        return;
				      }
				   }
			  }
			});
			
	  });
</script>

<#-- 页脚结束 -->
<#include "/root/commons/footerEnd.ftl">

推断仅仅有是数字字符串才发送

$("#duration").on('input',function(e){  
	    var value=$("#duration").val();
	    //alert($.isNumeric(value));
	
	    if($.isNumeric(value)){
	    	$("#mistakeText").html("");
	    	$.get("/springmvc/input/change",{number:value},function(data){
		    	$("#chinaText").html(data+"分钟");
		    });
	    }else{
	    	$("#mistakeText").html("请输入数字!");
	    }
	    
	});

Java类文件

package com.school.web.controller.root;

import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.school.business.DepositLogManager;
import com.school.business.SchoolManager;
import com.school.domain.DepositLog;
import com.school.domain.Root;
import com.school.domain.School;
import com.school.stereotype.YesNoStatus;
import com.school.util.Constants;

/**
 * 充值管理的控制器。
 */
@Controller("rootDepositManagementController")
@RequestMapping("/root/depositlog")
public class DepositManagementController extends AbstractRootController {

    private static final Logger LOG = LoggerFactory.getLogger(DepositManagementController.class);

    @Autowired
    private SchoolManager schoolManager;

    @Autowired
    private DepositLogManager depositLogManager;

    /**
     * 充值表单。
     */
    @RequestMapping(value = "/{schoolId}/deposit", method = RequestMethod.GET)
    public ModelAndView depositForm(@PathVariable String schoolId, HttpServletRequest request) {

        // 网校信息
        School school = schoolManager.getSchool(schoolId);

        ModelAndView mav = this.createModelAndView(request);
        mav.setViewName("root/depositLog/deposit");
        mav.addObject("schoolId", schoolId);
        mav.addObject("school", school);
        return mav;
    }

    /**
     * 处理充值。
     */
    @RequestMapping(value = "/{schoolId}/deposit", method = RequestMethod.POST)
    public @ResponseBody String depositPost(@PathVariable String schoolId, HttpServletRequest request) {

        int duration = ServletRequestUtils.getIntParameter(request, "duration", 0);// 时长分钟数。单位:分钟
        double amount = ServletRequestUtils.getDoubleParameter(request, "amount", 0);// 价格
        String tradingNote = ServletRequestUtils.getStringParameter(request, "note", null); // 备注

        if (duration <= 0) {
            return "invalid duration";
        }

        if (amount < 0) {
            return "invalid amount";
        }

        // 当前管理员信息
        Root root = (Root) (request.getSession().getAttribute(Constants.ROOT_SESSION_NAME));

        // 交易名称
        String tradingName = schoolId + "充值" + duration + "。费用:" + amount + "元";

        // 充值信息
        DepositLog depositLog = new DepositLog();
        depositLog.setSchoolId(schoolId);
        depositLog.setTradingName(tradingName);
        depositLog.setTradingNote(tradingNote);
        depositLog.setDuration(duration);
        depositLog.setAmount(BigDecimal.valueOf(amount));
        depositLog.setOperator(root.getNickname());
        depositLog.setStatus(YesNoStatus.YES.getValue());
        depositLog.setDateAdded(new Date());
        depositLog.setLastModified(new Date());

        int rows = depositLogManager.addDepositLog(depositLog);
        LOG.info(tradingName + "。处理结果:" + rows);

        return "success";
    }

    /**
     * 查看近期100条充值记录。
     */
    @RequestMapping("/list")
    public ModelAndView depositLogs(HttpServletRequest request) {
        // 查询充值记录
        List<DepositLog> depositLogs = depositLogManager.getDepositLogs();

        ModelAndView mav = this.createModelAndView(request);
        mav.setViewName("root/depositLog/list");
        mav.addObject("depositLogs", depositLogs);
        return mav;
    }
    
    /**
     * 将数字转换成中文数字
     * @author Prosper
     * @throws UnsupportedEncodingException 
     */
    @RequestMapping(value="/input/change", method = {RequestMethod.POST,RequestMethod.GET})
    public ResponseEntity<String> getCNint(HttpServletRequest request){
        HttpHeaders headers = new HttpHeaders();
        MediaType mediaType = new MediaType("text", "plain", Charset.forName("UTF-8"));
        //MediaType mediaType = new MediaType("application", "json", Charset.forName("UTF-8"));
        headers.setContentType(mediaType);
        //HttpStatus Yes=HttpStatus.OK;
        
        String str = request.getParameter("number");
        
        if("".equals(str) && str==null){
            return new ResponseEntity<String>("no",  headers, HttpStatus.OK);
        }else{
            Integer number = Integer.parseInt(str);
            String ri=intToZH(number);
            return new ResponseEntity<String>(ri,  headers, HttpStatus.OK);
        }
         
    }
    
    public String intToZH(int i){
        String[] zh = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        String[] unit = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十"};
        
        String str = "";
        StringBuffer sb = new StringBuffer(String.valueOf(i));
        sb = sb.reverse();
        int r = 0;
        int l = 0;
        for (int j = 0; j < sb.length(); j++)
        {
            /**
             * 当前数字
             */
            r = Integer.valueOf(sb.substring(j, j+1));
            
            if (j != 0)
                /**
                 * 上一个数字
                 */
                l = Integer.valueOf(sb.substring(j-1, j));
            
            if (j == 0)
            {
                if (r != 0 || sb.length() == 1)
                    str = zh[r];
                continue;
            }
            
            if (j == 1 || j == 2 || j == 3 || j == 5 || j == 6 || j == 7 || j == 9)
            {
                if (r != 0)
                    str = zh[r] + unit[j] + str;
                else if (l != 0)
                    str = zh[r] + str;
                continue;
            }
            
            if (j == 4 || j == 8)
            {
                str =  unit[j] + str;
                if ((l != 0 && r == 0) || r != 0)
                    str = zh[r] + str;
                continue;
            }
        }
        return str;
    }

}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/117590.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 游戏建模自学真的能学出来吗?

    游戏建模自学真的能学出来吗?游戏建模自学肯定是能学出来的,但这有几个先决条件:1.高度的自律性2.时间,你得有一定的空闲时间用于学习和练习,全日制的同学们每天从早上8/9点钟一直到6点过7点都在学习、做作品,可能回家之后还在练习,一天花在建模上的时间比8个小时只多不少,所以你肯定不能指望着每天一两个小时的练习时间就能突飞猛进成为大佬(除非你有基础且天赋异禀,这个另当别论)3.有人指导帮你找出你的问题并给出改正方案最后,不可否认确实有部分同学可以通过自学入行,也确实会有很多人出于各种各样的原因觉得培训班不靠谱想自学,

  • 关于内存警告

    关于内存警告

  • 求生之路2ping高_DDS信号源

    求生之路2ping高_DDS信号源问答时间:2020年12月17日嘉宾简介:高少星:萌宝集团创始人、稻荷资本创始合伙人、《好玩的书》作者。曾任顺为资本董事总经理、百度高级投资经理,是好大夫、丁香园、一点资讯、宝宝巴士、I…

    2022年10月26日
  • linux安装有几种方法_linux查看gcc是否安装

    linux安装有几种方法_linux查看gcc是否安装Linux安装Pycharm

    2022年10月18日
  • 什么叫分销商_分销是什么意思「详细介绍」带你秒懂[通俗易懂]

    什么叫分销商_分销是什么意思「详细介绍」带你秒懂[通俗易懂]很多创业者在创业的道路上可能都会遇到一个问题那就是分销,但是很多创业者却又不懂分销是什么意思。今天我们抖音创业网大家详细地介绍一下关于分析的意思,绝对让你看完以后秒懂。分销是什么意思解释其实简单来说分销就是我们帮助别人销售商品,但是我们销售出去以后我们可以得到一定的分成,同时在我们的利润允许的情况下我们还可以继续拉下线,让其他的人成为我们的销售员工。分销实际案例模拟假如现在有一个苹果,供货商说这…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号