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;
}



