【发布时间】:2014-09-18 09:51:00
【问题描述】:
我尝试在 Spring MVC 中对我的控制器进行查询。
我的操作代码是:
@RequestMapping(value = "/compile/{applicationId}", method = RequestMethod.GET)
public String compileApplication(@PathVariable Long applicationId, @RequestParam("email") String email) throws ApplicationNotFoundException {
...
}
但我得到一个错误:
必需的字符串参数“电子邮件”不存在
我的 main.js:
var runCompileModal = function (options) {
$(".modal-compile").each(function () {
var modalNode = $('<div class="modal fade" id="compileModal" tabindex="-1" role="dialog" aria-hidden="true">' +
'<div class="modal-dialog modal-dialog-sm">' +
' <div class="modal-content">' +
' <div class="modal-header">' +
' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
' <h4 class="modal-title text-center">compile ?</h4>' +
' </div>' +
' <div class="modal-body">' +
' <p class="margin-bottom-lg">Are you sure ?</p>' +
' <div class="form-group text-center">' +
' <label for="email">@ Mail:</label>' +
' <input class="form-control" name="email" id="email" type="text" style="border:solid 1px black; border-radius:5px; text-align:center; box-shadow:0 0 6px;" /> ' +
' </div>' +
' <div class="form-group text-center">' +
' <button type="button" class="modal-btn-yes btn btn-success btn-gradient margin-right-lg">' +
' <i class="fa fa-check"></i>' +
' <span>' + options.compileModal.yes + '</span>' +
' </button>' +
' <button type="button" class="modal-btn-no btn btn-danger btn-gradient" data-dismiss="modal">' +
' <i class="fa fa-warning"></i>' +
' <span>' + options.compileModal.no + '</span>' +
' </button>' +
' </div>' +
' </div>' +
' </div>' +
'</div>' +
'</div>');
$('body').append(modalNode);
modalNode.find('.modal-btn-yes').click(function () {
var email = document.getElementById('email');
location.href = $(this).data('url') + "/" + email.value;
});
modalNode.on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var modal = $('#compileModal');
modal.find('.modal-title').html(button.data('title'));
modal.find('.modal-body p').html(button.data('content'));
modal.find('.modal-btn-yes').attr('data-url', button.data('url'));
});
});
}
我的 app.html:
' <button title="' + compileTitle + '" class="btn btn-compile btn-gradient" data-toggle="modal" data-target="#compileModal" data-url="' + compileUrl + object.id + '" + data-title="' + compileModalTitle + '" + data-content="' + compileModalContent + '">' +
' <span class="glyphicon glyphicon-share"></span>' +
' </button>'
当我在 url 中包含电子邮件参数时出现新错误:
类型错误:e 为空
【问题讨论】:
-
执行 HTTP get 的代码是什么样的?
标签: java spring spring-mvc