在使用grails 开发的过程,一些总结,随笔
1)grails 连接sybase数据乱码解决办法
url = "jdbc:sybase:Tds:URL:5000/jxcbase?CHARSET_CONVERTER_CLASS=com.sybase.jdbc2.utils.Cp850PureConverter"
2)自定义Sql查询
Domain.executeQuery("select user from Buser user where user.name =?",["a"],[max:20,offset:20])
3)统计数据量
Domain.count()
Domain.countByFbh()
3) 保存时候,自定义错误显示
newHzdwzd.errors.allErrors.each {
errTexts += getFormatString("${it.objectName}", it.defaultMessage, it.rejectedValue, it.arguments) + "\r\n"
}
public String getFormatString(String domain,String p,String rejectedValue,Object[] b){
String[] np = new String[b.length];
String t = "";
for (int i =0;i<b.length;i++) {
Object o = b[i] ;
if (o instanceof String) {
t = o.toString();
if (t.equals(rejectedValue)) {
np[i] = rejectedValue;
}else{
np[i] = getLabel(domain.toLowerCase()+"."+t);
}
}else if (o instanceof Class) {
t = ((Class) o).getName();
np[i] = getLabel(t.toLowerCase());
}else{
np[i] = o.toString()
}
}
return MessageFormats.format(p,np);
}
public String getLabel(String name) {
return Labels.getLabel(name.toLowerCase(),name.toLowerCase()) ;
}
在i3lable-propereies 文件中配置 domain 的相关信息