使用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)


相关推荐

  • Python函数基础[通俗易懂]

    Python函数基础[通俗易懂]函数声明、调用、返回基础Python中使用def关键字来声明函数,声明函数的格式为:有3个需要注意的地方:1.函数名后面必须加冒号2.如果函数体和def不在同一行,则必须缩进3.ret

  • 《转》OpenStack Live Migration[通俗易懂]

    《转》OpenStack Live Migration

  • Layui分页_pagehelper分页使用

    Layui分页_pagehelper分页使用本文介绍了LayUI分页,LayUI动态分页,LayUIlaypage分页,LayUIlaypage刷新当前页,分享给大家,具体如下:效果图:一、引用js依赖主要是jquery-1.11.3.min.js和layui.all.js,json2.js用来做json对象转换的二、js分页方法封装(分页使用模板laytpl)1、模板渲染/***分页模板的渲染方法*@paramtemp…

    2022年10月28日
  • 测试数据增强_预测模型最佳cutoff值

    测试数据增强_预测模型最佳cutoff值cutout是2017年提出的一种数据增强方法,想法比较简单,即在训练时随机裁剪掉图像的一部分,也可以看作是一种类似dropout的正则化方法。ImprovedRegularizationofConvolutionalNeuralNetworkswithCutoutpaper:https://arxiv.org/pdf/1708.04552.pdfcode:https://github.com/uoguelph-mlrg/Cutoutcutout采用的操作是随机裁剪掉图像中..

  • java中如何进行异常处理_java检查时异常

    java中如何进行异常处理_java检查时异常运行时异常是Java编程语言所有异常的父类,这些异常在发生时会崩溃或崩溃,可能会破坏程序或应用程序。与不被视为运行时异常的异常不同,永远不会检查运行时异常。“运行时异常”通常显示程序员的错误,而不是预期程序要处理的条件。当无法发生的情况时,也会使用运行时异常。应该注意的是,当程序内存不足时,将引发程序错误,而不是将其显示为运行时异常。最常见的运行时异常为NullPointerException,A…

  • 免费的API接口_api平台

    免费的API接口_api平台转:https://blog.csdn.net/qq_35304570/article/details/79811226声明:整理记录,自己开发过程使用,请勿用做非法途径!参考:http://developer.51cto.com/art/201412/458778.htm豆瓣:https://api.douban.com/v2/book/search?q="百年孤独" …

发表回复

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

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