订单类CRUD和Controller API

This commit is contained in:
myh 2023-11-07 23:46:24 +08:00
parent 8f1ee8896b
commit 872bb0e3e7
4 changed files with 81 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -1,10 +1,10 @@
package com.example.springdemo.dao; 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.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface IndentRepository public interface OrdersRepository
extends CrudRepository<Indent, Long> { extends CrudRepository<Orders, Long> {
} }

View File

@ -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();
}

View File

@ -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();
}
}