1.JPA的hql方式不不支持limit,故要采用其他的方法,其实,用nativequery也很不错。
参考文档在http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/
其实,用EntityManager也非常好,见下面的例子:
UserParkingHistory是用@Entity注解的实体(当然,同时注解与数据库的映射关系@Table和@Column等)
UserParkingHistoryForHistogram是POJO
//接口
public interface UserParkingHistoryDao extends Repository<UserParkingHistory, Integer> {
public List<UserParkingHistory> findAll();
public List<UserParkingHistoryForHistogram> findTopTen(Date startDate, Date endDate);
}
//接口实现
public class UserParkingHistoryDaoImpl implements UserParkingHistoryDao{
@javax.persistence.PersistenceContext
EntityManager em;
@Override
public List<UserParkingHistory> findAll() {
// TODO Auto-generated method stub
String hql = "from UserParkingHistory";
List<UserParkingHistory> list = em.createQuery(hql, UserParkingHistory.class).getResultList();
return list;
}
@Override
public List<UserParkingHistoryForHistogram> findTopTen(Date startDate, Date endDate) {
// TODO Auto-generated method stub
List<UserParkingHistoryForHistogram> list = new ArrayList<UserParkingHistoryForHistogram>();
String sql = "SELECT u.park_code ,COUNT(*) FROM user_parking_history AS u WHERE u.parking_date >= ?1 AND u.parking_date <= ?2 " +
"GROUP BY u.park_code ORDER BY COUNT(*) DESC";
Query query=em.createNativeQuery(sql);
query.setParameter(1, startDate);
query.setParameter(2, endDate);
query.setMaxResults(10);
Iterator<?> results = query.getResultList().iterator();
while ( results.hasNext() ) {
Object[] row = (Object[]) results.next();
list.add(new UserParkingHistoryForHistogram((String)row[0],(BigInteger)row[1]));
}
return list;
}
}
2.浏览器缓存还是要经常清理的。
3.判断浏览器方法
参考文章:http://www.cnblogs.com/carekee/articles/1854674.html
function showBrowserName() {
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
Sys.ie = ua.match(/msie ([\d.]+)/)[1];
else if (document.getBoxObjectFor)
Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1];
else if (window.MessageEvent && !document.getBoxObjectFor)
Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1];
else if (window.opera)
Sys.opera = ua.match(/opera.([\d.]+)/)[1];
else if (window.openDatabase)
Sys.safari = ua.match(/version\/([\d.]+)/)[1];
//以下进行测试
if(Sys.ie) document.write('IE: '+Sys.ie);
if(Sys.firefox) document.write('Firefox: '+Sys.firefox);
if(Sys.chrome) document.write('Chrome: '+Sys.chrome);
if(Sys.opera) document.write('Opera: '+Sys.opera);
if(Sys.safari) document.write('Safari: '+Sys.safari);
}