订单类CRUD和Controller API
This commit is contained in:
parent
8f1ee8896b
commit
872bb0e3e7
@ -0,0 +1,33 @@
|
||||
package com.example.springdemo.controller;
|
||||
|
||||
import com.example.springdemo.entities.Orders;
|
||||
import com.example.springdemo.service.OrdersService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/indent")
|
||||
public class OrdersController {
|
||||
@Resource
|
||||
private OrdersService ordersService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public Orders addIndent(@RequestBody Orders orders) {
|
||||
return ordersService.addIndent(orders);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public void deleteIndent(@PathVariable Long id) {
|
||||
ordersService.deleteIndentById(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Orders updateIndent(@RequestBody Orders orders) {
|
||||
return ordersService.updateIndent(orders);
|
||||
}
|
||||
|
||||
@GetMapping("/find")
|
||||
public Iterable<Orders> getIndent() {
|
||||
return ordersService.findAllIndents();
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.example.springdemo.dao;
|
||||
|
||||
import com.example.springdemo.entities.Indent;
|
||||
import com.example.springdemo.entities.Orders;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface IndentRepository
|
||||
extends CrudRepository<Indent, Long> {
|
||||
public interface OrdersRepository
|
||||
extends CrudRepository<Orders, Long> {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.example.springdemo.service;
|
||||
|
||||
import com.example.springdemo.entities.Orders;
|
||||
|
||||
public interface OrdersService {
|
||||
Orders addIndent(Orders orders);
|
||||
|
||||
void deleteIndentById(Long id);
|
||||
|
||||
Orders updateIndent(Orders orders);
|
||||
|
||||
Iterable<Orders> findAllIndents();
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.example.springdemo.service;
|
||||
|
||||
import com.example.springdemo.dao.OrdersRepository;
|
||||
import com.example.springdemo.entities.Orders;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class OrdersServiceImpl implements OrdersService {
|
||||
@Resource
|
||||
private OrdersRepository ordersRepository;
|
||||
|
||||
@Override
|
||||
public Orders addIndent(Orders orders) {
|
||||
return ordersRepository.save(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIndentById(Long id) {
|
||||
ordersRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Orders updateIndent(Orders orders) {
|
||||
return ordersRepository.save(orders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Orders> findAllIndents() {
|
||||
return ordersRepository.findAll();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user