Mysql JavaSpring4.0响应状态代码为200,但执行(错误登录)响应的错误块

Mysql JavaSpring4.0响应状态代码为200,但执行(错误登录)响应的错误块,mysql,angularjs,hibernate,maven,spring-mvc,Mysql,Angularjs,Hibernate,Maven,Spring Mvc,Angular js-1(loginCtrl):Angular不反映spring响应,我不明白可能是什么问题……请您帮忙,顺便说一下,我是Angular和spring RestFul ws的新手 app.controller('loginCtrl', function($scope,$http,$window){ $scope.login = function(email,password) { var myData = {

Angular js-1(loginCtrl):Angular不反映spring响应,我不明白可能是什么问题……请您帮忙,顺便说一下,我是Angular和spring RestFul ws的新手

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);


            });
        };                                                                                                       
       });
JavaSpring4.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);
    }
}
/*
*要更改此许可证标题,请在“项目属性”中选择“许可证标题”。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
包com.product.Controller;
导入com.product.Exceptions.CustomerNotFoundException;
导入com.product.Services.CustomerServices;
导入com.product.product.Customer;
导入com.fasterxml.jackson.databind.JsonNode;
导入com.fasterxml.jackson.databind.ObjectMapper;
导入java.io.IOException;
导入java.io.Serializable;
导入java.util.List;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.http.HttpStatus;
导入org.springframework.http.ResponseEntity;
导入org.springframework.security.crypto.bcrypt.bcrypt;
导入org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.RequestBody;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RestController;
导入org.springframework.web.servlet.ModelAndView;
/*
*
*@author HP
*/
@RestController
@请求映射(“/customer”)
公共类客户控制器{
/////////成员////////////////////////////////////////////////////////////////////////////////////
私有静态最终记录器Logger=LoggerFactory.getLogger(CustomerController.class)//
@自动连线//
私人客户服务;
专用BCryptPasswordEncoder pe//
///////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(value=”“,method=RequestMethod.PUT)
public ResponseEntity createCustomer(@RequestBody String json)引发CustomerNotFoundException
{
试一试{
ObjectMapper mapper=新的ObjectMapper();
final JsonNode data=mapper.readTree(json);
info(“接收到的json字符串”+json);
字符串email=data.get(“email”).asText();
字符串密码=data.get(“密码”).asText();
String firstname=data.get(“firstname”).asText();
字符串姓氏=data.get(“姓氏”).asText();
//brypt散列
字符串pw_hash=BCrypt.hashpw(密码,BCrypt.gensalt(10));
客户c=新客户(名字、姓氏、电子邮件、pw_哈希);
///////创建客户/////////
服务。客户(c);
///如果尝试成功,则返回
//loginService.createLogin(u);
返回新的ResponseEntity(HttpStatus.CREATED);
}捕获(IOEX异常){
抛出新的运行时异常(ex);
}
}
@RequestMapping(value=”“,method=RequestMethod.POST)
public ResponseEntity LogincCustomer(@RequestBody String json)引发CustomerNotFoundException
{
试一试{
ObjectMapper mapper=新的ObjectMapper();
final JsonNode data=mapper.readTree(json);
字符串email=data.get(“email”).asText();
字符串密码=data.get(“密码”).asText();
if(services.findByName(email)!=null和&services.findByPw(密码)!=null){
info(“在:json字符串“+json”中收到了正确的用户详细信息);
System.out.println(“Successfull!!”;
返回新的响应状态(HttpStatus.OK);
}否则{
System.out.println(“错误!!”);
返回新的响应属性(HttpStatus.BAD_请求);
}
}捕获(IOEX异常){
抛出新的运行时异常(ex);
}
}
@RequestMapping(value=”“,method=RequestMethod.GET)
公共响应getAllCustomers(){
List customerList=services.getCustomerList();
如果(customerList!=null){
返回新的响应属性(customerList,HttpStatus.OK);
}否则{
返回新的响应属性(HttpStatus.BAD_请求);
}
}
@RequestMapping(value=“/{id}”,method=RequestMethod.DELETE)
public ResponseEntity Delete(@PathVariable long id)引发CustomerNotFoundException{
服务。删除客户(id);
返回新的响应属性(HttpStatus.BAD_请求);
}
}

在控制器类之前使用以下注释:

@RestController
@RequestMapping("/login")
课前使用

@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
    public ResponseEntity save(@RequestBody LoginView loginView) {


}
LoginView
是一个类,它包含用于JSON及其setter-getter方法的相同变量

package com.test;



public class LoginView  {


private String email;

private String password;

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

}

感谢你们的时间,你们这些浏览我的帖子的人,这篇帖子是清晰的,因为我能够解决这个问题,最终的问题是,即使url不存在,状态代码总是求助于200,我阻止了默认和在客户端的传播,阻止了请求被取消。。。希望这能帮助一些人,顺便说一句,这是我的第一个Restful应用程序…我是世界上最快乐的人…;)

你得到了什么回应?