ich einen Frühling-Controller haben,Gibt es eine Möglichkeit zu wissen, welche vollständige URL der Spring Controller zuordnen wird?
@Controller
@RequestMapping(value = "/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* returns all the employees in the datastore.
*
* @return list of all employees.
*/
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody String getAllEmployees() {
return convertObjectListToJSONArray(this.employeeService.listEmployees());
}
/**
* adds an employee in the data-store.
*
* @param employee
* employee to add in the data-store.
* @return request status.
*/
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<?> addEmployee(UriComponentsBuilder uriCBuilder, @RequestBody Employee employee) {
Employee e = this.employeeService.getEmployeeById(employee.getId());
if(null != e) {
throw new EmployeeConflictException();
}
this.employeeService.addEmployee(employee);
UriComponents uriComponents = uriCBuilder.path("/cmpe281Pratik021/rest/employee/{id}")
.buildAndExpand(employee.getId());
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uriComponents.toUri());
return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}
Aber, wenn ich http://localhost:8080/employee getroffen gibt es einen Fehler 404. Gibt es einen Weg, um vollständige URL zu drucken, die in diesem Frühjahr Controller zugeordnet werden soll?
Es scheint, Ihr Kontext ist in der URL fehlt Sie schlagen. http: // localhost: 8080//Mitarbeiter –
Khuzi
Wie haben Sie diese Anwendung bereitgestellt? War es eine WAR-Datei? oder Frühlingsstiefel? Bei einem .war benötigen Sie auch den Kontextpfad (Name von .war). "http: // localhost: 8080//Mitarbeiter" –
shazin