java后台代码常备记录总结
2015-01-30 11:54
295 查看
一些后台java代码应用中常用到的部分知识,记录下来,以备后用:
1.java获取request对象:
2.java获取session对象:
3.java通过java.util.UUID类获取uuid:
4.判断一个字符串不为空或null:
5.java获取response:
6.java获取application.properties里的变量值:
7.java中获取一个实体的类的类型:
8.java中将一个字符串替换成一个字符串在连接一个字符串:
9.java中执行hql的更新和删除语句:
10.java后台乱码问题:
11.通过oracle数据库链接url截取ip和sid的方法:
12.通过sql语句查询oracle或mysql中指定表的所有字段和字段描述信息
13.c3p0获取连接池:
14.前台js中获取应用根路径方法
1.java获取request对象:
HttpServletRequest request = (HttpServletRequest) ActionContext .getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletRequest request = ServletActionContext.getRequest();
2.java获取session对象:
ServletActionContext.getRequest().getSession()
3.java通过java.util.UUID类获取uuid:
public static String getUUId() { UUID uuid = UUID.randomUUID(); String uid = uuid.toString().replace("-", ""); return uid; }
4.判断一个字符串不为空或null:
StringUtils.isNullOrEmpty(value.toString())
5.java获取response:
HttpServletResponse response = ServletActionContext.getResponse();
6.java获取application.properties里的变量值:
String dbType = PropertiesBean.getInstance().getProperty("conf.rightdata.type");
7.java中获取一个实体的类的类型:
Class.forName("com.dhcc.dfis.entity.className");
8.java中将一个字符串替换成一个字符串在连接一个字符串:
String relation_id = new String(mainTableName).replace("t_", "").concat("_id");
9.java中执行hql的更新和删除语句:
super.updateByHqlWithFreeParam(hql,value);
10.java后台乱码问题:
String endText = new String(startText.getBytes("ISO8859-1"), "UTF-8");
11.通过oracle数据库链接url截取ip和sid的方法:
//截取ip的方法 public static String getIpByUrl(String url){ Pattern p = Pattern.compile("@.*?:"); Matcher m = p.matcher(url); String ipStr = ""; if(m.find()){ ipStr = url.substring(m.start()+1,m.end()-1); } return ipStr; } //截取sid的方法 public static String getSidByUrl(String url){ String sid=""; if(url!=null&&!url.equals("")){ sid=url.substring(url.lastIndexOf(":")+1,url.length()); } return sid; }
12.通过sql语句查询oracle或mysql中指定表的所有字段和字段描述信息
mysql: select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name';
select column_name from information_schema.columns where table_schema='your_db_name' and table_name='your_table_name';
oracle: select a.TABLE_NAME,a.COMMENTS,b.COLUMN_NAME,b.COMMENTS from USER_TAB_COMMENTS a,USER_COL_COMMENTS b where a.table_name=b.table_name and a.table_name="your_table_name";
13.c3p0获取连接池:
private static com.mchange.v2.c3p0.ComboPooledDataSource connectionSource = SpringContextHolder.getBean("dataSource");
14.前台js中获取应用根路径方法
/** * 获得应用的根路径 */ function getContextPath(){ var strFullPath=window.document.location.href; var strPath=window.document.location.pathname; var pos=strFullPath.indexOf(strPath); var prePath=strFullPath.substring(0,pos); var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1); var basePath = prePath; //if(canBeAccess(prePath + postPath)){ /** * */ basePath = prePath + postPath; //} return basePath; }
相关文章推荐
- Java 基础代码离散性总结
- 后台自动发邮件--java代码
- ASP.NET前台代码绑定后台变量方法总结 [转]
- ASP.NET前台代码绑定后台变量方法总结
- ASP.NET前台代码绑定后台变量方法总结
- java代码框架生成工具 开发记录2005-03-02
- ASP.NET前台代码绑定后台变量方法总结
- 记录Java代码的执行时间
- ASP.NET前台代码绑定后台变量方法总结
- ASP.NET前台代码绑定后台变量方法总结
- Ajax (部分二:prototype.js代码后半部分)自己做的,总结页面向后台传Form值、单个值和后台向前台传一个或是一组值
- 【转】ASP.NET前台代码绑定后台变量方法总结
- ASP.NET前台代码绑定后台变量方法总结
- 过滤html 文件java 代码记录
- SqlSever2005 一千万条以上记录分页数据库优化经验总结【索引优化 + 代码优化】一周搞定
- 记录asp后台密码的asp代码
- ASP后台操作日志记录代码(搜集整理)
- ASP.NET前台代码绑定后台变量方法总结
- Nokia S40手机java代码实现后台
- 一起谈.NET技术,ASP.NET前台代码绑定后台变量方法总结