自动生成订单号(固定+日期+数字)
做项目的过程中,在某些项目中订单号是必须的,今天就来写订单号吧!
首先我们来写jsp页面的代码:
<%-- 单号--%>
<div class="row justify-content-end px-2"><h6 class="col-3 text-danger" style="margin-top: 5px;">单号:<text id="danhao">${number}</text></h6>
</div>
然后通过以下这个方法的modelAndView.addObject("number", numberName("CJ"));这一句代码返回并显示到页面:
public ModelAndView purchase(String sename, HttpSession session) {ModelAndView modelAndView = new ModelAndView("/CaiGou/Purch");List<suppVo> list = suppService.selectAll(null);//查询所有的供应商List<BEmployee> employeeList = employService.selectAll();//员工//排序Collections.sort(list, new Comparator<suppVo>() {@Overridepublic int compare(suppVo o1, suppVo o2) {boolean onLine1 = o1.getStatus();boolean onLine2 = o2.getStatus();//两个值进行位运算,值不同为1,为true,参与运算//值相同为0,为false,不参与运算if (onLine1 ^ onLine2) {return onLine1 ? -1 : 1;} else {return 0;}}});modelAndView.addObject("list", list);modelAndView.addObject("employeeList", employeeList);modelAndView.addObject("number", numberName("CJ"));modelAndView.addObject("sename", sename);return modelAndView;
}
然后controller的方法:
try {BAccount account1 = accountService.selectlast();int y = (new Date().getYear()) + 1900;String m = ((new Date().getMonth()) < 10 ? ("0" + (new Date().getMonth())) : (new Date().getMonth())) + "";String d = ((new Date().getDate()) < 10 ? ("0" + (new Date().getDate())) : (new Date().getDate())) + "";if (account1 != null && account1.getReceiptsnum() != null) {String dd = account1.getReceiptsnum().substring(10);String[] strings = account.getReceiptsnum().split("J");Long integer = (Long.parseLong(strings[1]) * 1) + 1;account.setReceiptsnum("DJ" + y + m + d + (Integer.parseInt(dd) + 1));//a = purchService.AddPurchse(purchase, account, ids, nus, uns);} else {account.setReceiptsnum("DJ" + y + m + d + "100001");}a = purchService.AddPurchse(purchase, account, ids, nus, uns);
} catch (Exception e) {a = "出错了......";
}
然后再处理一下:
我这里因为是采购进货所以固定字母就是“CJ”,这个可以根据每个实际情况来决定,然后就是日期,最后加上你想要加上的数字或者随机数,我这里是自己确定的数字,并且这个数字会随着订单号的增加而增加
public String numberName(String name) {List<BPurchase> number = purchService.selectnum(name);//查询采购的单号String num = "";Date b = new Date();String month = ((b.getMonth() + 1) < 10 ? ("0" + (b.getMonth() + 1)) : (b.getMonth() + 1)) + "";String date = ((b.getDate()) < 10 ? ("0" + b.getDate()) : (b.getDate())) + "";String a = b.getYear() + 1900 + month + date;if (number == null || number.size() < 1) {num = "CJ" + a + 100001;} else {String c = number.get(number.size() - 1).getReceiptsnum().substring(10);//从第十位开始往后截取//System.out.println("-----------------------"+number.get(number.size() - 1).getReceiptsnum());int d = Integer.parseInt(c) + 1;num = "CJ" + a + d;}return num;
}
最后的“100001”会随着订单的增加而自增,下图“100011”就说明了我数据库中已经有10条数据了!
然后订单号就好了,订单号生成后就自动显示到页面,效果如下图:
自动生成订单号(固定+日期+数字)相关推荐
- php根据当天日期生成编号,前台js根据当前时间生成订单号
*********前台显示框**************** **************js代码***************** function GetDateNow() { var vNow ...
- PHP制作订货,PHP生成订单号的两种方法
在开发项目的时候经常有生成订单号的需求,这里列出两种生成20位订单号的常用方法. 方法一: 以下代码是14位当前时间加6位随机数,如果增减位数,只需修改末尾的数字6即可.<?php Functi ...
- php订单号递增,PHP生成订单号的两种方法
在开发项目的时候经常有生成订单号的需求,这里列出两种生成20位订单号的常用方法. 方法一: 以下代码是14位当前时间加6位随机数,如果增减位数,只需修改末尾的数字6即可.<?php functi ...
- java随机生成订单号
package com.aaa.utils;import org.springframework.stereotype.Component;/*** @项目名:ppp* @类名: DateUtil.j ...
- redis生成订单号案例
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.redis的相关工具类 二.生成订单号相关方法 前言 项目开发中遇到了对订单号的修改,这里只是实现了利用redis ...
- 自动生成卡号和住院号
(作者:苦行者:撰写时间:2019年7月18) 1.图1显示的html代码分别是两个卡号和住院号的文本框,而我要实现的功能是当我点击"新增"按钮的时候,自动生成卡号和住院号并回填到 ...
- Java 生成订单号(唯一id)方案
1.直接使用uuid public static String getUUID() {String replaceUUID = UUID.randomUUID().toString().replace ...
- Java 生成订单号或唯一id(高并发)方案
1.直接使用uuid public static String getUUID() {String replaceUUID = UUID.randomUUID().toString().replace ...
- 使用redis 加锁的方式生成订单号
建一个订单对象 /*** 订单号 对象*/ @Data public class OrderNumberVo implements Serializable {/*** 日期字符串 格式:" ...
最新文章
- 【C++】C++11 STL算法(六):最小/最大操作(Minimum/maximum operations)、比较运算(Comparison operations)
- python numpy安装-Python--Numpy安装
- 前端js变量踩坑,部分手机浏览器不支持let、const
- 【华为云技术分享】干货!!卷积神经网络之LeNet-5迁移实践案例
- 云计算虚拟化之Docker上如何安装Mongodb?
- 中配置kylin_Kylin集群模式部署(使用同一HBase存储)
- 盲盒商城app开发需要具备哪些核心功能,盲盒商城app源码成品分享
- Android学习笔记七之ContentProvider
- 15家银行信用卡积分含金量大比拼
- 服务器芯片和一般电脑芯片的区别,服务器CPU和PC的CPU区别
- 我的世界服务器java启动脚本_教程/服务器启动脚本
- 结构变异SV的鉴定--smartie-sv与bayestyper
- python西瓜视频UP主所有视频封面下载
- 轻量级模型设计与部署总结
- 2022年煤矿探放水考题及模拟考试
- Win7如何打开软键盘?Win7打开软键盘的方法
- 一个简单的宿舍管理系统
- Nim问题和阶梯Nim(staircase nim)
- 抓51比抓91力度还大!51信用卡CEO孙海涛被警方带走
- 《多传感器融合定位》惯性导航基础(二)