bug fix: Ambiguous handler methods mapped for 'xxx'; Double @RequestBody param accept

This commit is contained in:
myh 2023-11-12 19:34:54 +08:00
parent 587ac7bb45
commit 1f8754ef4c
6 changed files with 71 additions and 55 deletions

View File

@ -4,6 +4,7 @@ import com.example.springdemo.entities.Merchants;
import com.example.springdemo.entities.password.MerchantsPassword;
import com.example.springdemo.service.MerchantsService;
import jakarta.annotation.Resource;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@ -15,13 +16,20 @@ public class MerchantsController {
private MerchantsService merchantsService;
@PostMapping("/add")
public Merchants addMerchants(@RequestBody Merchants merchant,
@RequestBody MerchantsPassword merchantPassword) {
return merchantsService.addMerchant(merchant, merchantPassword);
public Merchants addMerchants(@RequestBody wrapperMerchantAndPassword wrapperMerchantAndPassword) {
return merchantsService.addMerchant(
wrapperMerchantAndPassword.merchant,
wrapperMerchantAndPassword.merchantPassword);
}
@DeleteMapping("/delete/{id}")
public void deleteMerchants(@PathVariable("id") Long merchantId) {
@Data
public static class wrapperMerchantAndPassword {
public Merchants merchant;
public MerchantsPassword merchantPassword;
}
@DeleteMapping("/delete/id")
public void deleteMerchants(@RequestParam("id") Long merchantId) {
merchantsService.deleteMerchantById(merchantId);
}
@ -30,23 +38,23 @@ public class MerchantsController {
return merchantsService.updateMerchant(merchant);
}
@GetMapping("/find")
@GetMapping("/find/all")
public Iterable<Merchants> getMerchants() {
return merchantsService.findAllMerchants();
}
@GetMapping("/find/{name}")
public Optional<Merchants> getMerchantsByName(@PathVariable("name") String name) {
@GetMapping("/find/name}")
public Optional<Merchants> getMerchantsByName(@RequestParam("name") String name) {
return merchantsService.findByName(name);
}
@GetMapping("/find/{id}")
public Optional<Merchants> getMerchantsById(@PathVariable("id") Long merchantId) {
@GetMapping("/find/id")
public Optional<Merchants> getMerchantsById(@RequestParam("id") Long merchantId) {
return merchantsService.findById(merchantId);
}
@PutMapping("/update/password")
public int updatePassword(@RequestParam String password, @RequestParam Long merchantId) {
public int updatePassword(@RequestParam("password") String password, @RequestParam("merchantId") Long merchantId) {
return merchantsService.updateMerchantPasswordById(password, merchantId);
}
}

View File

@ -6,28 +6,28 @@ import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/indent")
@RequestMapping("/orders")
public class OrdersController {
@Resource
private OrdersService ordersService;
@PostMapping("/add")
public Orders addIndent(@RequestBody Orders orders) {
return ordersService.addIndent(orders);
return ordersService.addOrder(orders);
}
@DeleteMapping("/delete/{id}")
public void deleteIndent(@PathVariable Long id) {
ordersService.deleteIndentById(id);
@DeleteMapping("/delete/id")
public void deleteOrderById(@RequestParam("id") Long id) {
ordersService.deleteOrderById(id);
}
@PutMapping("/update")
public Orders updateIndent(@RequestBody Orders orders) {
return ordersService.updateIndent(orders);
public Orders updateOrder(@RequestBody Orders orders) {
return ordersService.updateOrder(orders);
}
@GetMapping("/find")
public Iterable<Orders> getIndent() {
return ordersService.findAllIndents();
@GetMapping("/find/all")
public Iterable<Orders> getAllOrders() {
return ordersService.findAllOrders();
}
}

View File

@ -21,8 +21,8 @@ public class PermissionsController {
return permissionsService.addPermission(permission);
}
@DeleteMapping("/delete/{id}")
public void deletePermissions(@PathVariable("id") Long permissionId) {
@DeleteMapping("/delete/id")
public void deletePermissions(@RequestParam("id") Long permissionId) {
permissionsService.deletePermissionById(permissionId);
}
@ -31,13 +31,13 @@ public class PermissionsController {
return permissionsService.updatePermission(permission);
}
@GetMapping("/find")
@GetMapping("/find/all")
public List<Permissions> getPermissions() {
return permissionsService.findAllPermissions();
}
@GetMapping("/find/{permissionsId}")
public Optional<Permissions> getPermissionsById(@PathVariable Long permissionsId) {
@GetMapping("/find/id")
public Optional<Permissions> getPermissionsById(@RequestParam("id") Long permissionsId) {
return permissionsService.findById(permissionsId);
}
}

View File

@ -21,8 +21,8 @@ public class RolesController {
return rolesService.createRole(role);
}
@DeleteMapping("/delete/{id}")
public void deleteRole(@PathVariable("id") Long roleId) {
@DeleteMapping("/delete/id")
public void deleteRole(@RequestParam("id") Long roleId) {
rolesService.deleteRoleById(roleId);
}
@ -31,18 +31,18 @@ public class RolesController {
return rolesService.updateRole(role);
}
@GetMapping("/find")
@GetMapping("/find/all")
public List<Roles> getAllRoles() {
return rolesService.findAllRoles();
}
@GetMapping("/find/{roleId}")
public Optional<Roles> getRolesById(@PathVariable Long roleId) {
@GetMapping("/find/id")
public Optional<Roles> getRolesById(@RequestParam("id") Long roleId) {
return rolesService.findById(roleId);
}
@GetMapping("/find/{roleName}")
public Optional<Roles> getRolesByName(@PathVariable String roleName) {
@GetMapping("/find/name")
public Optional<Roles> getRolesByName(@RequestParam("name") String roleName) {
return rolesService.findByName(roleName);
}
}

View File

@ -41,13 +41,13 @@ public class RolesPermissionsController {
}
}
@GetMapping("/find")
@GetMapping("/find/all")
public List<RolesPermissions> findAllRolesPermissions() {
return rolesPermissionsService.findAllRolesPermissions();
}
@GetMapping("/find/{rolesPermissionsId}")
public Optional<RolesPermissions> getRolePermissionById(@PathVariable(name = "rolesPermissionsId") Long rolesPermissionsId) {
@GetMapping("/find/id")
public Optional<RolesPermissions> getRolePermissionById(@RequestParam(name = "id") Long rolesPermissionsId) {
return rolesPermissionsService.findById(rolesPermissionsId);
}

View File

@ -5,6 +5,7 @@ import com.example.springdemo.entities.password.UsersPassword;
import com.example.springdemo.service.UsersService;
import com.example.springdemo.utils.RoleVerificationAnnotation;
import jakarta.annotation.Resource;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -18,24 +19,31 @@ public class UsersController {
private UsersService usersService;
//添加新用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@RoleVerificationAnnotation(UserIDList = {1})
@PostMapping("/add")
public Users addUsers(@RequestBody UsersPassword userPassword,
@RequestBody Users user) {
return usersService.addUser(user, userPassword);
public Users addUsers(@RequestBody wrapperUserAndPassword wrapperUserAndPassword) {
return usersService.addUser(
wrapperUserAndPassword.user,
wrapperUserAndPassword.userPassword);
}
@Data
public static class wrapperUserAndPassword {
public Users user;
public UsersPassword userPassword;
}
//通过ID删除用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@DeleteMapping("/delete/{id}")
public void deleteUserById(@PathVariable(name = "id") Long userId) {
@RoleVerificationAnnotation(UserIDList = {1})
@DeleteMapping("/delete/id")
public void deleteUserById(@RequestParam(name = "id") Long userId) {
usersService.deleteUserById(userId);
}
//通过姓名删除用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@DeleteMapping("/delete/{name}")
public void deleteUserByName(@PathVariable(name = "name") String name) {
@RoleVerificationAnnotation(UserIDList = {1})
@DeleteMapping("/delete/name")
public void deleteUserByName(@RequestParam(name = "name") String name) {
usersService.deleteUserByName(name);
}
@ -47,23 +55,23 @@ public class UsersController {
}
//查找全部用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@GetMapping("/find")
@RoleVerificationAnnotation(UserIDList = {1})
@GetMapping("/find/all")
public List<Users> getUsers() {
return usersService.findAllUsers();
}
//根据姓名查找用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@GetMapping("/find/{name}")
public Optional<Users> getUsersByName(@PathVariable(name = "name") String name) {
@RoleVerificationAnnotation(UserIDList = {1})
@GetMapping("/find/name")
public Optional<Users> getUsersByName(@RequestParam(name = "name") String name) {
return usersService.findByName(name);
}
//根据ID查找用户
@RoleVerificationAnnotation(RoleIDList = {1}, UserIDList = {1})
@GetMapping("/find/{id}")
public Optional<Users> getUsersById(@PathVariable(name = "id") Long userId) {
@RoleVerificationAnnotation(UserIDList = {1})
@GetMapping("/find/id")
public Optional<Users> getUsersById(@RequestParam(name = "id") Long userId) {
return usersService.findById(userId);
}