我有一个 javaEE 应用程序,我有一个 jquery 表单来将用户添加到数据库。我将 fiekd 值发送到我的 Spring 控制器,但由于某种原因没有发送数据。问题是什么?
我在日志中收到以下异常
java.lang.IllegalStateException: Could not find @PathVariable [login] in @RequestMapping
形式
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form:form action="${pageContext.request.contextPath}/test" method="post">
<fieldset>
<label for="login">Login</label>
<input type="text" name="login" id="login" class="text ui-widget-content ui-corner-all" />
<label for="password">Password</label>
<input type="text" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form:form>
</div>
<button id="create-user">Add user</button>
脚本
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 600,
width: 350,
modal: true,
buttons: {
"Create an account": function() {
var login = $( '#login' );
var email = $( '#email' );
var password = $( '#password' );
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}/test",
data: "login=" + login + "&email=" + email + "&password="+ password,
success: function(){
$( this ).dialog( "close" );
}
})
控制器
@RequestMapping(value="/test", method=RequestMethod.POST)
@ResponseBody
public void test(@PathVariable String login, @PathVariable String password, @PathVariable String email) {
User user = new User();
user.setLogin(login);
user.setPassword(password);
user.setEmail(email);
userService.create(user);
}