Как искать и получать значения в базе данных, используя spring-mvc? - PullRequest
0 голосов
/ 13 июня 2019

Я создал форму входа, где я могу сохранять, обновлять и искать информацию об ученике.Я завершил функцию сохранения и обновления, и я изо всех сил пытаюсь завершить функцию кнопки сохранения.Я мог получить искомые значения в консоль, но не на страницу JSP.

Страница JSP содержит три кнопки с отдельными функциями javascript для создания, обновления и поиска сведений об ученике.

Контроллер

@RequestMapping(value="/auths", method=RequestMethod.POST)
    @ResponseBody
    public void search(
            @RequestParam(value="Id") long studentid,
            @RequestParam(value="Name") String name,
            Model model, HttpServletRequest httpRequest
            ){

        StudentCoursesSisi objct=dobj.find(studentid);
        if(objct != null){
            System.out.println(objct.getStudentName());
            model.addAttribute("studentName",objct.getStudentName());

        }


    }

JSP

<form id = "frmStudent" onsubmit="return false;">
                        <div class="panel-body">                            
                            <div class="col-md-12 form-group" >
                                <!--  Student Id -->
                                <label class="col-md-2 control-label customlabel">Student Id</label>

                                <!-- Input Item -->
                                <div class="col-md-3">
                                    <div class="input-group " >
                                        <!-- Input type -->
                                        <input type="text" class="form-control reset" id="txtStudentId"
                                            name="studentId" value="${studentId}">
                                    </div>
                                </div>
                                <!-- ./Input Item -->
                                <!-- ./student id -->                                     
                            </div>

                            <div class="col-md-12 form-group" style = "margin-top : 15px;">
                                <!--  Student Name -->
                                <label class="col-md-2 control-label customlabel">Student Name</label>

                                <!-- Input Item -->
                                <div class="col-md-8">                                   
                                    <!-- Input type -->
                                    <input type="text" class="form-control reset" id="txtStudentName"
                                        name="studentName" value="${studentName}">                                   
                                </div>
                                <!-- ./Input Item -->
                                <!-- ./student id -->                                     
                            </div>



                            <div class="col-md-12 form-group" style = "margin-top : 15px;">
                                <label class="col-md-2 control-label customlabel">Gender</label>

                                <div class="col-md-6" >
                                    <input type="radio" class="  large" id="optMale"
                                        style="margin-top: 8px;" name="gender" value="M">
                                        Male &nbsp; &nbsp;
                                     <input type="radio" class="    large"
                                        id="optFemale" style="margin-top: 8px;"
                                        name="gender" value="F"> Female
                                </div>
                                <div class="col-md-3"></div>
                            </div>





                            <div class="col-md-12 form-group" style = "margin-top : 15px;">
                                <!--  Centre Status -->
                                <label class="col-md-2 control-label customlabel">Language</label>

                                <!-- Input Item -->
                                <div class="col-md-2">
                                    <kendo:dropDownList id="lan" name="language" dataTextField="text"
                                        dataValueField="value" style="width: 100%;">
                                        <kendo:dataSource data="${languageList}">   
                                        <select id="dropdown">
                                            <option>Sinhala</option>
                                            <option>English</option>
                                            <option>Tamil</option>
                                        </select>                                        
                                        </kendo:dataSource>
                                    </kendo:dropDownList>
                                </div>
                                <!-- ./Input Item -->
                                <!-- ./Centre Status -->

                                <div class = "col-md-7">
                                    <p class="text-danger col-md-4 reset" id="createdUser" style = "padding-top: 4px;"></p>
                                    <p class="text-danger col-md-8 reset" id="createdDate" style = "padding-top: 4px;"></p> 
                                </div>
                            </div>

                        </div>
                        <div class="panel-footer">
                            <button class = "btn btn-default" title = "Clear Form" name = "clear" id = "btnClear" type = "reset" >
                                <i class = "fa fa-eraser"></i> Clear
                            </button>                    

                            <button class="btn btn-success pull-right" title="Save Record" name="save" id="btnSave" type="button" onclick="authUser()" >
                                <i class="fa fa-save"></i> &nbsp; Save Me 
                            </button>   

                            <button class="btn btn-success pull-right" title="Save Record" name="save" id="btnSave" type="button" onclick="authUserUpdate()" >
                                <i class="fa fa-save"></i> &nbsp; Update
                            </button>

                            <button class="btn btn-success pull-right" title="Save Record" name="save" id="btnSave" type="button" onclick="authUsersearch()" >
                                <i class="fa fa-save"></i> &nbsp; Search
                            </button>

                        </div>
                    </form> 
                </div>

                <div class="panel panel-info">
                    <div class="panel-heading">
                        <h3 class="panel-title">Student Courses</h3>
                    </div>

                    <div class = "panel-body" style = "padding: 0px;">
                        <kendo:grid name = "courseDetails" autoBind = "true" selectable = "true" editable = "true" pageable = "true" sortable= "false" columnMenu="true" >                      

                            <kendo:grid-columns>
                                <kendo:grid-column title = "Course Code" field = "courseCode" />
                                <kendo:grid-column title = "Course Name" field = "courseName" />
                                <kendo:grid-column title = "Created User" field = "createdUser" />
                                <kendo:grid-column title = "Created Date" field = "createdDate" format="{0:dd/MM/yyyy HH:mm:ss}" />
                            </kendo:grid-columns>

                            <kendo:dataSource pageSize="2" data= "data" serverPaging="true"serverSorting="true" serverFiltering="true" serverGrouping="true">
                                <kendo:dataSource-transport>
                                    <kendo:dataSource-transport-read url = "${readUrl}" type="post" dataType="json" contentType="application/json"/>
                                    <kendo:dataSource-transport-parameterMap>
                                        <script>
                                            function parameterMap(options, type) {
                                                return JSON.stringify(options);
                                            }
                                        </script>
                                    </kendo:dataSource-transport-parameterMap>
                                </kendo:dataSource-transport>

                                <kendo:dataSource-schema data="data" total="total">
                                    <kendo:dataSource-schema-model>
                                        <kendo:dataSource-schema-model-fields>
                                            <kendo:dataSource-schema-model-field name = "createdDate" type="date">
                                                <kendo:dataSource-schema-model-field-parse>
                                                    <script>
                                                        function parseDate(e){
                                                            if (e != null)
                                                                return kendo.parseDate(new Date(e), 'dd/MM/yyyy HH:mm:ss');
                                                        }   
                                                    </script>
                                                </kendo:dataSource-schema-model-field-parse>
                                            </kendo:dataSource-schema-model-field>
                                        </kendo:dataSource-schema-model-fields>
                                    </kendo:dataSource-schema-model>

                                </kendo:dataSource-schema>
                            </kendo:dataSource>
                        </kendo:grid>
                    </div>
                </div>
            </div>
            <!-- END YOUR CONTENT -->

        </div>
        <!-- END CONTENT FRAME BODY -->

    </div>
    <!-- PAGE CONTENT FRAME -->

