package dao;
import java.util.List;
/**
* @author 雷霄骅
* 对Object的DAO操作
* 提供了通用的一些方法
*/
public interface BaseDao {
public void save(Object object);
public void delete(Object object);
public void update(Object object);
public Object ReadSingle(String targetName,String propertyName,Object value);
public List
实现:BaseDaoImpl.java
package dao;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* @author 雷霄骅
* HibernateTemplate提供非常多的常用方法来完成基本的操作,比如通常的增加、删除、修改、查询等操作,
* Spring 2.0更增加对命名SQL查询的支持,也增加对分页的支持。大部分情况下,就可完成大多数DAO对象的CRUD操作。
*/
public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao{
@Override
public void save(Object object) {
getHibernateTemplate().save(object);
//System.out.println("save "+object.toString());
}
@Override
public void delete(Object object) {
getHibernateTemplate().delete(object);
}
@Override
public void update(Object object) {
getHibernateTemplate().update(object);
//改用saveOrUpdate,在评价的时候,第一次创建的时候Save,其他时候Update
//getHibernateTemplate().saveOrUpdate(object);
//System.out.println("update "+object.toString());
}
@SuppressWarnings("unchecked")
@Override
public Object ReadSingle(final String targetName,final String propertyName, final Object value) {
// TODO Auto-generated method stub
return (Object) getHibernateTemplate().execute(new HibernateCallback() {
/*doInHibernate()。session的创建和销毁,一切都在程序内部完成。*/
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "from "+targetName+" as "+targetName+" where "+targetName+"." + propertyName + "=:value";
Query query = session.createQuery(hql);
query.setParameter("value", value);
return query.uniqueResult();
}
});
}
@SuppressWarnings("unchecked")
@Override
public List ReadAll(String targetName) {
// TODO Auto-generated method stub
String hql="from "+targetName;
return getHibernateTemplate().find(hql);
}
@SuppressWarnings("unchecked")
@Override
public List ReadByProperty(final String targetName, final String propertyName,
final Object value) {
// TODO Auto-generated method stub
return (List) getHibernateTemplate().execute(new HibernateCallback() {
/*doInHibernate()。session的创建和销毁,一切都在程序内部完成。*/
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "from "+targetName+" as "+targetName+" where "+targetName+"." + propertyName + "=:value";
Query query = session.createQuery(hql);
query.setParameter("value", value);
return query.list();
}
});
}
//比ReadByProperty简单很多
@Override
public Object get(int id) {
// TODO Auto-generated method stub
return getHibernateTemplate().get(Object.class, id);
}
@Override
public List ReadByPropertyList(final String targetName,
final List propertyName, final List value) {
// TODO Auto-generated method stub
return (List) getHibernateTemplate().execute(new HibernateCallback() {
/*doInHibernate()。session的创建和销毁,一切都在程序内部完成。*/
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String hql = "from "+targetName+" as "+targetName;
//-------------------------------
for(int i=0;i ReadLimitedByOrder(final String targetName,
final String propertyName, final int num, final String order) {
// TODO Auto-generated method stub
return (List) getHibernateTemplate().execute(new HibernateCallback() {
/*doInHibernate()。session的创建和销毁,一切都在程序内部完成。*/
public Object doInHibernate(Session session) throws HibernateException, SQLException {
String hql ="from "+targetName+" as "+targetName+ " order by "+targetName+"." + propertyName+ " " + order;
Query query = session.createQuery(hql);
query.setMaxResults(num);
//当返回的数据不是一条的时候,不用uniqueresult(),而用list()
return query.list();
}
});
}
@Override
public List ReadAllByOrder(String targetName, String propertyName,
String order) {
// TODO Auto-generated method stub
String hql="from "+targetName+" as "+targetName+ " order by "+targetName+"." + propertyName+ " " + order;
return getHibernateTemplate().find(hql);
}
}
Service:
接口:BaseService.java
package service;
import java.util.List;
/**
* @author 雷霄骅
* 对Object的Service
* 提供了一些通用的方法
*/
public interface BaseService {
public void save(Object object);
public void update(Object object);
public void delete(Object object);
public Object ReadByID(String targetName,int id);
@SuppressWarnings("rawtypes")
public List ReadAll(String targetName);
public List ReadAllByOrder(String targetName,String propertyName,String order);
@SuppressWarnings("rawtypes")
public List ReadByProperty(String targetName,String propertyName,Object propertyValue);
public List ReadByPropertyList(String targetName,List propertyName,List propertyValue);
public List ReadLimitedByOrder(String targetName,String propertyName,int num,String order);
public Object ReadSingle(String targetName,String propertyName,Object propertyValue);
public int ReadCount(String targetName);
}
实现:BaseServiceImpl.java
package service;
import java.util.ArrayList;
import java.util.List;
import dao.BaseDao;
/**
* @author 雷霄骅
* 对Object的Service
* 提供了一些通用的方法
*/
public class BaseServiceImpl implements BaseService {
private BaseDao baseDao;
@Override
public void save(Object object) {
// TODO Auto-generated method stub
baseDao.save(object);
}
@Override
public void update(Object object) {
// TODO Auto-generated method stub
baseDao.update(object);
}
@Override
public void delete(Object object) {
// TODO Auto-generated method stub
baseDao.delete(object);
}
@Override
public Object ReadByID(String targetName,int id) {
// TODO Auto-generated method stub
return baseDao.ReadSingle(targetName,"id", id);
}
@SuppressWarnings("rawtypes")
@Override
public List ReadAll(String targetName) {
// TODO Auto-generated method stub
return baseDao.ReadAll(targetName);
}
@SuppressWarnings("rawtypes")
@Override
public List ReadAllByOrder(String targetName,String propertyName,String order) {
// TODO Auto-generated method stub
return baseDao.ReadAllByOrder(targetName,propertyName,order);
}
public BaseDao getBaseDao() {
return baseDao;
}
public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseDao;
}
@Override
public List ReadByProperty(String targetName, String propertyName,
Object propertyValue) {
// TODO Auto-generated method stub
return baseDao.ReadByProperty(targetName, propertyName, propertyValue);
}
@Override
public Object ReadSingle(String targetName, String propertyName,
Object propertyValue) {
// TODO Auto-generated method stub
return baseDao.ReadSingle(targetName, propertyName, propertyValue);
}
@Override
public int ReadCount(String targetName) {
// TODO Auto-generated method stub
return baseDao.ReadCount(targetName);
}
@Override
public List ReadLimitedByOrder(String targetName, String propertyName,
int num, String order) {
return baseDao.ReadLimitedByOrder(targetName,propertyName,num,order);
}
@Override
public List ReadByPropertyList(String targetName,
List propertyName, List propertyValue) {
// TODO Auto-generated method stub
return baseDao.ReadByPropertyList(targetName,propertyName,propertyValue);
}
}
GetUrlParam:function GetUrlParam(param){
var reg = new RegExp("(^|&)"+ param +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null
==================================================
1、打开PowerDesigner12,在菜单中按照如下方式进行操作
file->Reverse Engineer->DataBase
点击后,弹出 New Physical Data Model 的对话框
2、在General选项卡中
Model name:模板名字,自
网站配置是apache+tomcat,tomcat没有报错,apache报错是:
The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /. Reason: Error reading fr
Free variable A free variable of an expression is a variable that’s used inside the expression but not defined inside the expression. For instance, in the function literal expression (x: Int) => (x
Part Ⅰ:
《阿甘正传》Forrest Gump经典中英文对白
Forrest: Hello! My names Forrest. Forrest Gump. You wanna Chocolate? I could eat about a million and a half othese. My momma always said life was like a box ochocol
Json在数据传输中很好用,原因是JSON 比 XML 更小、更快,更易解析。
在Java程序中,如何使用处理JSON,现在有很多工具可以处理,比较流行常用的是google的gson和alibaba的fastjson,具体使用如下:
1、读取json然后处理
class ReadJSON
{
public static void main(String[] args)