使用注解@RequestBody变红的解决问题
解决办法:
package com.takeout.controller;
import com.takeout.common.R;
import com.takeout.entity.Employee;
import com.takeout.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 这个注解是jsr规范提供,不属于spring
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
//@Autowired // 不推荐使用这个注解,spring官方推荐使用构造注入
// 此外,如果不适用构造注入,推荐使用 @Resource注解代替
@Resource
private EmployeeService employeeService;
// 原因是项目在启动时能够确保你的依赖被正确加载,而不是等到请求访问后
// 才发现依赖不存在报错,属于一种快速失败策略
// @Autowired
// public EmployeeController(EmployeeService employeeService){
// this.employeeService = employeeService;
// }
/**
* 员工登录
*/
@PostMapping("/login")
public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
return null;
}
}
成功解决截图如下: