2014年3月7日星期五

double四舍五入并保留两位小数的方法

搜了好多double 保留两位小数的方法,就这个靠谱
转自:http://glblong.blog.51cto.com/3058613/1312340

1.只要输出结果
1
2
double x1 = 0.026;
System.out.println(String.format("%.2f", x1));


2.数据转换
1
2
3
4
5
6
7
8
9
10
11
//方案一:
get_double = (double)(Math.round(result_value*100)/100.0)
//方案二:
DecimalFormat df = new DecimalFormat("#.##");
get_double = Double.ParseDouble(df.format(result_value));
//方案三:
get_double = Double.ParseDouble(String.format("%.2f",result_value));
//方案四:
BigDecimal bd = new BigDecimalresult_value();
BigDecimal  bd2 = bd.setScale(2,BigDecimal  .ROUND_HALF_UP);
get_double = Double.ParseDouble(bd2.ToString());




3.只保留两位小数(不含四舍五入)
1
2
double d = 13.4324;
d=((int)(d*100))/100;

2014年3月6日星期四

终于将webx跑起来了

webx
因为Webx在阿里巴巴和淘宝用了很多年。对于这种超大访问量的电子商务网站,Webx经受了考验,被证明是成熟可靠的
就因为这句话,就得好好研究研究。

通过git clone https://github.com/webx/citrus-sample.git 才能将示例源码下载下来
每个模块单独一个上下文容器
基于Velocity模板
管道 阀门
日志
表单验证
AutoConfig
。。。继续研究

poi读取excel模板展示report

这周一直在研究通过jxls poi读取excel模板,然后动态填充数据,以替换润乾报表
这个主要基于的场景是每个考试有不同的申报表,而每个申报表有很多是死内容,比如注意事项之类,现在基于润乾实现,每个考试都要根据客户给的excel文件做一个raq,然后写sql,调用,申报表是固定的,基本没有扩展。
        最大的难度是读取excel模板并解析样式转换成html显示给考生,读取数据很简单,但合并单元格,单元格样式有点不好控制,现在这个问题基本解决,poi提供了一个toHtml的实例,它的合并单元格是通过css控制边框,修改了css colspan。
       第二个问题是效率问题,通过模板填充数据,效率很低,经同事测试,填充2w条数据,poi直接创建和jxls模板写入是几百毫秒和4秒多的差距。还好申报表一般A4大小,内容相对固定,待实际测试吧。
       要是不行就用velocity代替试试。


2014年2月17日星期一

linux 查找

从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR”的行
find / -type f -name "*.log" | xargs grep "ERROR"
例子:从当前目录开始查找所有扩展名为.in的文本文件,并找出包含”thermcontact”的行
find . -name "*.in" | xargs grep "thermcontact"

tomcat启动在80端口 Permission denied :80

linux 下将tomcat的server.xml的端口改为80后以tomcat身份无法启动tomcat! 
在redhat上启动tomcat(将server.xml中的端口改为80) 
su - tomcat -c "$CATALINA_HOME/bin/startup.sh" 
后出现:Catalina.start: LifecycleException: null.open: java.net.BindException: Permission denied:80 

这是因为只有root用户才可访问1024以下的端口。 

解决方法: 
重将server.xml中的端口改为8080 
然后:iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 
(如果用到443,也相应执行以上方法) 
即可!

linux命令

压缩 tar.gz
tar -zcvf operate.tar.gz operate*

解压 tar.gz
tar -xzvf ideaIU-13.tar.gz

给用户授权
chown -R spring:spring /opt/ideaIU-13.tar.gz 

复制目录
cp -r yjrc /home/capinfo

授权
sudo chmod u+x /usr/lib/jvm/java/jdk1.6.0_12.bin

更新源
sudo gedit /etc/apt/sources.list

给root创建一个密码:sudo passwd roo


sudo apt-get install rar
sudo apt-get install unrar

很快就下载完了,然后输入:
ln -fs /usr/bin/rar /usr/bin/unrar


sqldeveloper 安装
sqldeveloper  linux 安装包只有rpm格式的,ubuntu是不支持的,要把rpm转成deb,这里就用到了alien
如果没有安装
sudo apt-get install alien
然后
sudo alien /路径/xxxx.rpm
然后在当前用户路径下生成了一个XXXXX.deb
直接
sudo dpkg -i xxxx.deb
就行了。
在终端输入 sudo sqldeveloper 就可以启动了,
然后会有以下提示:
Type the full pathname of a J2SE installation (or Ctrl-C to quit), the path will be stored 
输入jdk的路径就可以了。
每次启动都需要输入jdk的路径是不是很麻烦。
修改/opt/sqldeveloper/sqldeveloper/bin下的sqldeveloper的配置文件,然后要重启一下(不然好像不生效)
#vi ./sqldeveloper/bin/sqldeveloper.conf
 修改 SetJavaHome 参数为 $JAVA_HOME



svn
apt-get install subversion

Ubuntu系统的Hosts只需修改/etc/hosts文件,在目录中还有一个hosts.conf文件,刚开始还以为只需要修改这个就可以了,结果发现是需要修改hosts。修改完之后要重启网络。
具体过程如下:
1、修改hosts
sudo gedit /etc/hosts
2、添加解析记录( . )
完整案例:127.0.0.1 localhost.localdomain localhost
简洁记录:127.0.0.1 localhost
3、保存后重启网络
sudo /etc/init.d/networking restart

.快速清理磁盘垃圾
磁盘空间又不够用了?尝试在终端窗口中输入
sudo apt-get autoremove
然后输入
sudo apt-get clean
,前一个命令会卸载系统中所有未被使用的依赖关系,后一个命令会清除所有缓存的包文件,两者都是无害的。在一个升级过多次的系统上,你也许能通 过这个方法清理出若干GB的空间。

mvn clean package -Dmaven.test.skip=true





Skip your tests with maven release plugin


The maven release plugin becomes often very handy. However, in its default configuration all relevent maven lifecycle phases are performed including the verify phase. Here, all your tests – if any available – are compiled and run as well. In my particular case, I just wanted to perform the release without the test steps.
This is what you need to do:
  1. Preparing   – mvn -DpreparationGoals=clean -DscmCommentPrefix="XXX" release:prepare
  2. Performing – mvn -Darguments="-Dmaven.test.skip=true" release:perform
The prepare goal will only perform the clean lifecycle. You may of course define other lifecycle phases as well unless they include testing activities. The perform goal is a different story. Here we make use of the arguments parameter providing some input for the underlying phases deploy and site-deploy run by the perform goal.
Cheers