• 关于 query. 的搜索结果

问题

Springside4.0.1GA版本quickstart Demo启动报错?报错

爱吃鱼的程序员 2020-06-22 22:08:08 0 浏览量 回答数 1

问题

QuickBI追加数据源后,刷新数据集报错。

吾空 2019-12-01 19:36:50 1001 浏览量 回答数 2

问题

hibernate更新数据库时报了个错误,请教一下大家?报错

爱吃鱼的程序员 2020-06-09 14:34:56 0 浏览量 回答数 1

新用户福利专场,云服务器ECS低至96.9元/年

新用户福利专场,云服务器ECS低至96.9元/年

问题

queryrunner query报错 Cannot create com.c?报错

爱吃鱼的程序员 2020-06-09 10:35:51 0 浏览量 回答数 1

问题

MySQL数据库SQL Error:1030, SQLState: HY000,Got error 28 from storage engine 怎么弄?

我的中国 2019-12-01 19:39:55 2933 浏览量 回答数 1

回答

`Query query = new Query(Criteria.where("ppid").is(ppid).and("epid").is(epid).and("infos.lc").exists(true));query.with(new Sort(Sort.Direction.DESC, "infos.lc.ed")).limit(1); List result= this.mongoTemplate.find(query, XXX.class);` 这样就可以了

落地花开啦 2019-12-02 01:52:59 0 浏览量 回答数 0

回答

如果query参数值含中文,需要对query的值进行utf-8编码。可参考下面url的构建方式。 private static String initUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException { StringBuilder sbUrl = new StringBuilder(); sbUrl.append(host); if (!StringUtils.isBlank(path)) { sbUrl.append(path); } if (null != querys) { StringBuilder sbQuery = new StringBuilder(); for (Map.Entry<String, String> query : querys.entrySet()) { if (0 < sbQuery.length()) { sbQuery.append("&"); } if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { sbQuery.append(query.getValue()); } if (!StringUtils.isBlank(query.getKey())) { sbQuery.append(query.getKey()); if (!StringUtils.isBlank(query.getValue())) { sbQuery.append("="); sbQuery.append(URLEncoder.encode(query.getValue(), "UTF-8")); } } } if (0 < sbQuery.length()) { sbUrl.append("?").append(sbQuery); } } return sbUrl.toString(); }

保持可爱mmm 2020-03-26 21:41:35 0 浏览量 回答数 0

问题

