使用mybatis plus框架,service继承了IService,SysOrder为订单实体类,SysOrderMapper为mybatis plus的Mapper接口,请写出controller层的增删改查功能
时间: 2024-05-09 15:19:42 浏览: 204
基于mybatis-plus的快速开发框架源码+数据库,无需手写增查查改等接口方法,只需建好实体类
增加功能:
```java
@RestController
@RequestMapping("/orders")
public class OrderController {
@Autowired
private SysOrderService sysOrderService;
@PostMapping
public boolean addOrder(@RequestBody SysOrder sysOrder) {
return sysOrderService.save(sysOrder);
}
}
```
删除功能:
```java
@RestController
@RequestMapping("/orders")
public class OrderController {
@Autowired
private SysOrderService sysOrderService;
@DeleteMapping("/{id}")
public boolean deleteOrder(@PathVariable("id") Long id) {
return sysOrderService.removeById(id);
}
}
```
修改功能:
```java
@RestController
@RequestMapping("/orders")
public class OrderController {
@Autowired
private SysOrderService sysOrderService;
@PutMapping("/{id}")
public boolean updateOrder(@PathVariable("id") Long id, @RequestBody SysOrder sysOrder) {
sysOrder.setId(id);
return sysOrderService.updateById(sysOrder);
}
}
```
查询功能:
```java
@RestController
@RequestMapping("/orders")
public class OrderController {
@Autowired
private SysOrderService sysOrderService;
@GetMapping("/{id}")
public SysOrder getOrder(@PathVariable("id") Long id) {
return sysOrderService.getById(id);
}
@GetMapping
public List<SysOrder> getOrderList() {
return sysOrderService.list();
}
}
```
阅读全文