栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java接口概念(java什么是接口)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java接口概念(java什么是接口)

查询接口定义

CRUD

单条查询:

@RequestMapping(value = "/qust",method = RequestMethod.GET)
public Student list(@PathVariable Integer id){
   List ldd  =   orderRecordMapper.selectByPrimaryKey(id);
   return ldd ;
}

或
@RequestMapping(value = "/qust",method = RequestMethod.GET)
public @RequestBodylist  Object qust (Integer id){
   Student ldd  =   orderRecordMapper.selectByPrimaryKey(id);
   return ldd ;
}
全表查询:
xml配置文件增加全表查询



新增查询全表数据接口方法
List selectAll();


@RequestMapping(value = "/list",method = RequestMethod.GET)
public List list(){
    List ldd  =   orderRecordMapper.selectAll();
    return ldd ;
}

新增表数据

//@Transactional(rollbackFor = Exception.class)  开启事务 一般不需要开启
public void insert(OrderRecordInsertUpdateDto dto) throws Exception{
   

   //TODO:采用spring提供的BeanUtils进行操作 只需三行代码
   OrderRecord record=new OrderRecord();
   BeanUtils.copyProperties(dto,record);
   orderRecordMapper.insertSelective(record);
}

@Autowired
private OrderRecordMapper orderRecordMapper;
@Autowired
private OrderRecordService orderRecordService;
@RequestMapping(value = prefix+"/save",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public baseResponse insert(@RequestBody OrderRecordInsertUpdateDto dto){
    baseResponse response=new baseResponse(StatusCode.Success);
    try {
        log.info("接收数据:{} ",dto);

        //TODO:进行属于你自己的控制层层面的校验以及处理
        orderRecordService.insert(dto);
    }catch (Exception e){
        log.error("新增发生异常:",e.fillInStackTrace());
        response=new baseResponse(StatusCode.Fail.getCode(),e.getMessage());
    }
    return response;
}

更新表数据

public void update(OrderRecord entity,OrderRecordInsertUpdateDto dto) throws Exception{
    //TODO:采用spring提供的BeanUtils进行操作 
    final Integer pk=entity.getId();
    BeanUtils.copyProperties(dto,entity);
    entity.setUpdateTime(new Date());
    entity.setId(pk);

    orderRecordMapper.updateByPrimaryKeySelective(entity);
}

@RequestMapping(value = prefix+"/update",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public baseResponse update(@RequestBody OrderRecordInsertUpdateDto dto){
  baseResponse response=new baseResponse(StatusCode.Success);
  try {
      log.info("接收数据:{} ",dto);

      //TODO:进行属于你自己的控制层层面的校验以及处理
      OrderRecord entity=orderRecordMapper.selectByPrimaryKey(dto.getId());
      if (entity==null){
          return new baseResponse(StatusCode.Entity_Not_Exist);
      }

      orderRecordService.update(entity,dto);
  }catch (Exception e){
      log.error("更新发生异常:",e.fillInStackTrace());
      response=new baseResponse(StatusCode.Fail.getCode(),e.getMessage());
  }
  return response;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/776309.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号