我正在为我的网络应用程序使用Angular Twitter Bootstrap Spring MVC,数据和安全性,这里我有一些问题我不知道如何使用bootsrap datepicker提交表单,该日期的插入值为null ,我真的不知道如何在Spring MVC上使用Datepicker,当我提交表单时,值不是通过hibernate mapp到数据库mysql
我的JSP代码如下:
<link href="<c:url value='/resources/date-css/bootstrap-datetimepicker.min.css'/>" rel="stylesheet"/>
<script src="<c:url value='/resources/date-css/bootstrap-datetimepicker.js' />"></script>
<script src="<c:url value='/resources/date-css/bootstrap-datetimepicker.fr.js' />"></script>
<div class="control-group">
<label class="control-label">Date </label>
<div class="controls input-append date form_date"
data-date=""
data-date-format="yyyy-mm-dd"
data-link-field="dtp_input2"
data-link-format="yyyy-mm-dd">
<input type="text"
required
ng-datepicker
ng-options="datepickerOptions"
placeholder="YYYY-MM-DD" />
<span class="add-on"><i class="icon-remove"></i></span>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<input type="hidden" value="{{ctrs.dateDebut}}"
ng-model="ctrs.dateDebut"
name="dateDebut"
id="dtp_input2"
class="ng-invalid-required"/>
</div>
-----------
脚本javascript就像beloow:
$(function(){
$('.form_date').datetimepicker({
format: 'yyyy-mm-dd',
language: 'fr',
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0
});
$('.form_date input[type=text]').change(function() {
//$('.ng-pristine').val($(this).val());
$('.ng-invalid-required').val($(this).val());
});
});
</script>
我使用Angularjs来放置数据并从服务器获取返回的数据,在我的controllerAngular中我在Angular控制器中有这个功能,允许我将数据传递给后端
$scope.createContact = function (newContactForm) {
if (!newContactForm.$valid) {
console.debug(newContactForm);
console.log('ici');
$scope.displayValidationError = true;
return;
}
$scope.lastAction = 'create';
var url = $scope.url;
var config = {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}};
$scope.addSearchParametersIfNeeded(config, false);
$scope.startDialogAjaxRequest();
$http.post(url, $.param($scope.ctrs), config)
.success(function (data) {
console.log('ici1');
$scope.finishAjaxCallOnSuccess(data, "#addContactsModal", false);
console.log('ici2');
})
.error(function(data, status, headers, config) {
console.log('ero1');
$scope.handleErrorInDialogs(status);
console.log("error");
});
};
Spring控制器如下:
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<?> create(@ModelAttribute("ctrs") Contrat ctrs,
@RequestParam(required = false) String searchFor,
@RequestParam(required = false, defaultValue = DEFAULT_PAGE_DISPLAYED_TO_USER) int page,
Locale locale) {
contraatsService.save(ctrs);
}
请帮助我!