如何将数据插入到DB中,从JSP获取输入并使用spring restful services存储它,

时间:2017-04-18 08:55:45

标签: spring jsp spring-mvc

我的JSP代码是:feedback.jsp

                客户的反馈意见         

        <tr><th>Name</th><td>
                    <spring:bind path="cust.name">
                    <input name="name" type="text" id="name" class="form-control" value="${pdet.register_fname}&nbsp;${pdet.register_lname}" pattern="[A-Za-z\s]{1,15}"
                            title="Name should contain min of 1 and max of 15 characters!"required/>
                    </spring:bind>
                    </td><td>
                        <p id="demo" cssClass="error" />
                        <springform:errors path="name" cssClass="error" />
                       </td></tr>

            <tr><th>Email</th><td>
                    <spring:bind path="cust.emailid">
                    <input name="emailid" type="email" id="emailid"  class="form-control"   value="${pdet.username}" pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" title="Please enter a valid email address." required size="40"/>
                    </spring:bind>
                    </td><td>
                        <p id="demo" cssClass="error" />
                        <springform:errors path="emailid" cssClass="error" />
                       </td><td style="border:0; color: red; position: fixed;">${msg}</td></tr>

             <tr><th>Mobile Number</th><td>
                    <spring:bind path="cust.mobileno">
                   <input name="mobileno" type="text" id="mobileno" class="form-control"  pattern="[0-9]{6,10}" title="Mobile number of minimum of 6 and maximum of 10 digits" value="${pdet.register_mno} " />

                    </spring:bind>
                    </td><td>
                        <p id="demo" cssClass="error" />
                        <springform:errors path="mobileno" cssClass="error" />
                       </td></tr>




               <tr><th>Description</th><td>
                    <spring:bind path="cust.description">
                    <textarea name="description" rows='3' id='description' class="form-control" title="cust_comment" required></textarea>
                    </spring:bind>
                    </td> </td><td>
                        <p id="demo" cssClass="error" />
                        <springform:errors path="description" cssClass="error" />
                       </td></tr>

@RestController代码:

@RequestMapping(value =&#34; / customer / new&#34;,method = RequestMethod.POST,headers =&#34; Accept = application / json&#34;)     public ResponseEntity addCustomer(@RequestBody feedbackRepo customer,UriComponentsBuilder ucb){

    feedback f=new feedback(); 
    customer.setName(f.getName());
    customer.setEmailid(f.getEmailid());

    this.pmService.saveCustomer(customer);
    HttpHeaders headers=new HttpHeaders();
    headers.setLocation(ucb.path("/customer/{id}").buildAndExpand(customer.getIssueid()).toUri());
    return new ResponseEntity<Void>(HttpStatus.CREATED);  
}

0 个答案:

没有答案