Store null values in database while trying to save data using spring mvc angular js
angular js code
<body data-ng-app="myApp" data-ng-controller="UserController as userBean">
<form method="post" action="register" name="myForm">
<div class="form-group col-lg-7" >
<label for="username" class="control-label">First Name:</label>
<input type="text" data-ng-model="userBean.username" class="form-control" placeholder="Enter Firstname"/><br>
<label for="phone" class="control-label">Phone:</label>
<input type="text" data-ng-model="userBean.phone" class="form-control" placeholder="Enter phone no."/><br>
<label for="email" class="control-label">Email:</label>
<input type="text" data-ng-model="userBean.email" class="form-control" placeholder="Enter email"/><br>
<label for="address" class="control-label">Address:</label>
<input type="text" data-ng-model="userBean.address" class="form-control" placeholder="Enter address"/><br>
<label for="password" class="control-label">Password:</label>
<input type="password" data-ng-model="userBean.password" class="form-control" placeholder="Enter password"/><br>
</div>
<div class="form-group col-lg-7">
<button type="submit" data-ng-click="insertData()" class="btn btn-primary">Submit</button>
</div>
</form>
<script type="text/javascript">
var app = angular.module('myApp', );
app.controller("UserController", ['$scope', '$http', function($scope, $http, httpPostService)
var self=this;
$scope.insertData = function()
alert($scope.userBean.username, $scope.userBean.phone, $scope.userBean.email);
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password
).then(function(response)
console.log(response.status);
console.log("in success");
, function(response)
console.log(response.status);
console.log("in fail");
);
;
]);
</script>
controller code
@RequestMapping(value="/register", method = RequestMethod.POST, consumes="application/json")
public @ResponseBody ModelAndView doRegister(@ModelAttribute @RequestBody UserBean userBean, BindingResult result)
if(!result.hasFieldErrors())
if(retrieveService.insert(userBean) != null)
System.out.println("done");
return new ModelAndView("redirect:/welcome");
}
I think a controller problem. userBean has null values to pass it to a controller. so kindly anyone helps me
It error also came
HTTP Status 415 – Unsupported Media Type The origin server is refusing to service the request because the payload is in a format not
supported by this method on the target resource.
mysql angularjs spring spring-mvc
add a comment |
angular js code
<body data-ng-app="myApp" data-ng-controller="UserController as userBean">
<form method="post" action="register" name="myForm">
<div class="form-group col-lg-7" >
<label for="username" class="control-label">First Name:</label>
<input type="text" data-ng-model="userBean.username" class="form-control" placeholder="Enter Firstname"/><br>
<label for="phone" class="control-label">Phone:</label>
<input type="text" data-ng-model="userBean.phone" class="form-control" placeholder="Enter phone no."/><br>
<label for="email" class="control-label">Email:</label>
<input type="text" data-ng-model="userBean.email" class="form-control" placeholder="Enter email"/><br>
<label for="address" class="control-label">Address:</label>
<input type="text" data-ng-model="userBean.address" class="form-control" placeholder="Enter address"/><br>
<label for="password" class="control-label">Password:</label>
<input type="password" data-ng-model="userBean.password" class="form-control" placeholder="Enter password"/><br>
</div>
<div class="form-group col-lg-7">
<button type="submit" data-ng-click="insertData()" class="btn btn-primary">Submit</button>
</div>
</form>
<script type="text/javascript">
var app = angular.module('myApp', );
app.controller("UserController", ['$scope', '$http', function($scope, $http, httpPostService)
var self=this;
$scope.insertData = function()
alert($scope.userBean.username, $scope.userBean.phone, $scope.userBean.email);
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password
).then(function(response)
console.log(response.status);
console.log("in success");
, function(response)
console.log(response.status);
console.log("in fail");
);
;
]);
</script>
controller code
@RequestMapping(value="/register", method = RequestMethod.POST, consumes="application/json")
public @ResponseBody ModelAndView doRegister(@ModelAttribute @RequestBody UserBean userBean, BindingResult result)
if(!result.hasFieldErrors())
if(retrieveService.insert(userBean) != null)
System.out.println("done");
return new ModelAndView("redirect:/welcome");
}
I think a controller problem. userBean has null values to pass it to a controller. so kindly anyone helps me
It error also came
HTTP Status 415 – Unsupported Media Type The origin server is refusing to service the request because the payload is in a format not
supported by this method on the target resource.
mysql angularjs spring spring-mvc
add a comment |
angular js code
<body data-ng-app="myApp" data-ng-controller="UserController as userBean">
<form method="post" action="register" name="myForm">
<div class="form-group col-lg-7" >
<label for="username" class="control-label">First Name:</label>
<input type="text" data-ng-model="userBean.username" class="form-control" placeholder="Enter Firstname"/><br>
<label for="phone" class="control-label">Phone:</label>
<input type="text" data-ng-model="userBean.phone" class="form-control" placeholder="Enter phone no."/><br>
<label for="email" class="control-label">Email:</label>
<input type="text" data-ng-model="userBean.email" class="form-control" placeholder="Enter email"/><br>
<label for="address" class="control-label">Address:</label>
<input type="text" data-ng-model="userBean.address" class="form-control" placeholder="Enter address"/><br>
<label for="password" class="control-label">Password:</label>
<input type="password" data-ng-model="userBean.password" class="form-control" placeholder="Enter password"/><br>
</div>
<div class="form-group col-lg-7">
<button type="submit" data-ng-click="insertData()" class="btn btn-primary">Submit</button>
</div>
</form>
<script type="text/javascript">
var app = angular.module('myApp', );
app.controller("UserController", ['$scope', '$http', function($scope, $http, httpPostService)
var self=this;
$scope.insertData = function()
alert($scope.userBean.username, $scope.userBean.phone, $scope.userBean.email);
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password
).then(function(response)
console.log(response.status);
console.log("in success");
, function(response)
console.log(response.status);
console.log("in fail");
);
;
]);
</script>
controller code
@RequestMapping(value="/register", method = RequestMethod.POST, consumes="application/json")
public @ResponseBody ModelAndView doRegister(@ModelAttribute @RequestBody UserBean userBean, BindingResult result)
if(!result.hasFieldErrors())
if(retrieveService.insert(userBean) != null)
System.out.println("done");
return new ModelAndView("redirect:/welcome");
}
I think a controller problem. userBean has null values to pass it to a controller. so kindly anyone helps me
It error also came
HTTP Status 415 – Unsupported Media Type The origin server is refusing to service the request because the payload is in a format not
supported by this method on the target resource.
mysql angularjs spring spring-mvc
angular js code
<body data-ng-app="myApp" data-ng-controller="UserController as userBean">
<form method="post" action="register" name="myForm">
<div class="form-group col-lg-7" >
<label for="username" class="control-label">First Name:</label>
<input type="text" data-ng-model="userBean.username" class="form-control" placeholder="Enter Firstname"/><br>
<label for="phone" class="control-label">Phone:</label>
<input type="text" data-ng-model="userBean.phone" class="form-control" placeholder="Enter phone no."/><br>
<label for="email" class="control-label">Email:</label>
<input type="text" data-ng-model="userBean.email" class="form-control" placeholder="Enter email"/><br>
<label for="address" class="control-label">Address:</label>
<input type="text" data-ng-model="userBean.address" class="form-control" placeholder="Enter address"/><br>
<label for="password" class="control-label">Password:</label>
<input type="password" data-ng-model="userBean.password" class="form-control" placeholder="Enter password"/><br>
</div>
<div class="form-group col-lg-7">
<button type="submit" data-ng-click="insertData()" class="btn btn-primary">Submit</button>
</div>
</form>
<script type="text/javascript">
var app = angular.module('myApp', );
app.controller("UserController", ['$scope', '$http', function($scope, $http, httpPostService)
var self=this;
$scope.insertData = function()
alert($scope.userBean.username, $scope.userBean.phone, $scope.userBean.email);
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password
).then(function(response)
console.log(response.status);
console.log("in success");
, function(response)
console.log(response.status);
console.log("in fail");
);
;
]);
</script>
controller code
@RequestMapping(value="/register", method = RequestMethod.POST, consumes="application/json")
public @ResponseBody ModelAndView doRegister(@ModelAttribute @RequestBody UserBean userBean, BindingResult result)
if(!result.hasFieldErrors())
if(retrieveService.insert(userBean) != null)
System.out.println("done");
return new ModelAndView("redirect:/welcome");
}
I think a controller problem. userBean has null values to pass it to a controller. so kindly anyone helps me
It error also came
HTTP Status 415 – Unsupported Media Type The origin server is refusing to service the request because the payload is in a format not
supported by this method on the target resource.
mysql angularjs spring spring-mvc
mysql angularjs spring spring-mvc
edited Nov 12 at 5:14
Amin Mozhgani
6041520
6041520
asked Nov 12 at 5:12
Vignesh_E
386
386
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Set content type JSON in your request headers like below.
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password,
headers: 'Content-Type': 'application/json'
)
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
add a comment |
Use @JsonIgnore on the field which can have null values.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256258%2fstore-null-values-in-database-while-trying-to-save-data-using-spring-mvc-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Set content type JSON in your request headers like below.
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password,
headers: 'Content-Type': 'application/json'
)
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
add a comment |
Set content type JSON in your request headers like below.
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password,
headers: 'Content-Type': 'application/json'
)
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
add a comment |
Set content type JSON in your request headers like below.
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password,
headers: 'Content-Type': 'application/json'
)
Set content type JSON in your request headers like below.
$http(
method: "POST",
url: "register",
data:
username: $scope.userBean.username,
phone: $scope.userBean.phone,
email: $scope.userBean.email,
address: $scope.userBean.address,
password: $scope.userBean.password,
headers: 'Content-Type': 'application/json'
)
answered Nov 12 at 5:17
Alien
4,69331024
4,69331024
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
add a comment |
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
Bro Its not working
– Vignesh_E
Nov 12 at 5:27
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
In console shows error like this Failed to load resource: the server responded with a status of 415 ()
– Vignesh_E
Nov 12 at 5:30
add a comment |
Use @JsonIgnore on the field which can have null values.
add a comment |
Use @JsonIgnore on the field which can have null values.
add a comment |
Use @JsonIgnore on the field which can have null values.
Use @JsonIgnore on the field which can have null values.
answered Nov 12 at 6:08
Sanchi Girotra
32228
32228
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256258%2fstore-null-values-in-database-while-trying-to-save-data-using-spring-mvc-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown