public abstract class BaseAction extends ActionSupport implements Action{
// 成功常量
public static final String SUCCESS = "success";
public static final int PAGE=20;
//如果session里没有,返回重新登陆
public static final String LOGIN = "login";
public static final String INPUT = "input";
// 失败常量
public static final String ERROR = "error";
public Object getBean(String id){
ServletContext servletContext = ServletActionContext.getServletContext();
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
return context.getBean(id);
}
public HttpServletRequest request() {
return ServletActionContext.getRequest();
}
public HttpSession session() {
return ServletActionContext.getRequest().getSession();
}
public ServletContext application() {
return ServletActionContext.getServletContext();
}
public HttpServletResponse response() {
return ServletActionContext.getResponse();
}
public class BaseDAO extends HibernateDaoSupport{
public static final int PAGE=20;
public void add(Object o){
getHibernateTemplate().save(o);
/*//
try {
getHibernateTemplate().save(o);
} catch (Exception e) {
//e.printStackTrace();
throw new DataBaseException("数据库插入失败!");
}*/
}
public void update(Object o){
getHibernateTemplate().update(o);
}
public void delete(Object o){
getHibernateTemplate().delete(o);
}
public Object findById(Class clazz,Integer id){
return getHibernateTemplate().get(clazz, id);
}
public List findAll(String hql){
List list = this.getHibernateTemplate().find(hql);
return list;
}
public List findByDeatched(DetachedCriteria dc){
List list = getHibernateTemplate().findByCriteria(dc);
System.out.println(list.size());
return list;
}
//分页,适合无条件查询,参数为类名,页数
public List FenYe(String tableName,int page){
int start = 0;
int end = 0;
start = (page - 1) * PAGE + 1;
end = page * PAGE;
SessionFactory sf = getHibernateTemplate().getSessionFactory();
Session session = sf.openSession();
String sql = "SELECT * FROM (SELECT A.*,rownum RN FROM " +
"(SELECT * FROM "+tableName+") A WHERE ROWNUM <= "
+ end + ") WHERE RN >=" + start;
SQLQuery sqlq = session.createSQLQuery(sql);
sqlq.addEntity(GetID.getClass(tableName));
List list=sqlq.list();
session.close();
sf.close();
return list;
}
//查询总页数,适合无条件查询
public int totalPage(String tableName){
SessionFactory sf = getHibernateTemplate().getSessionFactory();
Session session = sf.openSession();
String sql = "select * from "+tableName;
SQLQuery sqlq = session.createSQLQuery(sql);
List list=sqlq.list();
session.close();
sf.close();
return list.size();
}
public class Page implements Serializable {
private int currentPage;
private int totalRecordNum;
private int totalPage;
private List result;
private int beginNum;
public int getBeginNum() {
return beginNum;
}
public void setBeginNum(int beginNum) {
this.beginNum = beginNum;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List getResult() {
return result;
}
public void setResult(List result) {
this.result = result;
}
public int getTotalRecordNum() {
return totalRecordNum;
}
访问权限是java中一个比较中要的知识点,它规定者什么方法可以访问,什么不可以访问
一:包访问权限;
自定义包:
package com.wj.control;
//包
public class Demo {
//定义一个无参的方法
public void DemoPackage(){
System.out.println("调用
用户自定义聚合函数,用户提供的多个入参通过聚合计算(求和、求最大值、求最小值)得到一个聚合计算结果的函数。
问题:UDF也可以提供输入多个参数然后输出一个结果的运算,比如加法运算add(3,5),add这个UDF需要实现UDF的evaluate方法,那么UDF和UDAF的实质分别究竟是什么?
Double evaluate(Double a, Double b)
在利用tomcat-redis-session-manager做session同步时,遇到了在session保存一个自定义对象时,修改该对象中的某个属性,session未进行序列化,属性没有被存储到redis中。 在 tomcat-redis-session-manager的github上有如下说明: Session Change Tracking
As noted in the &qu
关于Table Driven Approach的一篇非常好的文章:
http://www.codeproject.com/Articles/42732/Table-driven-Approach
package com.ljn.base;
import java.util.Random;
public class TableDriven {
public