本文主要是介绍java后台代码常备记录总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一些后台java代码应用中常用到的部分知识,记录下来,以备后用:
1.java获取request对象:
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletRequest request = ServletActionContext.getRequest();
ServletActionContext.getRequest().getSession()
public static String getUUId() {UUID uuid = UUID.randomUUID();String uid = uuid.toString().replace("-", "");return uid;}
StringUtils.isNullOrEmpty(value.toString())
HttpServletResponse response = ServletActionContext.getResponse();
String dbType = PropertiesBean.getInstance().getProperty("conf.rightdata.type");
7.java中获取一个实体的类的类型:
Class.forName("com.dhcc.dfis.entity.className");
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后台代码常备记录总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!