angularjs将json发布到spring

时间:2014-08-22 10:52:29

标签: json angularjs spring

400 Bad Request 角js json到spring mvc

我使用angular js

创建登录页面模块

它从角到春天转到json格式

运行400错误请求时如何接收代码错误

myjsp代码:

  <div id="showProjects" ng-controller="crescentGetProjects">

    <table>

    <tr><td>User Name</td><td><input type="text" id="pname" name="pname" ng-model="project.UserName"></td></tr>
    <tr><td>Password</td><td><input type="text" id="aname" name="aname" ng-model="project.Password"></td></tr>
    <tr><td><input type="hidden" ng-model="project.projectId" /></td>
    <td><input type="button" value="Save" ng-click="saveProjectDetails(project)"></td></tr>

    </table>
    </div>

我的js代码:

function crescentGetProjects($scope,$http){
    $scope.saveProjectDetails = function(project)
    {

            console.log(project);
            var dataObj = {
                    UserName : $scope.project.UserName,
                    Password : $scope.project.Password

            };
        var res=$http.post('research/api/register',dataObj);
        res.success(function(data, status, headers, config) {
            $scope.message = data;
            alert("success");
        });
        res.error(function(data, status, headers, config) {
            alert("failure");


        });

控制器代码

@RequestMapping(value = "/register", method = RequestMethod.POST,consumes="application/json")
public @ResponseBody String registerUser(@RequestBody LoginEntity userModel,HttpServletRequest request) {
    String resp=null;
    try{
        System.out.println("$$$$$$$$$$ "+userModel.getUserName());
    crescentManager.LoginCheck(userModel);
    resp="success";
    }catch(Exception e){
        resp="fail";
        System.out.println(e);
    }
    return resp;

}

我的实体类是

@Entity
@Table(name="LOGININFO")
public class LoginEntity {
    @Id
    @Column(name="LOGINID")
    @GeneratedValue
    private Integer LoginId;

    @Column(name="USERNAME")
    private String UserName;

    @Column(name="PASSWORD")
    private String Password;

    public Integer getLoginId() {
        return LoginId;
    }

    public void setLoginId(Integer loginId) {
        LoginId = loginId;
    }

    public String getUserName() {

        return UserName;
    }

    public void setUserName(String userName) {
        UserName = userName;
        System.out.println("@@@@@@@@@@@@@@@username is settled in entity   "+userName);
    }

    public String getPassword() {
        return Password;
    }

    public void setPassword(String password) {
        Password = password;
    }


}
错误的消息 400 糟糕的要求

0 个答案:

没有答案