java的小細節

2021-09-17 07:19:33 字數 4798 閱讀 8789

1,用mybatis框架做分頁查詢,直接用map

dao: 

public listfindhistory( int limits, int pages, string sogo)

select * from installment

sogo=#

order by id desc limit # , #

//返回實體類

select * from userlogin

phone=#

2,去掉雙引號

string sogo= sogo1.replace("\"", "");//去掉雙引號
3,去掉小數點後面的0

string amt = amt2.tostring();

if(amt.indexof(".") > 0)

4,uuid的工具類

//32位的uuid

public static string getuuid32()

//生成指定個數的uuid

public static string getuuid(int num)

string uuidari=new string[num];

for(int i=0;i6,查詢號碼,返回資料 中間的資料用*代替

u serloginexample example = new userloginexample();

example.setorderbyclause("id desc");

criteria criteria = example.createcriteria();

criteria.andtogetherwayequalto(togetherway);

criteria.andsogoequalto(sogo);

arraylistarraylist = new arraylist<>();

for(int k=0;k2 && i<7)

}string phone = string.valueof(m);

userlogin userlogin = new userlogin();

userlogin.setid(id);

userlogin.setphone(phone);

userlogin.setcopy2(copy2);

userlogin.settogetherway(togetherway2);

arraylist.add(userlogin);

7,bigdecimal的加減乘除

加法 add()函式     減法substract()函式

乘法multipy()函式 除法divide()函式 絕對值abs()函式

bigdecimal num1 = new bigdecimal(0.005);

bigdecimal num2 = new bigdecimal(1000000);

bigdecimal num3 = new bigdecimal(-1000000);

//盡量用字串的形式初始化

bigdecimal num12 = new bigdecimal("0.005");

bigdecimal num22 = new bigdecimal("1000000");

bigdecimal num32 = new bigdecimal("-1000000");

//加法

bigdecimal result1 = num1.add(num2);

bigdecimal result12 = num12.add(num22);

//減法

bigdecimal result2 = num1.subtract(num2);

bigdecimal result22 = num12.subtract(num22);

//乘法

bigdecimal result3 = num1.multiply(num2);

bigdecimal result32 = num12.multiply(num22);

//絕對值

bigdecimal result4 = num3.abs();

bigdecimal result42 = num32.abs();

//除法

bigdecimal result5 = num2.divide(num1,20,bigdecimal.round_half_up);

bigdecimal result52 = num22.divide(num12,20,bigdecimal.round_half_up);

8,日期的演算法

//逾期天數

date today1 = (date)df.parse(today);

date latespaymenttime = (date)df.parse(latestpaymenttime);

long overdata=today1.gettime()-latespaymenttime.gettime();

"相差毫秒數..."+overdata);

long overdays=overdata/(1000 * 60 * 60 * 24);

/* long overhours= (overdata % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);

long minutes = (overdata % (1000 * 60 * 60)) / (1000 * 60);

long seconds = (overdata % (1000 * 60)) / 1000;*/

//string differenceformat = overdays + " days " + overhours + " hours " + minutes + " minutes " + seconds + " seconds ";

system.out.println("相差天數...."+overdays);

"相差時間..."+differenceformat);

9,map資料返給json資料

mapmap = new hashmap();

//還款

map.put("repaidmount", repaidmount3);

map.put("repaidretio", repaidretio);

map.put("latesbill", latesbill);

map.put("latestpaymenttime", latestpaymenttime);

map.put("content", content);

//歷史記錄

map.put("historys", historys);

string jsonstring = json.tojsonstring(map);

return jsonstring;

10.md5加密

/**

* md5加密

}//往物件中新增相關的引數

try

//4,呼叫httpclient物件的execute方法執行

//5,獲取請求響應物件和響應enity

//6.從相應物件中,獲取相應狀態,從響應entiy中獲取響應內容

//8,關閉client

},// httppost 請求

},// httpput 請求

},// httpdelete 請求

}

12.mybatis檢視sql語句,在mybatis.cfg.xml裡面配置

13,日期

******dateformat df = new ******dateformat("yyyy-mm-dd");

string today = df.format(new date());

Java程式設計小細節

a 和 的區別?a 最終結果一樣。b 具有短路效果。左邊是false,右邊不執行。是無論左邊是false還是true,右邊都會執行 b 和 的區別?a 最終結果一樣 b 具有短路效果.左邊是true,右邊不執行 是無論左邊是false還是true,右邊都會執行 輔助鍵的練習 alt 快速生成main...

一些Java程式設計上的小細節

1 使用 stringbuilder 拼接字串時,將單個拼接的標點符號用單引號,作為 char 型別的入參傳入。public string tostring if contentencoding null final long len getcontentlength if len 0 return...

SearchView的小細節

存起來方便以後用到 最近用到action bar,其中最糾結的就是searchview了,查了很多,都沒有寫到這些細小的地方.我就在巨人的肩膀上新增一些小細節吧.遇到的問題 1.actionbar中不顯示 2.預設圖示修改 3.控制項的監控 其中最耗時間的就是樣式的問題了,後面會詳細分析一下.一.a...