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

View File

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

View File

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

View File

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

View File

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