• 关于

    getid3

    的搜索结果

问题

为每个新类分配唯一的ID(不是实例!)

montos 2020-03-23 16:01:12 1 浏览量 回答数 1

问题

按名称调用时服务与nullPointer一起使用,而调用rest时服务正常工作

垚tutu 2019-12-01 22:06:21 7 浏览量 回答数 1

问题

一段java并发同步代码的疑惑

蛮大人123 2019-12-01 20:02:06 901 浏览量 回答数 2

万券齐发助力企业上云,爆款产品低至2.2折起!

限量神券最高减1000,抢完即止!云服务器ECS新用户首购低至0.95折!

回答

TaskCall每个线程一个实例,getId放到TaskCall里,则synchronized修饰符是获取taskCall实例的锁,因有3个实例所以有出现上述情况

chankan 2019-12-02 01:53:37 0 浏览量 回答数 0

问题

向mysql数据库中插入数据时报错的问题

落地花开啦 2019-12-01 19:47:44 2300 浏览量 回答数 3

问题

sessinid每次都不同

放到 2019-12-01 22:08:19 3854 浏览量 回答数 0

回答

我用你的实体类写了一遍,没有发现任何问题啊! temim1=newMenuItem(); im1.setId(2); im1.setParentId(0); im1.setList(null); MenuItemim2=newMenuItem(); im2.setId(3); im2.setParentId(0); im2.setList(null); List<MenuItem>list=newArrayList<MenuItem>(); list.add(im1); list.add(im2); MenuItempm=newMenuItem(); pm.setId(1); pm.setParentId(0); pm.setList(list); Gsonjson=newGson(); Stringstr=json.toJson(pm); System.out.println(str); Stringstr1="{\"id\":1,\"parentId\":0,\"list\":[{\"id\":2,\"parentId\":0},{\"id\":3,\"parentId\":0}]}"; MenuItempm2=json.fromJson(str1,MenuItem.class); System.out.println(pm2.getId()); System.out.println(pm2.getList().get(0).getId());

爱吃鱼的程序员 2020-06-15 19:47:32 0 浏览量 回答数 0

问题

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

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

问题

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

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

回答

如果所有按钮操作都一样的话,那也简单//你的activity public class MainActivity extends Activity implements View.OnClickListener { @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_1: case R.id.btn_2: case R.id.btn_3: case R.id.btn_4: case R.id.btn_5: case R.id.btn_6: case R.id.btn_7: // 好了,全部获取到了 String text =( (Button)v).getText().toString(); break; } }

爵霸 2019-12-02 02:10:38 0 浏览量 回答数 0

问题

TransientObjectException 保存的对象被引用异常

a123456678 2019-12-01 20:21:17 981 浏览量 回答数 1

问题

java,session销毁的问题Java报错

python小菜菜 2020-06-02 19:37:39 1 浏览量 回答数 1

问题

hibernate如何保存三层结构的数据表

小旋风柴进 2019-12-01 20:22:44 1067 浏览量 回答数 0

回答

