Java controls a field increment on the day

Source: Internet
Author: User

① Ideas

1. Get the current time month date    : 2018-01-15 00:00:00          2018-01-15 24:00:002. Whether the corresponding date field in the query table is within the time period of the day 3. If so, increment 4 from 0. If not, then find the Msgno maximum value, on this basis +1

② on the Code

Method of encapsulation in Controller tuning service

Integer msgid= Xxtzservice.getmsgid ();

Service

Public Integer Getmsgid () {//1. Gets the current time, in the format of month-day seconds string date = dateu.getdatetostring (new date (). GetTime ()); String senddate1 = date+ "00:00:00"; String Senddate2 = date+ "24:00:00";//2. The corresponding field in the query table has list<message> msglist = Xxtzmapper.findtime for the current time (senddate1, SENDDATE2); if (Msglist.size () ==0 | | msglist==null) {//3.1 If there is no match, increments from 1 to integer msgid=0;//daily up to 100,000 for (int i = 0; i < 100000; i++) {Msgid++;return msgid;}} else{//3.2 if matching, then find the maximum value of Msgno, on this basis +1integer MsgId = Xxtzmapper.findmaxmsgid (senddate1,senddate2); Msgid++;return MsgId;} return null;}

Mapper

List<message> Findtime (@Param ("senddate1") string senddate1, @Param ("Senddate2") string senddate2); Findmaxmsgid (@Param ("senddate1") string senddate1, @Param ("Senddate2") string senddate2);

Xxmapper.xml

<select id= "Findmaxmsgid" resulttype= "int" >select Max (MsgId) from Message where senddate between #{senddate1} and # {senddate2}</select><!--Query whether the corresponding field in the Message table has the time of day--><select id= "Findtime" resulttype= "Message" > SELECT * from Message where senddate between #{senddate1} and #{senddate2}</select>

  

  

  

Java controls a field increment on the day

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.