我是新的春季MVC。我运行了一个api,但显示错误。
我正在使用Tomcat 8.5服务器
import org.apache.log4j.Logger;
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.apex.dto.MmsuserDto;
import com.apex.manager.ApexManager;
import com.apex.mapper.MmsuserDtoToMmsuserModelMapper;
import com.apex.model.MmsuserModel;
import com.apex.util.ApexResponse;
@RestController
public class ApexApi extends AbstractApi {
private static final Logger LOG = Logger.getLogger(ApexApi.class);
@Autowired
private ApexManager apexManager;
@RequestMapping(value = "/sample", method = RequestMethod.GET)
public String welcome() {
return "Welcome to Apex RestTemplate Example.";
}
@RequestMapping(value = "/authenticate", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE, headers="Content-Type=application/json")
public ResponseEntity<MmsuserModel> authenticate(@RequestBody MmsuserModel model) {
final MmsuserDto dto = apexManager.authenticateMmsuser(model.getUserid(), model.getPwd());
final MmsuserModel mmsuserModel = MmsuserDtoToMmsuserModelMapper.INSTANCE.toModel(dto);
LOGGED_IN_USER_MAP.put(mmsuserModel.getToken(), mmsuserModel);
LOG.info("successfully authenticated");
return new ResponseEntity<MmsuserModel>(mmsuserModel, HttpStatus.OK);
}
@RequestMapping(value = "/logout", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ApexResponse> logout(@RequestHeader(value = "Authorization") String token) {
ApexResponse response = new ApexResponse();
response.setCode(HttpStatus.OK.value());
response.setMessage(apexManager.logout(token));
return new ResponseEntity<ApexResponse>(response, HttpStatus.OK);
}
}
它应该运行以显示有意义的结果,但不幸的是它显示
''' HTTP状态415-
类型状态报告
消息
描述服务器拒绝了此请求,因为请求实体的格式不受请求的方法所请求的资源支持。 '''