因为之前的executeupdate返回为0可能跟mysql版本有关,也可能跟持久层框架有关,所以为了通用性,我就把程序改成“先做了delete后再做insert”你的表达式时间间隔太短了官网给的demo时间也是5秒 改源码,解决了该问题。 引用来自“见习程序猿”的评论 改源码,解决了该问题。 privatebooleaninsertJobExecutionEventWhenSuccess(finalJobExecutionEventjobExecutionEvent){booleanresult=false;StringsqlDelete="DELETEFROM"+TABLE_JOB_EXECUTION_LOG+"whereid=?";StringsqlInsert="INSERTINTO`"+TABLE_JOB_EXECUTION_LOG+"`(`id`,`job_name`,`task_id`,`hostname`,`ip`,`sharding_item`,`execution_source`,`is_success`,`start_time`,`complete_time`)"+"VALUES(?,?,?,?,?,?,?,?,?,?);";Connectionconn=null;PreparedStatementpreparedStatement=null;try{conn=dataSource.getConnection();preparedStatement=conn.prepareStatement(sqlDelete);preparedStatement.setString(1,jobExecutionEvent.getId());preparedStatement.execute();preparedStatement=conn.prepareStatement(sqlInsert);preparedStatement.setString(1,jobExecutionEvent.getId());preparedStatement.setString(2,jobExecutionEvent.getJobName());preparedStatement.setString(3,jobExecutionEvent.getTaskId());preparedStatement.setString(4,jobExecutionEvent.getHostname());preparedStatement.setString(5,jobExecutionEvent.getIp());preparedStatement.setInt(6,jobExecutionEvent.getShardingItem());preparedStatement.setString(7,jobExecutionEvent.getSource().toString());preparedStatement.setBoolean(8,jobExecutionEvent.isSuccess());preparedStatement.setTimestamp(9,newTimestamp(jobExecutionEvent.getStartTime().getTime()));preparedStatement.setTimestamp(10,newTimestamp(jobExecutionEvent.getCompleteTime().getTime()));preparedStatement.execute();result=true;}catch(finalSQLExceptionex){if(isDuplicateRecord(ex)){returnupdateJobExecutionEventWhenSuccess(jobExecutionEvent);}//TODO记录失败直接输出日志,未来可考虑配置化log.error(ex.getMessage());}returnresult;}  

爱吃鱼的程序员 2020-06-07 22:01:10 0 浏览量 回答数 0

问题

将焦点从一个“编辑”文本框移到另一个

LiuWH 2020-01-23 13:28:00 0 浏览量 回答数 1

回答

用事件监听的方式,根据用户ID或其他分库条件,来修改或者动态地注册数据库连接实例。或者简单点,就自己注册多个连接实例,然后定义一个获取所需实例的helper,比如按用户ID来分库:// (一)在app/config/config.yml里: # 定义好各个数据库连接 // (二)在controller里: private function getManager() { $user = $this->getUser(); // 取得当前用户 $shardId = null !== $user ? $user->getId() % 4 : 0; // 0,1,2,3共四个库 return $this->getDoctrine()->getManager(sprintf('shard_%s', $shardId)); } // (三)在业务Action里: public function someAction() { $om = $this->getManager(); // 这时拿到的就是对应当前用户的数据库连接实例了 // ... }在你的业务代码中,你还得考虑分片化后业务的完整性。

落地花开啦 2019-12-02 02:47:05 0 浏览量 回答数 0

回答

<p>楼主所示的错误信息似乎是说 departHeadUserList 没有创建成功(null)。</p> 数组存储异常, 即试图将错误类型的对象存储到一个对象数组时抛出的异常。 例如: public class Cns{ public static void main(String args[]){ Object x[] = new String[3]; x[1] = new Double(0.5); } } 参考: java.lang.ArrayStoreException异常 <p>sorray, my fault.</p> 上面是把对象直接转成string了,肯定转换不成功的。 改成如下方式就可以了。 assignees = departHeadUserList.stream().map(e->e.getId()).toArray(String[]::new); 不过他提示的异常也是挺奇怪。 提示的 ArayStoreException, 是运行时才发现的异常。是否运行时 赋值造成异常?

爱吃鱼的程序员 2020-06-05 13:51:24 0 浏览量 回答数 0

回答

代码如下: public class Guess { private int id; private String prize; private int v; public Guess(int id, String prize, int v) { super(); this.id = id; this.prize = prize; this.v = v; } public i1nt getId() { return id; } public void setId(int id) { this.id = id; } public String getPrize() { return prize; } public void setPrize(String prize) { this.prize = prize; } public int getV() { return v; } public void setV(int v) { this.v = v; } } public class WinPrize { private int mes; private String prize; public int getMes() { return mes; } public WinPrize(int mes, String prize) { super(); this.mes = mes; this.prize = prize; } public WinPrize() { super(); // TODO Auto-generated constructor stub } @Override public String toString() { return "mes:" + mes + ", prize:" + prize; } public void setMes(int mes) { this.mes = mes; } public String getPrize() { return prize; } public void setPrize(String prize) { this.prize = prize; } } public class TestPHP { public void guess_prize(){ Map prize_attr=new HashMap(); Integer[] arr=null; prize_attr.put(0, new Guess(1,"平板电脑",3)); prize_attr.put(1, new Guess(2,"数码相机",5)); prize_attr.put(2, new Guess(3,"音箱设备",10)); prize_attr.put(3, new Guess(4,"4G优盘",12)); prize_attr.put(4, new Guess(5,"Q币10元",20)); prize_attr.put(5, new Guess(6,"下次没准就能中哦",50)); arr=new Integer[prize_attr.size()+1]; for(Guess g:prize_attr.values()){ //System.out.println(prize_attr.size()); arr[g.getId()]=g.getV(); } WinPrize res=new WinPrize(); int rid=getRand(arr); if(prize_attr.get(rid)==null){ res.setMes(0); res.setPrize("下次没准就能中哦"); }else{ res.setMes(rid==6?0:1); res.setPrize(prize_attr.get(rid).getPrize()); } System.out.println(res); } public int getRand(Integer[] arr){ int sum=0; int result=0; //System.out.println(arr); for(int i=1;i<arr.length;i++){ sum+=arr[i]; } for(int i=1;i<arr.length;i++){ Random r=new Random(); int random=r.nextInt(sum)+1;//arr长度为6,生成1-6的随机数 if(random<=arr[i]){ result=i; break; }else{ sum-=arr[i]; } } return result; } public static void main(String[] args) { new TestPHP().guess_prize(); } }

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

回答

如果你想Map自动更新时id一个的OtherClass对象被修改,那么你需要编写的代码为你自己。 除非地图和对象紧密耦合,否则应保持逻辑分离,例如,通过实现属性更改跟踪。 我建议围绕PropertyChangeSupportJava Runtime Library中的类构建它。 其他类 首先,您需要启用属性更改跟踪。 我name在此答案的末尾添加了属性以改善测试代码的输出。 public final class OtherClass { private final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); private int id; private String name; public OtherClass(int id, String name) { this.id = id; this.name = name; } public void addPropertyChangeListener(PropertyChangeListener listener) { this.pcs.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { this.pcs.removePropertyChangeListener(listener); } public int getId() { return this.id; } public void setId(int id) { int oldId = this.id; this.id = id; this.pcs.firePropertyChange("id", oldId, id); } public String getName() { return this.name; } public void setName(String name) { String oldName = this.name; this.name = name; this.pcs.firePropertyChange("name", oldName, name); } @Override public String toString() { return "OtherClass[" + this.id + ", " + this.name + "]"; } } 接下来,您需要封装,Map以便可以正确处理属性更改侦听器。 为了防止内存泄漏,重要的是要clear()在OtherMap当不再需要它,否则,以一个单一的参考OtherMap对象,它是在OtherMap将保持在map和所有在map中的对象在内存活。为了解决这个问题,我创建了object AutoCloseable,以便可以将其与try-with-resources语句一起使用,并使代码分析器帮助强调需要关闭/清除Map。 final class OtherMap implements AutoCloseable { private final PropertyChangeListener listener = this::onPropertyChange; private Map<Integer, OtherClass> map = new HashMap<>(); public OtherMap() { } public Set<Integer> keys() { return Collections.unmodifiableSet(this.map.keySet()); } public Collection<OtherClass> values() { return Collections.unmodifiableCollection(this.map.values()); } public OtherClass get(int id) { return this.map.get(id); } public OtherClass add(OtherClass other) { OtherClass prev = this.map.put(other.getId(), other); if (prev != null) prev.removePropertyChangeListener(this.listener); other.addPropertyChangeListener(this.listener); return prev; } public OtherClass remove(int id) { OtherClass other = this.map.remove(id); if (other != null) other.removePropertyChangeListener(this.listener); return other; } public void clear() { this.map.values().forEach(other -> other.removePropertyChangeListener(this.listener)); this.map.clear(); } private void onPropertyChange(PropertyChangeEvent evt) { if (! "id".equals(evt.getPropertyName())) return; Integer oldId = (Integer) evt.getOldValue(); Integer newId = (Integer) evt.getNewValue(); if (oldId.equals(newId)) return; OtherClass other = (OtherClass) evt.getSource(); if (this.map.putIfAbsent(newId, other) != null) throw new IllegalStateException("Duplicate key"); if (! this.map.remove(oldId, other)) { this.map.remove(newId); throw new IllegalStateException(); } } @Override public String toString() { return this.map.toString(); } @Override public void close() { clear(); } } 测试 OtherClass eeny = new OtherClass(3, "Eeny"); OtherClass meeny = new OtherClass(5, "Meeny"); OtherClass miny = new OtherClass(7, "Miny"); OtherClass moe = new OtherClass(9, "Moe"); OtherMap otherMap = new OtherMap(); otherMap.add(eeny); otherMap.add(meeny); otherMap.add(miny); otherMap.add(moe); System.out.println("Before: " + otherMap); meeny.setId(2); otherMap.remove(miny.getId()); miny.setId(4); System.out.println("After: " + otherMap); 输出量 Before: {3=OtherClass[3, Eeny], 5=OtherClass[5, Meeny], 7=OtherClass[7, Miny], 9=OtherClass[9, Moe]} After: {2=OtherClass[2, Meeny], 3=OtherClass[3, Eeny], 9=OtherClass[9, Moe]} 回答来源:Stack Overflow

montos 2020-03-25 19:24:32 0 浏览量 回答数 0

回答

Cause:org.apache.ibatis.binding.BindingException:Parameter'id'notfound.Availableparametersare[goodsNo,param7,param5,param6,num,source,param3,userId,param4,param1,param2,now,shopNo,status]   异常在此。废话 你前面就是XX.id 你后面直接ID?告诉你了 id not found   mybatis改成cart.id也是一样的错 参数用对象,insert/update语句返回的是影响的条数,不是你要的主键意思是mybatis不能返回自增主键值?我换成对象也是错 <insertid="insertAndGetId"useGeneratedKeys="true"keyProperty="userId"parameterType="com.chenzhou.mybatis.User">insertintouser(userName,password,comment)values(#{userName},#{password},#{comment})</insert> publicclassUser{privateintuserId;privateStringuserName;privateStringpassword;privateStringcomment;//setterandgetter}  我用getId也是错回复 @王静0716:主键会set到user的userId上,而不是返回值我就是这样写的啊 <insertid="addCartAndGetId"parameterType="com.wj.pojo.Cart"useGeneratedKeys="true"keyProperty="cart.id">insertintocart(shop_no,goods_no,user_id,num,status,create_time,update_time,source)VALUES(#{cart.shopNo},#{cart.goodsNo},${cart.userId},${cart.num},${cart.status},#{cart.createTime},#{cart.updateTime},${cart.source})</insert>intaddCartAndGetId(@Param("cart")Cartcart);Cartcart=newCart();cart.setShopNo(goods.getShopNo());cart.setGoodsNo(goodsNo);cart.setUserId(userId);cart.setNum(buyNum);cart.setStatus(CartStatus.addCart.ordinal());cart.setCreateTime(now);cart.setUpdateTime(now);cart.setSource(source);//cartId=cartMapper.insertSelective(cart);orderDao.addCartAndGetId(cart);cartId=cart.getId();这样写就对了。   <tabletableName="rc_template"><generatedKeycolumn="ID"sqlStatement="MySql"identity="true"/></table> generatorconfig文件配置。亲测有效。http://blog.csdn.net/u011403655/article/details/50696341

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

回答

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

问题

Spring + shiro配置警告 :报错

kun坤 2020-06-06 19:02:47 0 浏览量 回答数 1

问题

Spring + shiro配置警告 - java报错

montos 2020-05-31 00:03:15 0 浏览量 回答数 1

问题

Spring + shiro配置警告 403.10 禁止访问:配置无效 

kun坤 2020-05-27 14:00:33 6 浏览量 回答数 1

回答

1数据库开发中经常会遇到一对多的关系,例如客户与订单的关系,一个客户对应多个订单。开发一个customer与orders的demo (1)领域模型 customer [java] view plain copy package com.songxu.domain; import java.io.Serializable; import java.util.Set; public class Customer implements Serializable { private int id; private String name; private Set orders; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getOrders() { return orders; } public void setOrders(Set orders) { this.orders = orders; } } orders [java] view plain copy package com.songxu.domain; import java.io.Serializable; import java.sql.Timestamp; public class Order implements Serializable { private int id; private Timestamp time; private Customer customer; public int getId() { return id; } public void setId(int id) { this.id = id; } public Timestamp getTime() { return time; } public void setTime(Timestamp time) { this.time = time; } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } } (2) hbm 映射文件 customer [html] view plain copy <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.songxu.domain.Customer" table="customer"> <id column="id" name="id" type="int"> <generator class="increment"/> </id> <!-- column同名时可以省略 --> <property column="name" generated="never" lazy="false" name="name" type="string"/> <set name="orders" cascade="save-update" inverse="true" > <key column="customer" ></key> <one-to-many class="com.songxu.domain.Order"/> </set> </class> </hibernate-mapping> order [html] view plain copy <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.songxu.domain.Order" table="orders"> <id column="id" name="id" type="int"> <generator class="increment"/> </id> <!-- column同名时可以省略 --> <property column="occurTime" generated="never" lazy="false" name="time" type="timestamp"/> <many-to-one name="customer" class="com.songxu.domain.Customer" column="customer_id"></many-to-one> </class> </hibernate-mapping> 2 自身一对多的例子,如层次关系 (1) 领域模型 [java] view plain copy package com.songxu.domain; import java.util.Set; public class Food { private int id; private String name ; private Food parentFood; private Set<Food> childFood; public int getId() { return id; } public Food() { } public Food(String name, Food parentFood, Set<Food> childFood) { this.name = name; this.parentFood = parentFood; this.childFood = childFood; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Food getParentFood() { return parentFood; } public void setParentFood(Food parentFood) { this.parentFood = parentFood; } public Set<Food> getChildFood() { return childFood; } public void setChildFood(Set<Food> childFood) { this.childFood = childFood; } } (2) 映射文件 [html] view plain copy <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.songxu.domain.Food" table="food"> <id column="id" name="id" type="int"> <generator class="increment" /> </id> <!-- column同名时可以省略 --> <property column="name" generated="never" lazy="false" name="name" type="string" /> <many-to-one name="parentFood" class="com.songxu.domain.Food" column="foodId"></many-to-one> <set name="childFood" cascade="all"> <key column="foodId"></key> <one-to-many class="com.songxu.domain.Food" /> </set> </class> </hibernate-mapping> (3) 测试代码 [java] view plain copy package com.songxu.test; import java.util.HashSet; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import com.songxu.domain.Food; public class FoodTest { static Configuration configuration; static SessionFactory sessionFactory; static { configuration=new Configuration().configure(); sessionFactory=configuration.buildSessionFactory(); } public static void main(String[] args) { Session session=sessionFactory.openSession(); Transaction tx=null; try { tx=session.beginTransaction(); Food food=new Food("食品",null,new HashSet<Food>()); Food fruit=new Food("水果",null,new HashSet<Food>()); Food vegetables=new Food("蔬菜",null,new HashSet<Food>()); food.getChildFood().add(fruit); food.getChildFood().add(vegetables); fruit.setParentFood(food); vegetables.setParentFood(food); Food fruit1=new Food("苹果",null,new HashSet<Food>()); Food fruit2=new Food("香蕉",null,new HashSet<Food>()); Food v1=new Food("黄瓜",null,new HashSet<Food>()); Food v2=new Food("茄子",null,new HashSet<Food>()); fruit.getChildFood().add(fruit1); fruit.getChildFood().add(fruit2); fruit1.setParentFood(fruit); fruit2.setParentFood(fruit); vegetables.getChildFood().add(v1); vegetables.getChildFood().add(v2); v1.setParentFood(vegetables); v2.setParentFood(vegetables); //仅保存根对象就可以了 session.save(food); //session.get(Food.class,1); tx.commit(); } catch (Exception e) { if(null!=tx) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); } }

云栖技术 2019-12-02 02:32:21 0 浏览量 回答数 0

问题

室内流动

LiuWH 2020-01-12 09:16:59 0 浏览量 回答数 1

问题

无法启动活动ComponentInfo-Android

LiuWH 2020-01-18 22:09:34 1 浏览量 回答数 1

回答

用poi吧,先读取excel表格数据,然后再写入到txt里面;给你个案例你看看 public class CreateExcel { private static List getstudent() throws Exception{ List list=new ArrayList(); SimpleDateFormat df=new SimpleDateFormat("yyyy-mm-dd"); Student stu=new Student(13, "张三", 14, df.parse("2015-3-3")); Student stu1=new Student(17, "张三", 18, df.parse("2015-3-4")); Student stu2=new Student(23, "张三", 21, df.parse("2015-3-5")); list.add(stu); list.add(stu1); list.add(stu2); return list; } public static void main(String[] args) { //第一步,创建一个webbook,对应一个excel文件 HSSFWorkbook wb=new HSSFWorkbook(); //第二步,在webbook中添加一个sheet,对应excel文件中的sheet HSSFSheet sheet=wb.createSheet("学生表一"); //第三步,在sheet中添加表头第0行 HSSFRow row=sheet.createRow((int)0); //第四步,创建单元格,并设置表头 设置表头居中 HSSFCellStyle style=wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); //创建一个居中表格 HSSFCell cell=row.createCell((short)0); cell.setCellValue("学号"); cell.setCellStyle(style); cell=row.createCell((short)1); cell.setCellValue("姓名"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("年龄"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("生日"); cell.setCellStyle(style); //第五步,写入实体数据 try { List list=CreateExcel.getstudent(); for(int i=0;i<list.size();i++){ row=sheet.createRow((int)i+1); Student str=(Student) list.get(i); //第六步创建单元格,并设置值 row.createCell(0).setCellValue(str.getId()); row.createCell(1).setCellValue(str.getName()); row.createCell(2).setCellValue(str.getAge()); row.createCell(3).setCellValue(new SimpleDateFormat("yyy-mm-dd").format(str.getBirth())); } //第七步将文件存到指定位置 FileOutputStream fout=new FileOutputStream("D:/student.txt"); wb.write(fout); fout.close(); } catch (Exception e) { e.printStackTrace(); } } }

蛮大人123 2019-12-02 01:53:04 0 浏览量 回答数 0

问题

mybatis对象插入一个对象 ? :报错

kun坤 2020-06-14 07:33:48 0 浏览量 回答数 1

问题

mybatis对象插入一个对象 ?-mybatis报错

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