Use Bootbox.js (level two must submit written and digital to digital China)

Source: Internet
Author: User

Page file

<#--header-->< #assign currnav = "Deposit" >< #assign title= "prepaid" >< #include "/root/commons/ HEADER.FTL "> <div class=" container "> <form id=" depositform "name=" Depositform "role=" for M "action="/root/depositlog/${schoolid}/deposit "method=" POST "> <div class=" Form-group "> < Label for= "SchoolID" > Net id</label> <input type= "text" class= "Form-control" id= "SchoolID" Name= "Schoo LId "placeholder=" for example. Udemy "value=" ${school.schoolid! "}" readonly= "readonly" > <p class= "Help-block" > globally unique, cannot be the same as other net IDs </            p> </div> <div class= "Form-group" > <label for= "name" > net name </label> <input type= "text" class= "Form-control" id= "name" name= "name" placeholder= "please fill in the net name" value= "${school.name!" } "readonly=" readonly "> </div> <div class=" Form-group "> &L T;label for= "DuratIon "> Recharge minutes <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 "> Units: minutes </p> </div> <div class=" Form-group "> <label for=" Amount "> Recharge amount <span id=" Moneytext "class=" text-muted text-sm "style=" Margi n-left:60px;font-size:12px; " > </span></label> <input type= "text" class= "Form-control" id= "Amount" name= "Amount" plac Eholder= "" > <p class= "Help-block" > Units: Meta </p> </div> <div class= "form-gr OUP "> <label for=" Note "> Remarks </label> <input type=" text "class=" Form-control "id=" not E "name=" note "placeholder=" "> </div> </form> <butt On id= "SUBMItbtn "class=" btn btn-primary "> Submit recharge Data </button> </div> <!--/container--><#--footer Start-up < #include "/ROOT/COMMONS/FOOTERBEGIN.FTL" ><script src= "/resources/js/bootbox.js" ></script><      Script>//Trigger Change $ ("#duration") when the content of the input box changes. On (' Input ', function (e) {var value=$ ("#duration"). Val ();   $.get ("/root/depositlog/input/change", {number:value},function (data) {$ ("#chinaText"). Text (data+ "minutes");  });    });      $ ("#amount"). On (' Input ', function (e) {var value=$ ("#amount"). Val ();   $.get ("/root/depositlog/input/change", {number:value},function (data) {$ ("#moneyText"). Text (data+ "Yuan");  });    });        $ ("#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 ' > net name:<span>" +name+ "</span><span style= ' margin-left:10px ' >schoolid-("+schoolid+") </span></div> "+" <div> Recharge time:<span> "+duration+" minutes </span></ Div> "+" <div> Recharge amount:<span> "+amount+" Yuan </span></div> ", Title:" Recharge Confirmation ", buttons: {su Ccess: {label: "OK", ClassName: "Btn-success", Callback:function () {document.depositForm.submit ()      ;      }}, Danger: {label: "Cancel", ClassName: "Btn-danger", Callback:function () {return;  }   }  }}); }); </script><#--footer End-->< #include "/ROOT/COMMONS/FOOTEREND.FTL" >

Infer that only a numeric string is sent

$ ("#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+ "minutes");    });    } else{    $ ("#mistakeText"). HTML ("Please enter a number!");}    );



Java class files

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;/** * Recharge Management controller. */@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;     /** * Recharge form. */@RequestMapping (value = "/{schoolid}/deposit", method = requestmethod.get) public Modelandview depositform (@PathV Ariable String SchoolID, httpservletrequest request) {//net information School School = Schoolmanager.getschool (schoo        LID);        Modelandview Mav = This.createmodelandview (request);        Mav.setviewname ("Root/depositlog/deposit");        Mav.addobject ("SchoolID", SchoolID);        Mav.addobject ("school", school);return MAV;     }/** * Handles recharge. */@RequestMapping (value = "/{schoolid}/deposit", method = requestmethod.post) public @ResponseBody String DEPOSITPO St (@PathVariable String SchoolID, httpservletrequest request) {int duration = Servletrequestutils.getintparameter ( Request, "duration", 0);//length of minutes. Units: Minute Double amount = servletrequestutils.getdoubleparameter (Request, "Amount", 0);//Price String Tradingnote = Servletrequestutils.getstringparameter (Request, "note", NULL);        Note if (Duration <= 0) {return "Invalid duration";        } if (Amount < 0) {return "Invalid amount";        }//Current administrator information root root = (root) (Request.getsession (). getattribute (Constants.root_session_name)); Trade name String Tradingname = schoolid + "Recharge" + Duration + ".        Cost: "+ Amount +" Yuan ";        Recharge information 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 + ".        Processing result: "+ rows";    Return "Success";     }/** * View recent 100 top-up Records. */@RequestMapping ("/list") public Modelandview Depositlogs (HttpServletRequest request) {//query recharge record Li        st<depositlog> depositlogs = Depositlogmanager.getdepositlogs ();        Modelandview Mav = This.createmodelandview (request);        Mav.setviewname ("Root/depositlog/list");        Mav.addobject ("Depositlogs", depositlogs);    return MAV; /** * Convert numbers to Chinese numerals * @author Prosper * @throws Unsupportedencodingexception */@RequestMapping (value= "/input/change", method = {Requestmethod.post,requestmethod.get}) public responseent        Ity<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 = {"0", "one", "two", "three", "four", "five", "six", "seven", "Eight", "Nine "};                string[] unit = {"", "ten", "Hundred", "thousand", "Million", "ten", "Hundred", "thousand", "billion", "ten"};        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 + +) {/** * Current number */R = Integer.                        ValueOf (Sb.substring (J, j+1)); if (J! = 0)/** * Previous number */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; }}



Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Use Bootbox.js (level two must submit written and digital to digital China)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.