MerchantsController Restful接口修改
This commit is contained in:
parent
8180141994
commit
b09082f30a
@ -3,12 +3,10 @@ package com.example.springdemo.controller;
|
||||
import com.example.springdemo.entities.Merchants;
|
||||
import com.example.springdemo.service.MerchantsService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/merchants")
|
||||
@ -16,34 +14,33 @@ public class MerchantsController {
|
||||
@Resource
|
||||
private MerchantsService merchantsService;
|
||||
|
||||
@GetMapping("/findAll")
|
||||
public List<Merchants> getMerchants() {
|
||||
return merchantsService.findAll();
|
||||
@PostMapping("/add")
|
||||
public Merchants saveMerchants(@RequestBody Merchants merchants) {
|
||||
return merchantsService.insetMerchants(merchants);
|
||||
}
|
||||
|
||||
@GetMapping("/findByName")
|
||||
public List<Merchants> getMerchantsByName(@RequestParam("name") String name) {
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public void deleteMerchants(@PathVariable("id") Long id) {
|
||||
merchantsService.deleteMerchantsById(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Merchants updateMerchants(@RequestBody Merchants merchants) {
|
||||
return merchantsService.updateMerchants(merchants);
|
||||
}
|
||||
|
||||
@GetMapping("/find")
|
||||
public List<Merchants> getMerchants() {
|
||||
return merchantsService.findAllMerchants();
|
||||
}
|
||||
|
||||
@GetMapping("/find/{name}")
|
||||
public Merchants getMerchantsByName(@PathVariable("name") String name) {
|
||||
return merchantsService.findByName(name);
|
||||
}
|
||||
|
||||
@GetMapping("/save")
|
||||
public String saveMerchants(@RequestParam("name") String name,
|
||||
@RequestParam("address") String address,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("phoneNumber") String phoneNumber) {
|
||||
|
||||
Merchants merchants = new Merchants();
|
||||
merchants.setName(name);
|
||||
merchants.setAddress(address);
|
||||
merchants.setDescription(description);
|
||||
merchants.setPhoneNumber(phoneNumber);
|
||||
merchantsService.save(merchants);
|
||||
return "success";
|
||||
}
|
||||
|
||||
@GetMapping("/delete")
|
||||
public String deleteMerchants(@RequestParam("id") Long id) {
|
||||
merchantsService.deleteById(id);
|
||||
return "success";
|
||||
@GetMapping("/find/{id}")
|
||||
public Optional<Merchants> getMerchantsById(@PathVariable("id") Long id) {
|
||||
return merchantsService.findById(id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user