enter image description here角度js-1(loginCtrl):角度不反映彈簧響應,我不明白可能是什麼問題......可以請你協助,順便是新的角度和春季的RESTful-WSJava Spring 4.0響應狀態碼200,但角度Js執行(錯誤登錄)響應的錯誤塊
app.controller('loginCtrl', function($scope,$http,$window){
$scope.login = function(email,password) {
var myData = {
email: $scope.email,
password: $scope.password
};
$http.post(customerURL,JSON.stringify(myData)).then(function(response){
if(response.data)
console.log(response.data);
$scope.msg = "SUCCESSFULLY LOGGED IN";
$scope.status = response.status;
$scope.statusText = response.statusText;
console.log($scope.msg);
},function(response){
//console.log(response.status);
$scope.msg = "ERROR LOGIN IN";
console.log($scope.msg);
});
};
});
Java的春季4.0:找到電子郵件和散列密碼正確(使用checkpw)...
@RequestMapping(value="",method = RequestMethod.POST)
public ResponseEntity LoginCustomer(@RequestBody String json) throws CustomerNotFoundException
{
try {
ObjectMapper mapper = new ObjectMapper();
final JsonNode data = mapper.readTree(json);
String email = data.get("email").asText();
String password = data.get("password").asText();
if(services.findByName(email) != null && services.findByPw(password) != null){
logger.info("received correct user details in :json String " + json);
System.out.println("Successfull!!");
return new ResponseEntity(HttpStatus.OK);
}else{
System.out.println("Error!!");
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
} catch (IOException ex){
throw new RuntimeException(ex);
}
}
我現在的客戶控制器...
控制器類之前/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.product.Controller;
import com.product.Exceptions.CustomerNotFoundException;
import com.product.Services.CustomerServices;
import com.product.Product.Customer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/*
*
* @author HP
*/
@RestController
@RequestMapping("/customer")
public class CustomerController{
/////////members ////////////////////////////////////////////////////////////////////////////////////
private static final Logger logger = LoggerFactory.getLogger(CustomerController.class); //
@Autowired //
private CustomerServices services;
private BCryptPasswordEncoder pe;//
///////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(value="",method = RequestMethod.PUT)
public ResponseEntity createCustomer(@RequestBody String json) throws CustomerNotFoundException
{
try {
ObjectMapper mapper = new ObjectMapper();
final JsonNode data = mapper.readTree(json);
logger.info("recived json String " + json);
String email = data.get("email").asText();
String password = data.get("password").asText();
String firstname = data.get("firstname").asText();
String surname = data.get("surname").asText();
//brypt hashing
String pw_hash = BCrypt.hashpw(password,BCrypt.gensalt(10));
Customer c = new Customer(firstname, surname, email, pw_hash);
///////create customer /////////
services.createCustomer(c);
///return if try was succesful
//loginService.createLogin(u);
return new ResponseEntity(HttpStatus.CREATED);
} catch (IOException ex){
throw new RuntimeException(ex);
}
}
@RequestMapping(value="",method = RequestMethod.POST)
public ResponseEntity LoginCustomer(@RequestBody String json) throws CustomerNotFoundException
{
try {
ObjectMapper mapper = new ObjectMapper();
final JsonNode data = mapper.readTree(json);
String email = data.get("email").asText();
String password = data.get("password").asText();
if(services.findByName(email) != null && services.findByPw(password) != null){
logger.info("received correct user details in :json String " + json);
System.out.println("Successfull!!");
return new ResponseEntity(HttpStatus.OK);
}else{
System.out.println("Error!!");
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
} catch (IOException ex){
throw new RuntimeException(ex);
}
}
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<List<Customer>> getAllCustomers() {
List<Customer> customerList = services.getCustomerList();
if(customerList != null) {
return new ResponseEntity<>(customerList, HttpStatus.OK);
}else{
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<CustomerController> Delete(@PathVariable long id) throws CustomerNotFoundException {
services.DeleteCustomer(id);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
你得到了什麼迴應? –