</div>
<!-- PAGE CONTENT WRAPPER -->

<kendo:notification name="saveNotification" autoHideAfter="10000">
    <kendo:notification-position pinned="true" right="10" top="85" />
</kendo:notification>

<script>
    var popupNotification = $("#saveNotification").kendoNotification({
        position : {
            pinned : true,
            top : 85,
            left : null,
            bottom : null,
            right : 20
        }
    }).data("kendoNotification");

    $(document).ready(function() {
        //$("#dropdown").kendoDropDownList();

    });

    function authUser(){
          $.ajax({
           type : "POST",
           url : 'student/auth',
           dataType : "json",
           data : {
            Name : $('#txtStudentName').val(),
            StudentId : $('#txtStudentId').val(),
            Rad : $("input[name='gender']:checked").val(),
            stdlanguage : $("#lan").val(), 
           },
           success : function(response) {

            if(response === success){     
             popupNotification.show('success');
            console.log(response);
             }else{
              popupNotification.show('error');
              }
           },
          });

        }
    function authUserUpdate(){
          $.ajax({
           type : "POST",
           url : 'student/authup',
           dataType : "json",
           data : {
            StudentId : $('#txtStudentId').val(),   
            Name : $('#txtStudentName').val(),
            Rad : $("input[name='gender']:checked").val(),
            stdlanguage : $("#lan").val(), 
           },
           success : function(response) {

            if(response === success){     
             popupNotification.show('success');
            console.log(response);
             }else{
              popupNotification.show('error');
              }
           },
          });

        }
    function authUsersearch(){
          $.ajax({
           type : "POST",
           url : 'student/auths',
           dataType : "json",
           data : {
            Id : $('#txtStudentId').val(),
            Name : $('#txtStudentName').val(),
           },
           success : function(response) {

            if(response === success){     
             popupNotification.show('success');
            console.log(response);
             }else{
              popupNotification.show('error');
              }
           },
          });

        }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...