我有一个springboot应用程序,当我从postman发布JSON时,我得到了null值。
Springboot文件:
`package com.learnspringboot.demo.controller;
import com.learnspringboot.demo.entity.Department;
import com.learnspringboot.demo.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class DepartmentController {
@Autowired
private DepartmentService departmentService;
@PostMapping("/departments")
public Department saveDepartment(@RequestBody Department department){
** System.out.println(department.toString());**
return departmentService.saveDepartment(department);
}
@GetMapping("/departments")
public List<Department> fetchDepartment(){
return departmentService.fetchDepartment();
}
@DeleteMapping("/departments/{Id}")
public String deleteDepartment(@PathVariable("Id") Long DepartmentId){
departmentService.deleteDepartment(DepartmentId);
return "Department Id: "+ DepartmentId +" Deleted Successfully";
}
}
`
字符串
Springboot console logs
Postman Request的
任何解决此问题的建议将受到高度赞赏。
我试着用实际的IP替换它,但它不起作用。
1条答案
按热度按时间1tuwyuhd1#
您在Postman中发送的JSON对象需要与您Map到的Java对象匹配。在您的情况下,它将是
Department
对象。看起来您正在发送以开头的字段,这导致了问题。试着在 Postman 上发送下面的内容(注意字段是 Camel 大小写)
字符串