一、 用Java实现数字转汉字
/**
* 数字转大写
* @param src 数字
* @return 返回大写
*/
public static String int2chineseNum(int src) {
final String num[] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
final String unit[] = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"};
String dst = "";
int count = 0;
while(src > 0) {
dst = (num[src % 10] + unit[count]) + dst;
src = src / 10;
count++;
}
return dst.replaceAll("零[千百十]", "零").replaceAll("零+万", "万")
.replaceAll("零+亿", "亿").replaceAll("亿万", "亿零")
.replaceAll("零+", "零").replaceAll("零$", "");
}
二、postgreSQL获得两个日期之间的时间差的天数
select date_part('day',cast(su.expire_time as TIMESTAMP)-cast(now() as TIMESTAMP)) from tb_ship_upload as su
三、postgreSQL给查到的日期+天数
1. 无拼接时:
SELECT scan_time + '5 day' FROM tbl_temp_record
SELECT scan_time + '-5 day' FROM tbl_temp_record
2. 拼接字段时:
SELECT scan_time + (5 || ' day')::interval FROM tbl_temp_record
SELECT scan_time + ('-' || 5 || ' day')::interval FROM tbl_temp_record
-- 或
SELECT scan_time + 5*interval '1 day' FROM tbl_temp_record
SELECT scan_time + 5*interval '-1 day' FROM tbl_temp_record
列:
select (hspr.start_date+(hspr.package_days+hspr.package_extension_days||' day')::interval) result from health_service_purchase_record hspr
四、mybatis的<if test>
条件判断
1. 在使用 MyBatis if 进行条件判断时,一直报错:
<if test="fwbdh != null and fwbdh == 'BAK'">
fwbdh=#{fwbdh}
<if>
2. MyBatis是使用的OGNL表达式来进行解析的,改成:
<if test='fwbdh != null and fwbdh == "BAK"'>
fwbdh=#{fwbdh}
<if>
同时,MyBatis的if、when里面的test表达式对参数进行判断时,可以调用java的java.lang.String中定义的方法:
比如:
<if test="fwbdh != null and fwbdh != ''">
<choose>
<when test='fwbdh.indexOf(",") != -1'>
AND t.FWBDH in (${fwbdh})
</when>
<otherwise>
AND t.FWBDH like '%'+#{fwbdh}+'%'
</otherwise>
</choose>
</if>
五、postgresql中将日期转成字符串
to_char(time,'YYYY-MM-DD hh24:mi:ss') as time1,
to_char(time,'YYYY-MM-DD') as time2,
to_char(time,'YYYY-MM-DD hh:mi:ss') as time3
六、postgresql中比较字符串数字
使用to_number()转成数字
SELECT max(to_number(attr_id,'9999999')) FROM base_dic_list;
网友评论