从表中获取id

时间:2016-05-19 08:34:19

标签: mysql angularjs spring spring-mvc

我需要从网址获取一个id,并将其显示给输入。   当我尝试在输入中获取它时,他们告诉我他们给我这个错误:   “必需的整数参数'idpatient'不存在。”

this is my html page and table from where i get the id:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tous les patients</title>
<meta charset="utf-8" content="text/html" X-Content-Type-Options="nosniff" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.min.css" 
th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" type="text/css" href="../static/css/myStyle.css" 
th:href="@{/css/myStyle.css}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="ListePatientController">
<div class="container">
<form>
        <label>Mot clé:</label>
        <input type="text" ng-model="motCle"/>
        <Button ng-click="charger()">Chercher un patient</Button>
</form>
</div>
 <div class="container">

<table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nom</th>
                    <th>Prenom</th>
                    <th>Sexe</th>
                    <th>Date de naissance</th>
                    <th>Nationalité</th>
                    <th>CIN</th>
                    <th>CNE</th>
                    <th>Type de couverture</th>
                    <th>Num° du type de couverture</th>
                    <th>Province</th>
                    <th>Résident</th>
                    <th>Adresse personnelle du patient</th>
                    <th>Adresse parents du patient</th>
                    <th>GSM</th>
                    <th>Adresse électronique</th>
                    <th>Pratiquer un sport</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="p in patients.content">
                    <td>{{p.idPatient}}</td>
                    <td>{{p.nomPatient}}</td>
                    <td>{{p.prenomPatient}}</td>
                    <td>{{p.sexe}}</td>
                    <td>{{p.dateNaiss|date:'dd/MM/yyyy'}}</td>
                    <td>{{p.nationalite}}</td>
                    <td>{{p.cin}}</td>
                    <td>{{p.cne}}</td>
                    <td>{{p.typeCouverture}}</td>
                    <td>{{p.numTypeCouverture}}</td>
                    <td>{{p.province}}</td>
                    <td>{{p.resident}}</td>
                    <td>{{p.adressPerso}}</td>
                    <td>{{p.adressPatient}}</td>
                    <td>{{p.gsmPatient}}</td>
                    <td>{{p.mailPatient}}</td>
                    <td>{{p.pratiquePatient}}</td>
                    <td>
                <a href="inscrireConsultation.html?idpatient={{p.idPatient}}">ajout consult</a>
                </td>
                </tr>
            </tbody>
        </table>
 </div>
 <div class="container">
    <ul class="nav nav-pills">
        <li ng-class="{active:$index==pageCourante}" class="clickable" ng-repeat="p in pages track by $index">
            <a ng-click="gotoPage($index)">{{$index}}</a>
        </li>
    </ul>
 </div>

<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/myApp.js"></script>
</body>
</html>

这是html页面,我应该在输入中显示它:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inscription d'une consultation</title>
<meta charset="utf-8" content="text/html" X-Content-Type-Options="nosniff" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.min.css" 
th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" type="text/css" href="../static/css/myStyle.css" 
th:href="@{/css/myStyle.css}"/>
</head>
<body ng-app="myApp" ng-controller="inscriptionConsultationController">

<div class="col-md-6 col-sm-6 col-xs-12  container">

    <div class="panel panel-success container spacer ">
    <div class="panel-heading"><b><h1>Ajout d'une consultation</h1></b></div>
    <div class="panel-body">

    <div ng-if="mode.value=='form'" >
    <form>
        <div class="form-group">
            <label class="control-label">Date de la consultation:</label>
            <input class="form-control" type="date" ng-model="consultation.dateConsult"/>
            <span ng-if="errors" class="error">{{errors.dateConsultt}}</span>
        </div>
        <div class="form-group">
            <label class="control-label">Type de la consultation:</label>
            <input class="form-control" type="text" ng-model="consultation.typeConsult"/>
            <span ng-if="errors" class="error">{{errors.typeConsult}}</span>
        </div>
        <div class="form-group">
            <label class="control-label">Motif(s):</label>
            <input class="form-control" type="text" ng-model="consultation.motifConsult"/>
            <span ng-if="errors" class="error">{{errors.motifConsult}}</span>
        </div>
        <div class="form-group">
            <label class="control-label">Dignostics:</label>
            <input class="form-control" type="text" ng-model="consultation.diagnostic"/>
            <span ng-if="errors" class="error">{{errors.diagnostic}}</span>
        </div>
        <div class="form-group">
            <label class="control-label">Maladie chronique?</label>
                <div class="radio">
                    <label><input type="radio" name="optradio" ng-model="consultation.maladieChronique">Oui</label>
                </div>
                <div class="radio">
                    <label><input type="radio" name="optradio" ng-model="consultation.maladieChronique">Non</label>
                </div>
            <span ng-if="errors" class="error">{{errors.maladieChronique}}</span>
        </div>
        <div class="form-group">
            <label class="control-label">Décision:</label>
            <input class="form-control" type="text" ng-model="consultation.decision"/>
            <span ng-if="errors" class="error">{{errors.decision}}</span>
        </div>
        <div class="form-group">
            <input type = "number" ng-model="consultation.idPatient" value="idpatient"/>

        </div>  
        <div class="form-group">
            <button  class="btn btn-success" ng-click="saveConsultation()"> Enregistrer</button>
        </div>
    </form>
    </div>
    <div ng-if="mode.value=='confirm'">
      <div class="panel-heading container spacer"><h2>Confirmation: La consultation a été ajoutée avec succès!</h2></div>
        <div class="form-group">
            <label class="control-label">ID:</label>
            <label class="control-label">{{consultation.idConsult}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">Date de la consultation:</label>
            <label class="control-label">{{consultation.dateConsult|date:'yyyy-MM-dd'}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">Type de la consultation:</label>
            <label class="control-label">{{consultation.typeConsult}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">Motif(s):</label>
            <label class="control-label">{{consultation.motifConsult}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">Diagnostics:</label>
            <label class="control-label">{{consultation.diagnostic}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">Maladie chronique?</label>
            <label class="control-label">{{consultation.maladieChronique}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">consultation:</label>
            <label class="control-label">{{consultation.decision}}</label>
        </div>
        <div class="form-group">
            <label class="control-label">id patient:</label>
            <label class="control-label">{{consultation.idPatient}}</label>
        </div>
    </div>
    <div ng-if="exception">
        <span class="error">{{exception.message}}</span>
    </div>
    </div>

 </div>


<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/myApp.js"></script>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

这是获取id的Spring服务:

@RequestMapping(value="/consultations",method=RequestMethod.POST)
public Object saveConsultation(@RequestParam (value = "idpatient", required = true) String idpatient,
                               @RequestBody @Valid Consultation c,
                               BindingResult bindingResult){

    if(bindingResult.hasErrors()){
        Map<String, Object> errors=new HashMap<>();
        errors.put("errors", true);
        for(FieldError fe: bindingResult.getFieldErrors()){

            errors.put(fe.getField(), fe.getDefaultMessage());
        }
        return errors;
    }       

    return consultationMetier.saveConsultation(idpatient,c,bindingResult);
}

答案 1 :(得分:0)

您无法直接使用它,您需要在服务级别为两个控制器共享数据。 有关详细信息,请参阅 - AngularJS - Passing data between pages