50 lines
1.6 KiB
Java
50 lines
1.6 KiB
Java
![]() |
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 java.util.List;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("/merchants")
|
||
|
public class MerchantsController {
|
||
|
@Resource
|
||
|
private MerchantsService merchantsService;
|
||
|
|
||
|
@GetMapping("/findAll")
|
||
|
public List<Merchants> getMerchants() {
|
||
|
return merchantsService.findAll();
|
||
|
}
|
||
|
|
||
|
@GetMapping("/findByName")
|
||
|
public List<Merchants> getMerchantsByName(@RequestParam("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";
|
||
|
}
|
||
|
}
|