Use bootbox. js to write a secondary confirmation submission (and convert numbers to Chinese numbers ),

Source: Internet
Author: User

Use bootbox. js to write a secondary confirmation submission (and convert numbers to Chinese numbers ),

Page files

<# -- Page header --> <# assign curnav = "deposit"> <# assign title = "online school recharge"> <# 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 "> online school ID </label> <input type =" text" class = "form-control" id = "schoolId" name = "schoolId" placeholder = "E. g, udemy "value =" $ {School. schoolId! ''}" Readonly = "readonly"> <p class = "help-block"> globally unique, cannot be the same as the ID of other online schools </p> </div> <div class = "form-group"> <label for = "name"> online school name </label> <input type = "text" class = "form-control" id = "name" name = "name" placeholder = "Enter the online school name" value = "$ {school. name! ''}" Readonly = "readonly"> </div> <div class = "form-group"> <label for = "duration"> recharge in 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"> unit: minutes </p> </div> <div class = "form-group"> <label for = "amount"> Recharge 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"> unit: RMB </p> </div> <div class = "form-group"> <label for = "note"> remarks </label> <input type = "text" class = "form-control" id = "note" name = "note" placeholder = ""> </div> </form> <button id = "submitBtn" class = "btn btn-primary "> submit recharge data </butt On> </div> <! --/Container --> <# -- footer start --> <# include "/root/commons/footerBegin. ftl "> <script src ="/resources/js/bootbox. js "> </script> <script> // triggers change $ (" # duration ") when the content in the input box changes "). on ('input', function (e) {var value = $ ("# duration "). val (); $. get ("/root/depositlog/input/change", {number: value}, function (data) {$ ("# chinaText "). text (data + "Minute") ;}) ;}$ ("# 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'> online school name: <span>" + name + "</span> <span style = 'margin-left: 10px '> schoolId-("+ schoolId +") </span> </div> "+" <div> recharge duration: <span> "+ duration +" Minutes </span> </div> "+" <div> Recharge Amount: <span> "+ amount +" RMB </span> </div> ", title:" recharge confirmation ", buttons: {success: {label:" OK ", className: "btn-success", callback: function () {document. depositForm. submit () ;}, danger: {label: "canceled", className: "btn-danger", callback: function () {return ;}}}) ;}); </script> <# -- footer end --> <# include "/root/commons/footerEnd. ftl ">

It is determined that the message is sent only when it is a numeric string.

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



Java 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 or G. 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. B Ind. 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 actrootcontroller {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 (@ PathVariable String schoolId, HttpServletRequest request) {// School school Information = schoolManager. getSchool (schoolId); ModelAndView mav = this. createModelAndView (request); mav. setViewName ("root/depositLog/deposit"); mav. addObject ("schoolId", schoolId); mav. addObject ("school", school); ret Urn mav;}/*** process recharge. */@ RequestMapping (value = "/{schoolId}/deposit", method = RequestMethod. POST) public @ ResponseBody String depositPost (@ PathVariable String schoolId, HttpServletRequest request) {int duration = ServletRequestUtils. getIntParameter (request, "duration", 0); // the number of minutes in minutes. Unit: minute double amount = ServletRequestUtils. getDoubleParameter (request, "amount", 0); // price String tradingNote = ServletRequestUtils. getStr IngParameter (request, "note", null); // remarks 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); // transaction name String tradingName = schoolId + "recharge" + duration + ", fee:" + amount + "RMB "; // recharge information DepositLog depositLog = new DepositLog (); depositLog. setSchoolId (schoolId); d EpositLog. 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 (t RadingName + ", processing result:" + rows); return "success" ;}/ *** view the last 100 recharge records. * // @ RequestMapping ("/list") public ModelAndView depositLogs (HttpServletRequest request) {// query the recharge record List <DepositLog> depositLogs = depositLogManager. getDepositLogs (); ModelAndView mav = this. createModelAndView (request); mav. setViewName ("root/depositLog/list"); mav. addObject ("depositLogs", depositLogs); return mav;}/*** converts a number to a Chinese number * @ author Prosper * @ throws UnsupportedEncodingException */@ Requ EstMapping (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); // Htt PStatus 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", "1", "2", "3", "4 ", "5", "6", "7", "8 ", "Nine"}; String [] unit = {"", "Ten", "Hundred", "Thousand", "Ten", "Hundred ", "Thousands", "hundreds of millions", "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 digit */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 ;}}




(1/2) extract one number from the numbers 1, 2, and 3 twice without replacement, and use (x, y) to represent "Number x for the first time, the second time, the number is y"

This is equal to two
So it is 6.
 
, 5 digits 1 2 3 4 5 The first transfer is to put the numbers on both sides to the right, the second move the numbers on both sides to the left, the third

Tested: the first question is no solution, and it will never be less than 54321
The second question changes to 12345 every six cycles.

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.