在Java Maven springboot项目中不能使用“ response.setService / .setMesage / .setData”

问题描述 投票:0回答:1

我尝试使用springboot构建API,当我制作控制器并使用response.response.setService / .setMesage / .setData时出现错误“方法Response类型的setService(String)未定义”,请帮助我解决这个问题。

package com.example.restapi.controller;

import com.example.restapi.entity.Hardware;
import com.example.restapi.service.HardwareService;
import com.example.restapi.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "hardware")
public class HardwareController {

    @Autowired
    HardwareService hardwareService;

    private String serviceString = "Hardware";

    ResponseEntity<Response> create (@RequestBody @Validated Hardware hardware)
    {
        String nameofCurrMethod = new Throwable()
                .getStackTrace()[0]
                .getMethodName();

        Response response = new Response();
        response.setService(this.getClass().getName() + nameofCurrMethod); <==This is error code
        response.setMessage("Berhasil Membuat Data");                      <==This is error code


        response.setData(hardwareService.create(hardware));                <==This is error code

        return  ResponseEntity
                .status(HttpStatus.OK)
                .contentType(MediaType.APPLICATION_JSON)
                .body(response);
    }

}
java eclipse rest spring-boot maven
1个回答
0
投票

您使用eclipse的lombok,也许lombok安装不正确。在这里查看详细信息link

© www.soinside.com 2019 - 2024. All rights reserved.