springdata的Query注解写的sql一直报错(Encountered ?400报错

爱吃鱼的程序员 2020-06-06 09:23:26 0 浏览量 回答数 1

问题

hibernate如何执行DB2序列查询?报错

爱吃鱼的程序员 2020-06-09 11:39:31 0 浏览量 回答数 1

回答

查询域名 A 记录 命令格式: dig <域名> 比如,查询域名 www.aliyun.com 的解析情况: $ dig www.aliyun.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.7 <<>> www.aliyun.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15919;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 2, ADDITIONAL: 4 ;; QUESTION SECTION:;www.aliyun.com. IN A ;; ANSWER SECTION:www.aliyun.com. 600 IN CNAME www-adns.aliyun.com.www-adns.aliyun.com. 300 IN CNAME www-adns.aliyun.com.gds.alibabadns.com.www-adns.aliyun.com.gds.alibabadns.com. 247 IN A 140.205.62.8 ;; AUTHORITY SECTION:gds.alibabadns.com. 82 IN NS gdsns2.alibabadns.com.gds.alibabadns.com. 82 IN NS gdsns1.alibabadns.com. ;; ADDITIONAL SECTION:gdsns1.alibabadns.com. 877 IN A 140.205.122.66gdsns1.alibabadns.com. 877 IN A 198.11.138.254gdsns2.alibabadns.com. 877 IN A 140.205.67.254gdsns2.alibabadns.com. 877 IN A 140.205.122.88 ;; Query time: 49 msec;; SERVER: 10.242.197.247#53(10.242.197.247);; WHEN: Thu Jun 9 18:43:55 2016;; MSG SIZE rcvd: 226 查询域名解析在指定 DNS 服务器解析是否生效 命令格式: dig <域名> @<DNS 服务器地址> 比如,查询 www.aliyun.com 在 223.5.5.5 DNS 服务器是否解析生效: $ dig www.aliyun.com @223.5.5.5; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.7 <<>> www.aliyun.com @223.5.5.5;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29651;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:;www.aliyun.com. IN A;; ANSWER SECTION:www.aliyun.com. 95 IN CNAME www-adns.aliyun.com. # 查询到的解析记录www-adns.aliyun.com. 95 IN CNAME www-adns.aliyun.com.gds.alibabadns.com. # 查询到的解析记录www-adns.aliyun.com.gds.alibabadns.com. 95 IN A 140.205.63.8;; Query time: 0 msec;; SERVER: 223.5.5.5#53(223.5.5.5);; WHEN: Thu Jun 9 18:44:42 2016;; MSG SIZE rcvd: 120 查询域名的 CNAME 记录 命令格式: dig CNAME <域名> 比如,查询域名 www.aliyun.com 的 CNAME 记录: # dig CNAME www.aliyun.com; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> CNAME www.aliyun.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4690;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 7;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;www.aliyun.com. IN CNAME;; ANSWER SECTION:www.aliyun.com. 120 IN CNAME www-intl-adns.aliyun.com. # 查询到的 CNAME 信息;; AUTHORITY SECTION:aliyun.com. 172800 IN NS ns5.aliyun.com.aliyun.com. 172800 IN NS ns4.aliyun.com.aliyun.com. 172800 IN NS ns3.aliyun.com.;; ADDITIONAL SECTION:ns3.aliyun.com. 432000 IN A 42.120.250.251ns4.aliyun.com. 432000 IN A 110.75.20.27ns4.aliyun.com. 432000 IN A 140.205.71.248ns4.aliyun.com. 432000 IN A 42.156.241.248ns5.aliyun.com. 432000 IN A 140.205.2.187ns5.aliyun.com. 432000 IN A 198.11.138.248;; Query time: 10 msec;; SERVER: 10.202.72.118#53(10.202.72.118);; WHEN: Fri Jul 08 11:46:33 CST 2016;; MSG SIZE rcvd: 221 查询 IP 反解记录 命令格式: dig -x <目标 IP 地址> $ dig -x 140.205.62.8; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -x 140.205.62.8;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38256;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;8.62.205.140.in-addr.arpa. IN PTR;; AUTHORITY SECTION:140.in-addr.arpa. 945 IN SOA z.arin.net. dns-ops.arin.net. 2016031910 1800 900 691200 10800;; Query time: 3 msec;; SERVER: 10.202.72.118#53(10.202.72.118);; WHEN: Fri Jul 08 11:51:32 CST 2016;; MSG SIZE rcvd: 108 查询域名的 mx 解析记录   命令格式: dig mx <目标域名> ?比如,查询域名 aliyun.com 的 mx 解析记录: $ dig mx aliyun.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.7 <<>> mx aliyun.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33606;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 7;; QUESTION SECTION:;aliyun.com. IN MX;; ANSWER SECTION:aliyun.com. 3600 IN MX 10 mx2.mail.aliyun.com.;; AUTHORITY SECTION:aliyun.com. 172800 IN NS ns4.aliyun.com.aliyun.com. 172800 IN NS ns3.aliyun.com.aliyun.com. 172800 IN NS ns5.aliyun.com.;; ADDITIONAL SECTION:mx2.mail.aliyun.com. 600 IN A 110.75.48.150ns3.aliyun.com. 432000 IN A 42.120.250.251ns4.aliyun.com. 432000 IN A 110.75.20.27ns4.aliyun.com. 432000 IN A 140.205.71.248ns4.aliyun.com. 432000 IN A 42.156.241.248ns5.aliyun.com. 432000 IN A 198.11.138.248ns5.aliyun.com. 432000 IN A 140.205.2.187;; Query time: 1 msec;; SERVER: 10.242.197.247#53(10.242.197.247);; WHEN: Thu Jun 9 18:59:44 2016;; MSG SIZE rcvd: 219

KB小秘书 2019-12-02 01:28:04 0 浏览量 回答数 0

问题

QN.image的一些疑问

我叫石头 2019-12-01 20:00:18 1119 浏览量 回答数 1

问题

druid的sql parser好像不支持oracle的within GROUP语法?报错

爱吃鱼的程序员 2020-06-22 20:22:29 0 浏览量 回答数 1

回答

1. 查询整个映射对象所有字段 Java代码 //直接from查询出来的是一个映射对象,即:查询整个映射对象所有字段 String hql = "from Users"; Query query = session.createQuery(hql); List<Users> users = query.list(); for(Users user : users){ System.out.println(user.getName() + " : " + user.getPasswd() + " : " + user.getId()); } 输出结果为: name1 : password1 : 1 name2 : password2 : 2 name3 : password3 : 3 2.查询单个字段 Java代码 //查询单个字段 String hql = " select name from Users"; Query query = session.createQuery(hql); List<String> list = query.list(); for(String str : list){ System.out.println(str); } 输出结果为: name1 name2 name3 3.查询其中几个字段 Java代码 //查询其中几个字段 String hql = " select name,passwd from Users"; Query query = session.createQuery(hql); //默认查询出来的list里存放的是一个Object数组 List<Object[]> list = query.list(); for(Object[] object : list){ String name = (String)object[0]; String passwd = (String)object[1]; System.out.println(name + " : " + passwd); } 输出结果为: name1 : password1 name2 : password2 name3 : password3 4.修改默认查询结果(query.list())不以Object[]数组形式返回,以List形式返回 引用 //查询其中几个字段,添加new list(),注意list里的l是小写的。也不需要导入包,这样通过query.list()出来的list里存放的不再是默认的Object数组了,而是List集合了 String hql = " select new list(name,passwd) from Users"; Query query = session.createQuery(hql); //默认查询出来的list里存放的是一个Object数组,但是在这里list里存放的不再是默认的Object数组了,而是List集合了 List<List> list = query.list(); for(List user : list){ String name = (String)user.get(0); String passwd = (String)user.get(1); System.out.println(name + " : " + passwd); } /** 输出结果为: name1 : password1 name2 : password2 name3 : password3 */ 5.修改默认查询结果(query.list())不以Object[]数组形式返回,以Map形式返回 Java代码 收藏代码 //查询其中几个字段,添加new map(),注意map里的m是小写的。也不需要导入包,这样通过query.list()出来的list里存放的不再是默认的Object数组了,而是map集合了 String hql = " select new map(name,passwd) from Users"; Query query = session.createQuery(hql); //默认查询出来的list里存放的是一个Object数组,但是在这里list里存放的不再是默认的Object数组了,而是Map集合了 List<Map> list = query.list(); for(Map user : list){ //一条记录里所有的字段值都是map里的一个元素,key是字符串0,1,2,3....,value是字段值 //如果将hql改为:String hql = " select new map(name as username,passwd as password) from Users";,那么key将不是字符串0,1,2...了,而是"username","password"了 String name = (String)user.get("0");//get("0");是get(key),注意:0,1,2...是字符串,而不是整形 String passwd = (String)user.get("1"); System.out.println(name + " : " + passwd); } /** 输出结果为: name1 : password1 name2 : password2 name3 : password3 */ 6.修改默认查询结果(query.list())不以Object[]数组形式返回,以Set形式返回,但是因为Set里是不允许有重复的元素,所以:username和password的值不能相同。只需将hql改为:String hql = " select new set(name,passwd) from Users"; 7.修改默认查询结果(query.list())不以Object[]数组形式返回,以自定义类型返回 自定义类: Java代码 package com.domain; public class MyUser { private String username; private String password; //因为:String hql = " select new com.domain.MyUser(name,passwd) from Users";所以必须要有接受2个参数的构造函数 public MyUser(String username,String password){ this.username = username; this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } Java代码 //通过query.list()出来的list里存放的不再是默认的Object数组了,而是自定义的类MyUser,必须加包名,String hql = "from Users";中的Users类也是必须加包名的,但是因为再Users.hbm.xml里<hibernate-mapping auto-import="true"> auto-import默认值为true(所以auto-import属性也可以不写),自动导入了 String hql = " select new com.domain.MyUser(name,passwd) from Users"; Query query = session.createQuery(hql); //默认查询出来的list里存放的是一个Object数组,但是在这里list里存放的不再是默认的Object数组了,而是MyUser对象了 List<MyUser> myUsers = query.list(); for(MyUser myUser : myUsers){ String name = myUser.getUsername(); String passwd = myUser.getPassword(); System.out.println(name + " : " + passwd); } /** 输出结果为: name1 : password1 name2 : password2 name3 : password3 */ 8:条件查询 Java代码 //条件查询,参数索引值从0开始,索引位置。通过setString,setParameter设置参数 String hql = "from Users where name=? and passwd=?"; Query query = session.createQuery(hql); //第1种方式 // query.setString(0, "name1"); // query.setString(1, "password1"); //第2种方式 query.setParameter(0, "name1",Hibernate.STRING); query.setParameter(1, "password1",Hibernate.STRING); List<Users> list = query.list(); for(Users users : list){ System.out.println(users.getId()); } Java代码 //条件查询,自定义索引名(参数名):username,:password.通过setString,setParameter设置参数 String hql = "from Users where name=:username and passwd=:password"; Query query = session.createQuery(hql); //第1种方式 // query.setString("username", "name1"); // query.setString("password", "password1"); //第2种方式,第3个参数确定类型 query.setParameter("username", "name1",Hibernate.STRING); query.setParameter("password", "password1",Hibernate.STRING); List<Users> list = query.list(); for(Users users : list){ System.out.println(users.getId()); } Java代码 //条件查询,通过setProperties设置参数 String hql = "from Users where name=:username and passwd=:password"; Query query = session.createQuery(hql); //MyUser类的2个属性必须和:username和:password对应 MyUser myUser = new MyUser("name1","password1"); query.setProperties(myUser); List<Users> list = query.list(); for(Users users : list){ System.out.println(users.getId()); } [java] view plaincopy package com.hp.ts.bca.user.bo; import com.hp.ts.bca.common.BaseObject; public class StationUser extends BaseObject { private static final long serialVersionUID = -1175811459644997844L; private int id; private String username; private String officePhone; private String mobilePhone1; private String officeEmail; private Integer ifDefault; public StationUser(int id, String username, String officePhone, String mobilePhone1, String officeEmail, Integer ifDefault) { super(); this.id = id; this.username = username; this.officePhone = officePhone; this.mobilePhone1 = mobilePhone1; this.officeEmail = officeEmail; this.ifDefault = ifDefault; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getOfficePhone() { return officePhone; } public void setOfficePhone(String officePhone) { this.officePhone = officePhone; } public String getMobilePhone1() { return mobilePhone1; } public void setMobilePhone1(String mobilePhone1) { this.mobilePhone1 = mobilePhone1; } public String getOfficeEmail() { return officeEmail; } public void setOfficeEmail(String officeEmail) { this.officeEmail = officeEmail; } public Integer getIfDefault() { return ifDefault; } public void setIfDefault(Integer ifDefault) { if(ifDefault==null) ifDefault=0; else this.ifDefault = ifDefault; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; result = prime * result + ((ifDefault == null) ? 0 : ifDefault.hashCode()); result = prime * result + ((mobilePhone1 == null) ? 0 : mobilePhone1.hashCode()); result = prime * result + ((officeEmail == null) ? 0 : officeEmail.hashCode()); result = prime * result + ((officePhone == null) ? 0 : officePhone.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; StationUser other = (StationUser) obj; if (id != other.id) return false; if (ifDefault == null) { if (other.ifDefault != null) return false; } else if (!ifDefault.equals(other.ifDefault)) return false; if (mobilePhone1 == null) { if (other.mobilePhone1 != null) return false; } else if (!mobilePhone1.equals(other.mobilePhone1)) return false; if (officeEmail == null) { if (other.officeEmail != null) return false; } else if (!officeEmail.equals(other.officeEmail)) return false; if (officePhone == null) { if (other.officePhone != null) return false; } else if (!officePhone.equals(other.officePhone)) return false; if (username == null) { if (other.username != null) return false; } else if (!username.equals(other.username)) return false; return true; } @Override public String toString() { return "StationUser [id=" + id + ", username=" + username + ", officePhone=" + officePhone + ", mobilePhone1=" + mobilePhone1 + ", officeEmail=" + officeEmail + ", ifDefault=" + ifDefault + "]"; } } [java] view plaincopy @Override public PageResponse<User> getUserListByStationId(int currentPage, int rowsPerPage, String sidx, String sord, Integer stationId) { StringBuilder hql = new StringBuilder(); hql.append("select new com.hp.ts.bca.user.bo.StationUser(a.id,a.username,a.officePhone,a.mobilePhone1,a.officeEmail,ug.ifDefault) FROM User a, UserGroup ug WHERE a.id=ug.userId and ug.groupId="); hql.append(stationId); //hql.append("FROM User AS user, UserGroup AS ug WHERE user.id=ug.userId"); PageResponse<User> userList = this.groupDao.excutePage(hql.toString(), currentPage, rowsPerPage, sidx, sord); return userList; }

小旋风柴进 2019-12-02 02:11:27 0 浏览量 回答数 0

问题

hibernate执行几次数据库查询就卡住,是什么原因

小旋风柴进 2019-12-01 20:05:19 2139 浏览量 回答数 1

问题

Spring data操作mongo时,对查询结果排序不起作用,什么原因?

落地花开啦 2019-12-01 19:57:54 1388 浏览量 回答数 1

问题

Spring3+hibernate3 在dao层使用Query的executeUpdate不回滚

a123456678 2019-12-01 20:23:58 998 浏览量 回答数 1

问题

关于 Hibernate 中 update 不执行,不报错 求解!

爵霸 2019-12-01 20:06:20 1626 浏览量 回答数 1

问题

hibernate执行几次数据库查询就卡住

云栖技术 2019-12-01 19:40:19 1130 浏览量 回答数 1

回答

如果需求变化不大!mybatis也是个不错的选择######既然是SSH,那么就交给Spring来管理你的hibernate的sessionFactory, 然后通过sessionFactory来进行相应的数据操作。 Spring和Hibernate的集成,google下,应该有很多标准的配置。######可以看下springside里面的dao,封装的不错######我用ssh做一个增删改查的小案例,用的很模糊,各位朋友可否指导一下呢,小弟谢过了.###### /** 写一段给你,希望对你有帮助 * / import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.; import org.hibernate.; import org.hibernate.type.Type; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class BaseHibernateDao extends HibernateDaoSupport { public BaseHibernateDao() { } public void delete(Object entity) { getHibernateTemplate().delete(entity); } public void delete(Serializable id, Class clazz) { delete(getEntity(id, clazz)); } public void deleteAll(Collection c) { for (Iterator iter = c.iterator(); iter.hasNext(); delete(iter.next())); } public void evict(Object entity) { getHibernateTemplate().evict(entity); } public void executeSql(String sql) { Connection con; Session session = getSession(); con = session.connection(); PreparedStatement pst = null; try { pst = con.prepareStatement(sql); pst.execute(); pst.close(); } catch (Exception e) { throw new BusinessException("执行SQL语句时出错!", e); } finally { if (pst != null) try { pst.close(); } catch (SQLException e) { throw new BusinessException("执行SQL语句时出错!", e); } } } public void flush() { getHibernateTemplate().flush(); } private Query genQuery(String hql, Object conditionValues[]) { Query query = genQuery(hql); setQueryConditionValue(hql, conditionValues, query); return query; } private Query genQuery(String hql) { return getSession().createQuery(hql); } public List getEntities(String hql, Object conditionValues[]) { Query query = genQuery(hql, conditionValues); return query.list(); } public List getEntities(String hql) { Query query = genQuery(hql); return query.list(); } public List getEntities(String hql, Object conditionNames[], Object conditionValues[]) { Query query = getQuery(hql, conditionNames, conditionValues); return query.list(); } public Query getQuery(String hql, Object conditionNames[], Object conditionValues[]) { if (conditionNames.length != conditionValues.length) throw new BusinessException("参数和值的数组长度不匹配,长度必需相等!"); getHibernateTemplate().setCacheQueries(true); Query query = getSession().createQuery(hql); if (conditionValues != null) { for (int i = 0; i < conditionValues.length; i++) { Object param = conditionValues[i]; if (param == null) throw new BusinessException((new StringBuilder("执行HQL为:")).append(hql).append(" 查询的时候验证参数出错,第 ").append(i + 1).append(" 个参数值为null!").toString()); if (param instanceof Object[]) query.setParameterList((String)conditionNames[i], (Object[])param); else if (param instanceof Collection) query.setParameterList((String)conditionNames[i], (Collection)param); else query.setParameter((String)conditionNames[i], param); } } return query; } public List getEntitiesByNativeSql(String nativeSql, String kids[], Class clazzs[], Object conditionValues[]) { SQLQuery query = getSession().createSQLQuery(nativeSql); if (kids.length != clazzs.length) throw new BusinessException("参数和值的数组长度不匹配,长度必需相等!"); if (clazzs != null) { for (int i = 0; i < clazzs.length; i++) query.addEntity(kids[i], clazzs[i]); } if (conditionValues != null) { for (int i = 0; i < conditionValues.length; i++) { Object param = conditionValues[i]; if (param == null) throw new BusinessException((new StringBuilder("执行原生SQL为:")).append(nativeSql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为null!").toString()); if (param instanceof Object[]) throw new BusinessException((new StringBuilder("执行原生SQL为:")).append(nativeSql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为数组!").toString()); if (param instanceof Collection) throw new BusinessException((new StringBuilder("执行原生SQL为:")).append(nativeSql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为列表!").toString()); query.setParameter(i, param); } } return query.list(); } public List getEntitiesByNativeSql(String nativeSql, String kids[], Class clazzs[], Object conditionValues[], String scalars[], Type types[]) { SQLQuery query = getSession().createSQLQuery(nativeSql); if (clazzs != null) { for (int i = 0; i < clazzs.length; i++) query.addEntity(kids[i], clazzs[i]); } return null; } public List getEntitiesByNativeSql(String nativeSql, String kids[], Class clazzs[]) { SQLQuery query = getSession().createSQLQuery(nativeSql); if (clazzs != null) { for (int i = 0; i < clazzs.length; i++) query.addEntity(kids[i], clazzs[i]); } return query.list(); } public List getEntitiesByNativeSql(String nativeSql, String kids[], Class clazzs[], String as[], Type atype[]) { return null; } public Object getEntity(Serializable id, Class clazz) { Object entity = getHibernateTemplate().get(clazz, id); return entity != null ? entity : BeanUtil.newInstance(clazz); } public Object insert(Object entity) { getHibernateTemplate().save(entity); return entity; } public Object loadEntity(Serializable id, Class clazz) { Object entity = getHibernateTemplate().load(clazz, id); return entity != null ? entity : BeanUtil.newInstance(clazz); } public Object save(Object entity) { if (LogUtil.getIdentify(entity) == null) getHibernateTemplate().save(entity); else getHibernateTemplate().saveOrUpdate(entity); return entity; } private void setQueryConditionValue(String hql, Object conditionValues[], Query query) { if (conditionValues != null) { for (int i = 0; i < conditionValues.length; i++) { Object param = conditionValues[i]; if (param == null) throw new BusinessException((new StringBuilder("执行HQL为:")).append(hql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为null!").toString()); if (param instanceof Object[]) throw new BusinessException((new StringBuilder("执行HQL为:")).append(hql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为数组!").toString()); if (param instanceof Collection) throw new BusinessException((new StringBuilder("执行HQL为:")).append(hql).append(" 验证参数时出错,第 ").append(i + 1).append(" 个参数值为列表!").toString()); query.setParameter(i, param); } } } public Object uniqueResult(String hql, Object conditionValues[]) { Query query = genQuery(hql, conditionValues); return query.uniqueResult(); } public Object update(Object entity) { getHibernateTemplate().update(entity); return entity; } public void updateOrDelete(String hql) { Session session = getSession(); Query query = session.createQuery(hql); query.executeUpdate(); session.flush(); session.clear(); } public void updateOrDelete(String hql, Object conditionValues[]) { Session session = getSession(); Query query = session.createQuery(hql); setQueryConditionValue(hql, conditionValues, query); query.executeUpdate(); session.flush(); session.clear(); } public void updateOrDetete(String hql, Map map) { Query query = getQuery(hql, map.keySet().toArray(), map.values().toArray()); query.executeUpdate(); getSession().flush(); getSession().clear(); } public List getAllEntitys(Class clazz, String sort[]) { StringBuffer hql = new StringBuffer("select o from "); hql.append(clazz.getName()).append(" o "); String as[]; int j = (as = sort).length; for (int i = 0; i < j; i++) { String sor = as[i]; if (sor != null && !"".equals(sor)) hql.append(" order by ").append(sor); } return getEntities(hql.toString()); } public PageInfo getEntities_Page(String hql, Object conditionNames[], Object conditionValues[], PageInfo page) { Long totalCount = getTotalCount(hql, conditionNames, conditionValues); Long totalPages = new Long((new Double(Math.ceil(totalCount.longValue() / page.getPageSize().longValue()))).intValue()); totalPages = Long.valueOf(totalCount.longValue() % page.getPageSize().longValue() != 0L ? totalPages.longValue() + (new Long(1L)).longValue() : totalPages.longValue()); PageInfo pageInfo = new PageInfo(); pageInfo.setPageSize(page.getPageSize()); pageInfo.setPage(page.getPage()); pageInfo.setTotalSize(totalCount); pageInfo.setPageCount(totalPages); Query query = getQuery(hql, conditionNames, conditionValues); query.setFirstResult((page.getPage().intValue() - 1) * page.getPageSize().intValue()); query.setMaxResults(page.getPageSize().intValue()); List list = query.list(); pageInfo.setData(list); return pageInfo; } private Long getTotalCount(String hql, Object conditionNames[], Object conditionValues[]) { Long totalCount = new Long(0L); String lowerhql = hql.toLowerCase(); String totalHql = new String(""); int fIndex = lowerhql.indexOf(" from "); if (fIndex < 0) fIndex = 0; else fIndex++; int orderLastIndex = lowerhql.lastIndexOf(" order by "); if (orderLastIndex > 0) totalHql = (new StringBuilder("select count(*) ")).append(hql.substring(fIndex, orderLastIndex)).append(" ").toString(); else totalHql = (new StringBuilder("select count(*) ")).append(hql.substring(fIndex)).append(" ").toString(); List list = getEntities(totalHql, conditionNames, conditionValues); Number num = (Number)list.get(0); totalCount = new Long(num.longValue()); return totalCount; } protected User getOper() { User oper = (User)SingleThreadImpl.getInstance().get("user_context"); return oper; } }######O(∩_∩)O谢谢,非常有用.######批量删除建议修改下,效率太慢.

kun坤 2020-06-09 11:45:32 0 浏览量 回答数 0

回答

superagent 是一个轻量的,渐进式的ajax api,可读性好,学习曲线低,内部依赖nodejs原生的请求api,适用于nodejs环境下. 一个简单的post请求,并设置请求头信息的例子 request .post('/api/pet') .send({ name: 'Manny', species: 'cat' }) .set('X-API-Key', 'foobar') .set('Accept', 'application/json') .end(function(res){ if (res.ok) { alert('yay got ' + JSON.stringify(res.body)); } else { alert('Oh no! error ' + res.text); } }); 当使用get请求传递查询字符串的时候,用.query()方法,传递一个对象就可以,下面的代码将产生一个/search? query=Manny&range=1..5&order=desc请求: request .get('/search') .query({ query: 'Manny' }) .query({ range: '1..5' }) .query({ order: 'desc' }) .end(function(res){ }); 或者传一个单独的大对象: request .get('/search') .query({ query: 'Manny', range: '1..5', order: 'desc' }) .end(function(res){ }); .query()方法也允许传递字符串: request .get('/querystring') .query('search=Manny&range=1..5') .end(function(res){ }); 或者字符串拼接: request .get('/querystring') .query('search=Manny') .query('range=1..5') .end(function(res){ }); POST/PUT请求 一个典型的json post请求看起来就像下面的那样,设置一个合适的Content-type头字段,然后写入一些数据,在这个例子里只是json字符串: request.post('/user') .set('Content-Type', 'application/json') .send('{"name":"tj","pet":"tobi"}') .end(callback) 因为json非常通用,所以就作为默认的Content-type,下面的例子跟上面的一样: request.post('/user') .send({ name: 'tj', pet: 'tobi' }) .end(callback) 或者调用多次.send()方法: request.post('/user') .send({ name: 'tj' }) .send({ pet: 'tobi' }) .end(callback) 默认发送字符串,将设置Content-type为application/x-www-form-urlencoded,多次调用将会通过&来连接,这里的结果为name=tj&pet=tobi: request.post('/user') .send('name=tj') .send('pet=tobi') .end(callback); superagent的请求数据格式化是可以扩展的,不过默认支持form和json两种格式,想发送数据以application/x-www-form-urlencoded类型的话,则可以简单的调用.type()方法传递form参数就行,这里默认是json,下面的请求将会postname=tj&pet=tobi内容: request.post('/user') .type('form') .send({ name: 'tj' }) .send({ pet: 'tobi' }) .end(callback) 注意:form是form-data和urlencoded的别名,为了向后兼容

小旋风柴进 2019-12-02 02:37:39 0 浏览量 回答数 0

问题

h5做的APP ipv6转换做好了,ipv6下无法访问

刘刚_ 2020-05-20 18:19:01 3 浏览量 回答数 1

问题

使用Java API访问phoenix报错?求大佬解答

hbase小能手 2019-12-01 20:25:55 1461 浏览量 回答数 5

问题

phoenix 连接超时,服务器操作正常

hbase小能手 2019-12-01 20:25:39 1493 浏览量 回答数 1

问题

MySQL:存储过程中的事务?mysql

保持可爱mmm 2020-05-17 18:54:59 1 浏览量 回答数 1

问题

运行solr报错的 java.net.URISyntaxException: I?报错

爱吃鱼的程序员 2020-06-09 14:56:17 0 浏览量 回答数 1

问题

EMR 常见问题?

nicenelly 2019-12-01 21:19:46 1624 浏览量 回答数 0

问题

hibernate delete语句报QueryParameterException错误

云栖技术 2019-12-01 19:40:11 1196 浏览量 回答数 1

回答

缓存配置首先在 persistence.xml 配置文件中添加下面内容: <property name="hibernate.cache.use_second_level_cache" value="true"/> <property name="hibernate.cache.use_query_cache" value="true"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/> <property name="hibernate.generate_statistics" value="true"/> EHCache 还需要一些独立的配置,你需要在类路径中放置 ehcache.xml ,文件内容如下: <cache name="samples.Employee" maxElementsInMemory="2000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false"/> 实体配置 @org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE) 现在,你已经为一个对象配置了缓存,例如通过类似 loadById 之类的方法就可以使缓存生效,但当需要一些查询或者使用标准查询对象时默认是不使用缓存的,因此我们需要在代码上做一些处理。 查询缓存 为了启用查询缓存,我们需要两个配置,一个是启用 hibernate.cache.user_query_cache,另外一个是设置查询缓存: Query query = entityManager.createQuery("from " + Employee.class.getName()); query.setHint("org.hibernate.cacheable", true); return query.getResultList(); 通过统计来确保缓存起效 执行下面的代码可以打印缓存的统计信息 EntityManagerFactoryInfo entityManagerFactoryInfo = (EntityManagerFactoryInfo) applicationContext.getBean("entityManagerFactory"); EntityManagerFactory emf = entityManagerFactoryInfo.getNativeEntityManagerFactory(); EntityManagerFactoryImpl emfImp = (EntityManagerFactoryImpl)emf; System.out.println(emfImp.getSessionFactory().getStatistics()); 别忘了,上述代码需要在 persistence.xml 中启用 hibernate.generate_statistics

a123456678 2019-12-02 02:09:19 0 浏览量 回答数 0

问题

Java SDK样例代码有什么?

nicenelly 2019-12-01 21:19:46 1591 浏览量 回答数 0

回答

HI,要搞清楚锁,首先要搞清楚,PG是有很多可以加锁的对象的,每种对象下面,再去看它的锁冲突。 可以加锁的对象: LOCKTAG_RELATION, /* whole relation */ /* ID info for a relation is DB OID + REL OID; DB OID = 0 if shared */ LOCKTAG_RELATION_EXTEND, /* the right to extend a relation */ /* same ID info as RELATION */ LOCKTAG_PAGE, /* one page of a relation */ /* ID info for a page is RELATION info + BlockNumber */ LOCKTAG_TUPLE, /* one physical tuple */ /* ID info for a tuple is PAGE info + OffsetNumber */ LOCKTAG_TRANSACTION, /* transaction (for waiting for xact done) */ /* ID info for a transaction is its TransactionId */ LOCKTAG_VIRTUALTRANSACTION, /* virtual transaction (ditto) */ /* ID info for a virtual transaction is its VirtualTransactionId */ LOCKTAG_SPECULATIVE_TOKEN, /* speculative insertion Xid and token */ /* ID info for a transaction is its TransactionId */ LOCKTAG_OBJECT, /* non-relation database object */ /* ID info for an object is DB OID + CLASS OID + OBJECT OID + SUBID */ /* * Note: object ID has same representation as in pg_depend and * pg_description, but notice that we are constraining SUBID to 16 bits. * Also, we use DB OID = 0 for shared objects such as tablespaces. */ LOCKTAG_USERLOCK, /* reserved for old contrib/userlock code */ LOCKTAG_ADVISORY /* advisory user locks */ 锁模式 /* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */ #define NoLock 0 #define AccessShareLock 1 /* SELECT */ #define RowShareLock 2 /* SELECT FOR UPDATE/FOR SHARE */ #define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */ #define ShareUpdateExclusiveLock 4 /* VACUUM (non-FULL),ANALYZE, CREATE * INDEX CONCURRENTLY */ #define ShareLock 5 /* CREATE INDEX (WITHOUT CONCURRENTLY) */ #define ShareRowExclusiveLock 6 /* like EXCLUSIVE MODE, but allows ROW * SHARE */ #define ExclusiveLock 7 /* blocks ROW SHARE/SELECT...FOR * UPDATE */ #define AccessExclusiveLock 8 /* ALTER TABLE, DROP TABLE, VACUUM * FULL, and unqualified LOCK TABLE */ 然后我们说一下死锁,死锁相互等待造成的,你给的图没有等待,所以一定不是死锁。 最后提供一个查询锁和等待的方法给你,会比较好看。 用一个函数来将锁转换为数字, postgres=# create or replace function f_lock_level(i_mode text) returns int as $$ declare begin case i_mode when 'INVALID' then return 0; when 'AccessShareLock' then return 1; when 'RowShareLock' then return 2; when 'RowExclusiveLock' then return 3; when 'ShareUpdateExclusiveLock' then return 4; when 'ShareLock' then return 5; when 'ShareRowExclusiveLock' then return 6; when 'ExclusiveLock' then return 7; when 'AccessExclusiveLock' then return 8; else return 0; end case; end; $$ language plpgsql strict; 修改查询语句,按锁级别排序: with t_wait as (select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.objid,a.objsubid, a.pid,a.virtualtransaction,a.virtualxid,a,transactionid,b.query,b.xact_start,b.query_start, b.usename,b.datname from pg_locks a,pg_stat_activity b where a.pid=b.pid and not a.granted), t_run as (select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.objid,a.objsubid, a.pid,a.virtualtransaction,a.virtualxid,a,transactionid,b.query,b.xact_start,b.query_start, b.usename,b.datname from pg_locks a,pg_stat_activity b where a.pid=b.pid and a.granted) select r.locktype,r.mode r_mode,r.usename r_user,r.datname r_db,r.relation::regclass,r.pid r_pid, r.page r_page,r.tuple r_tuple,r.xact_start r_xact_start,r.query_start r_query_start, now()-r.query_start r_locktime,r.query r_query,w.mode w_mode,w.pid w_pid,w.page w_page, w.tuple w_tuple,w.xact_start w_xact_start,w.query_start w_query_start, now()-w.query_start w_locktime,w.query w_query from t_wait w,t_run r where r.locktype is not distinct from w.locktype and r.database is not distinct from w.database and r.relation is not distinct from w.relation and r.page is not distinct from w.page and r.tuple is not distinct from w.tuple and r.classid is not distinct from w.classid and r.objid is not distinct from w.objid and r.objsubid is not distinct from w.objsubid and r.transactionid is not distinct from w.transactionid and r.pid <> w.pid order by f_lock_level(w.mode)+f_lock_level(r.mode) desc,r.xact_start; 现在可以排在前面的就是锁级别高的等待,优先干掉这个。 -[ RECORD 1 ]-+--------------------------------------------------------------------- locktype | relation -- 冲突类型 r_mode | ShareUpdateExclusiveLock -- 持锁模式 r_user | postgres -- 持锁用户 r_db | postgres -- 持锁数据库 relation | tbl -- 持锁对象 r_pid | 25656 -- 持锁进程 r_xact_start | 2015-05-10 14:11:16.08318+08 -- 持锁事务开始时间 r_query_start | 2015-05-10 14:11:16.08318+08 -- 持锁SQL开始时间 r_locktime | 00:01:49.460779 -- 持锁时长 r_query | vacuum freeze tbl; -- 持锁SQL,注意不一定是这个SQL带来的锁,也有可能是这个事务在之前执行的SQL加的锁 w_mode | AccessExclusiveLock -- 等待锁模式 w_pid | 26731 -- 等待锁进程 w_xact_start | 2015-05-10 14:11:17.987362+08 -- 等待锁事务开始时间 w_query_start | 2015-05-10 14:11:17.987362+08 -- 等待锁SQL开始时间 w_locktime | 00:01:47.556597 -- 等待锁时长 w_query | truncate tbl; -- 等待锁SQL -[ RECORD 2 ]-+--------------------------------------------------------------------- locktype | relation r_mode | ShareUpdateExclusiveLock r_user | postgres r_db | postgres relation | tbl r_pid | 25656 r_xact_start | 2015-05-10 14:11:16.08318+08 r_query_start | 2015-05-10 14:11:16.08318+08 r_locktime | 00:01:49.460779 r_query | vacuum freeze tbl; w_mode | RowExclusiveLock w_pid | 25582 w_xact_start | 2015-05-10 14:11:22.845+08 w_query_start | 2015-05-10 14:11:22.845+08 w_locktime | 00:01:42.698959 w_query | insert into tbl(crt_time) select now() from generate_series(1,1000); -- 这个SQL其实等待的是truncate tbl的锁; ......

德哥 2019-12-02 01:29:55 0 浏览量 回答数 0
阿里云大学 云服务器ECS com域名 网站域名whois查询 开发者平台 小程序定制 小程序开发 国内短信套餐包 开发者技术与产品 云数据库 图像识别 开发者问答 阿里云建站 阿里云备案 云市场 万网 阿里云帮助文档 免费套餐 开发者工具 云栖号物联网 小程序开发制作 视频内容分析 企业网站制作 视频集锦 代理记账服务 2020阿里巴巴研发效能峰会 企业建站模板 云效成长地图 高端建站 云栖号弹性计算 阿里云云栖号 云栖号案例 云栖号直播