如何通过 AJAX 将选择列表组件列表传递到 AngularJS 中的 Java 控制器?

How to pass a list of a picklist component via AJAX to my Java controller in AngularJS?

项目:jsp + AngularJS

我有一个模式,我已经通过 POST (ajax) 将一些信息传递到我的 Java 控制器,它工作正常。

但是,我插入了一个新组件,我不知道如何接收我选择的picklist组件列表,看图了解:

例如,我有一些字段通过 POST 传递到我的 java 控制器并且工作正常:

$scope.cadastraCertificado = function() {       

$http.post('/boxmlV2/cadastrocertificado/salvaCertificado', {
    urlCertificado :     $scope.certificadoIncluirAlterar.urlCertificado,
    dataValidadeCertificado : $scope.certificadoIncluirAlterar.dataValidadeCertificado.toString(),
    senhaCertificado : $scope.certificadoIncluirAlterar.senhaCertificado
    //picklist????????          
}).then(function(response) {
    $scope.sucesso();
}, function(response) {         
});

};  

但我不知道如何从我在选择列表组件中选择的列表中接收数据,即右侧的那些。

我该怎么做?

我的选择列表:

                               <div class="form-group">
                                    <label class="control-label col-md-3">Empresas:</label>
                                    <div class="col-md-9">                                          
                                        <select ng-model="corvo" multiple="multiple" class="multi-select" id="my_multi_select1" name="my_multi_select1[]">
                                            <option ng-repeat="c in clientes" value="{{c.idCliente}}" ng-click="atribuirUm($index, c)">{{c.razaoSocial}}</option>
                                            <option selected ng-repeat="c2 in clientes2" value="{{c2.idCliente}}" ng-click="limparUm($index, c2)">{{c2.razaoSocial}}</option>
                                        </select>                                       
                                    </div>                                          
                                </div>

$scope.corvo 将包含一个数组,其中包含所选元素的 ID(values),因此您只需发送该数组即可:

$http.post('/boxmlV2/cadastrocertificado/salvaCertificado', {
    urlCertificado :     $scope.certificadoIncluirAlterar.urlCertificado,
    dataValidadeCertificado : $scope.certificadoIncluirAlterar.dataValidadeCertificado.toString(),
    senhaCertificado : $scope.certificadoIncluirAlterar.senhaCertificado,
    corvo: $scope.corvo         
}).then(function(response) {
    $scope.sucesso();
}, function(response) {         
});

我假设你正在发送 JSON 数据,否则你必须将它序列化为一个字符串,例如使用 $scope.corvo.join(',').

这是我的 js 运行正常后的样子:

BoxApp.controller("CadastroCertificadoController", function($scope, $http) {

$scope.clientes = {};
$scope.listaEmpresas = [];

$scope.iniciar = function() {
    $http.get('/boxmlV2/cadastrocertificado').success(function(response) {
        $scope.clientes = response;
    });
};

$scope.iniciar();

/**
 * Trabalhando o componente picklist
 */
$scope.clientes2 = [];      
$scope.atribuirUm = function(index, c) {
    var cliente = {};
    cliente.idCliente = c.idCliente;
    cliente.razaoSocial = c.razaoSocial;
    $scope.clientes2.push(cliente);
    $scope.clientes.splice(index, 1);
}
$scope.limparUm = function(index, c2) {
    $scope.clientes2.splice(index, 1);
    $scope.clientes.push(c2);       
}

/**
 * Trecho para validar o form ao submeter.
 */
$scope.submitted = false;
$scope.submitForm = function(form, clientes2) {     
    $scope.listaEmpresas = $scope.clientes2;
    $scope.submitted = true;
    if (form.$valid) {          
        $scope.cadastraCertificado();
    }
};  

/**
 * Requisição POST (ajax)
 */
$scope.cadastraCertificado = function() {

    var dados = {
            urlCertificado : $scope.certificadoIncluirAlterar.urlCertificado,
            strDataValidadeCertificado : $scope.certificadoIncluirAlterar.strDataValidadeCertificado.toString(),
            senhaCertificado : $scope.certificadoIncluirAlterar.senhaCertificado,
            listaEmpresas : $scope.listaEmpresas                
    };

    $http.post('/boxmlV2/cadastrocertificado/salvarCertificado', dados).then(function(response) {

    }, function(response) { 
        $scope.sucesso();
    });
};  

$scope.sucesso = function() {
    $scope.closeMyPopup();
    $scope.iniciar();       
};  

$scope.closeMyPopup = function() {
    $(myModal_autocomplete).modal('hide');
};

});