Ich möchte eine Zugabe (Operation a + b = c) mit JavaRest, Methode GET mit 2 Doppelparameter und AngularJS, um die generierte Ressource zu bekommen, aber ich blockierte immer noch.
hier ist der Code:
//CalculatorResource.java
@Path("calco")
public class CalculeteResource {
double result;
@GET
@Path("/addition/{a}/{b}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAddition(@PathParam("a") double a, @PathParam("b") double b) {
Calculete calco = new Calculete();
calco.setA(a);
calco.setB(b);
result = calco.getA() + calco.getB();
calco.setC(result);
return Response.ok(calco).build();
}
// succesfull Test auf dem Server unter Verwendung von http:
http://localhost:8380/dadem-calculator/rest/calco/addition/5/5
und erzeugte Objekt ist, a + b = c (5 + 5 = 10
){"a":5.0,"b":5.0,"c":10.0}
und hier das Problem: die AngularJS-Controller mit GET + 2 Param:
var app = angular.module("CalculatorManagement", []);
//Controller
app.controller("CalculatorController", function($scope, $http) {
$scope.result;
$scope.operation={
a : 0,
b : 0,
c : 0
};
//HTTP GET- get all users collection
function _refreshUserData() {
$http({
method : 'GET',
url : 'http://localhost:8380/dadem-calculator/rest/calco/addition/' + operation.a + '/' + operation.b
}).then(function successCallback(response) {
$scope.result = response.data;
}, function errorCallback(response) {
console.log(response.statusText);
});
};
});
html mit ng-Modell:
<td><input type="number" ng-model="operation.a"></td>
<td><input type="number" ng-model="operation.b"></td>
<td> {{ result.c }} </td>
</tr>
Es ist ein Tippfehler in Ihrem http get: + Operation ‚/‘, die Sie vermissen ein ‚+ ". Es sollte + operation.a + '/' sein –
erhalten Sie irgendeinen Fehler in der Konsole? – Aravind
Was sehen Sie auf der Registerkarte Netzwerk Ihrer Developer Tools? – NicolasMoise