赞
踩
一.单条:通过主键id,直接对修改字段进行操作即可,不用再附带已有值和修改字段一起修改。
- public void updateInfo(){
- String id="344364895434851641";
- OrderDetailEntity od= orderService.queryOrderDetailEntityById(id);
- if(od==null){
- System.out.println("od为null");
-
- }
- System.out.println("od "+od.getOrderNo()+" id:"+od.getId());
- // od.setMiAmount(new BigDecimal(0));
- //od.setPayMethod(7);
- // od.setPayMoney(new BigDecimal(1.5));
- //341224197805034914
- od.setIdCard("341224197805034914");
- od.setRegisterTime(new Date());
- od.setAnalysisFlag(1);
- orderService.add(od);
-
- }
-
- /**
- * 添加
- * @param oe
- */
- public void add(OrderDetailEntity oe){
- ordersSearchRepository.save(oe);
- }
二。批量修改:使用主键更新,携带修改的字段即可
- public void batchUpdataData(){
- List<OrderDetailEntity> orderList=new ArrayList<OrderDetailEntity>();
- OrderDetailEntity ot1=new OrderDetailEntity();
- ot1.setOrderNo("344363949099720272");
- ot1.setIdCard("210204199303306485");
- ot1.setRegisterTime(new Date());
- ot1.setAnalysisFlag(1);
- orderList.add(ot1);
- OrderDetailEntity ot2=new OrderDetailEntity();
- ot2.setOrderNo("344371376360840270");
- ot2.setIdCard("500222199801010320");
- ot2.setRegisterTime(new Date());
- ot2.setAnalysisFlag(1);
- orderList.add(ot2);
- OrderDetailEntity ot3=new OrderDetailEntity();
- ot3.setOrderNo("344337535029511645");
- ot3.setIdCard("210202199505250720");//344337535029511645
- ot3.setRegisterTime(new Date());
- ot3.setAnalysisFlag(1);
- orderList.add(ot3);
-
- orderService.bulkUpdateData(orderList);
-
- }
-
- /**
- * 批量修改
- * @param orderNoList
- */
- @Override
- public void bulkUpdateData(List<OrderDetailEntity> orderNoList) {
- List<UpdateQuery> updateList = new ArrayList<UpdateQuery>();
- for(OrderDetailEntity orderDetailEntity:orderNoList){
- IndexRequest indexRequest = new IndexRequest();
- Map<String,Object> map=new HashMap<String,Object>();
- map.put("idCard",orderDetailEntity.getIdCard());
- map.put("registerTime",new Date().getTime());
- map.put("analysisFlag", orderDetailEntity.getAnalysisFlag());
- System.out.println("orderno:"+orderDetailEntity.getOrderNo());
- //这里只能用map,不能json串
- indexRequest.source(map);
- UpdateQuery updateQuery = new UpdateQueryBuilder().withId(orderDetailEntity.getOrderNo())
- .withClass(OrderDetailEntity.class).withIndexRequest(indexRequest).build();
- updateList.add(updateQuery);
- }
- // when
- elasticsearchTemplate.bulkUpdate(updateList);
- elasticsearchTemplate.refresh(OrderDetailEntity.class);
- System.out.println("修改完成!!!");
- }
- private <T> Map<String,Object> beanToMap(T bean){
- Map<String, Object> map = new HashMap<String,Object>();;
- if (null != bean){
- BeanMap beanMap = BeanMap.create(bean);
- for (Object key : beanMap.keySet()){
- map.put(key+"",beanMap.get(key));
- }
- }
- return map;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。