से पैरामीटर पास करना मैं एक स्प्रिंग एमवीसी अनुप्रयोग में काम कर रहा हूं जो हाइबरनेट का उपयोग करता है।जेएसपी से स्प्रिंग कंट्रोलर विधि
जेएसपी पृष्ठ में मेरे पास एक फ़ंक्शन है जो डेटाबेस में संग्रहीत मानों को सूचीबद्ध करता है (वर्तमान में सभी मान)।
मैंने एक विधि लिखी है, जहां सूची केवल जेएसपी फ़ाइल में पास की गई आईडी तक ही सीमित है। मुझे एचक्यूएल क्वेरी सही काम कर रही है, इसलिए मुझे पता है कि यह पैरामीटर के रूप में आईडी के आधार पर डेटा पुनर्प्राप्त कर रहा है।
अब, मैं नियंत्रक में इस विधि का उपयोग करना चाहता हूं। इसके लिए मुझे सूची में आईडी का पैरामीटर पास करना होगा, इसलिए नियंत्रक पक्ष में, फ़ंक्शन को कॉल किया जाता है जो उस आईडी के आधार पर सूची पुनर्प्राप्त करेगा।
दुर्भाग्य से मुझे नहीं पता कि जेएसपी फ़ाइल से पैरामीटर कैसे पास करें।
JSP फ़ाइल: सूची समारोह के साथ
<c:url var="addAction" value="/note/add" ></c:url>
<form:form action="${addAction}" commandName="notices">
<table>
<c:if test="${!empty notices.notetext}">
<tr>
<td>
<form:label path="noticesid">
<spring:message text="noticesid"/>
</form:label>
</td>
<td>
<form:input path="noticesid" readonly="true" size="8" disabled="true" />
<form:hidden path="noticesid" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="notetext">
<spring:message text="notetext"/>
</form:label>
</td>
<td>
<form:input path="notetext" />
</td>
</tr>
<tr>
<td>
<form:label path="notetag" >
<spring:message text="notetag"/>
</form:label>
</td>
<td>
<form:input path="notetag"/>
</td>
</tr>
<tr>
<td>
<form:label path="notecolor">
<spring:message text="notecolor"/>
</form:label>
</td>
<td>
<form:input path="notecolor" />
</td>
</tr>
<tr>
<td>
<form:label path="canvasid">
<spring:message text="canvasid"/>
</form:label>
</td>
<td>
<form:input path="canvasid" />
</td>
</tr>
<tr>
<td>
<form:label path="sectionid">
<spring:message text="sectionid"/>
</form:label>
</td>
<td>
<form:input path="sectionid" />
</td>
</tr>
<tr>
<td>
<form:label path="canvasnName">
<spring:message text="canvasnName"/>
</form:label>
</td>
<td>
<form:input path="canvasnName" />
</td>
</tr>
<tr>
<td colspan="2">
<c:if test="${!empty notices.noticesid}">
<input type="submit"
value="<spring:message text="Edit note"/>" />
</c:if>
<c:if test="${empty notices.notetext}">
<input type="submit"
value="<spring:message text="Add note"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<br>
<h3>Notes List</h3>
<c:url var="listAction" value="/note/list/2323" ></c:url>
<c:if test="${!empty notices.noticesid}">
<table class="tg">
<tr>
<th width="80">Notes ID</th>
<th width="120">Notes text</th>
<th width="120">Note Tag</th>
<th width="120">Note color</th>
<th width="120">Note section</th>
<th width="120">Canvas id</th>
<th width="120">Canvas name</th>
<th width="120">Other id</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listNotes}" var="notices">
<tr>
<td>${notices.noticesid}</td>
<td>${notices.notetext}</td>
<td>${notices.notetag}</td>
<td>${notices.notecolor}</td>
<td>${notices.sectionid}</td>
<td>${notices.canvasid}</td>
<td>${notices.canvasnName}</td>
<td>${notices.personid}</td>
<td><a href="<c:url value='/editnote/${notices.noticesid}' />" >Edit</a></td>
<td><a href="<c:url value='/removenote/${notices.noticesid}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
नियंत्रक फ़ाइल:
@RequestMapping(value = "/note/list/{id}", method=RequestMethod.GET)
public String listNotes(@PathVariable int id,Model model) {
Person person = personService.getCurrentlyAuthenticatedUser();
this.setSectionid(id);
model.addAttribute("person", new Person());
model.addAttribute("listPersons", this.personService.listPersons());
model.addAttribute("listNotes",this.notesService.listNotesBySectionId(id,person));
return "note";
}
@RequestMapping(value= "/note/add")
public String addNote(@ModelAttribute("notices") Notes p,Model model) {
Person person = personService.getCurrentlyAuthenticatedUser();
model.addAttribute("listNotes",this.notesService.listNotes());
int id = getSectionid();
System.out.println("Section id is"+id);
model.addAttribute("listNotes",this.notesService.listNotesBySectionId(id,person));
this.notesService.addNote(p, person);
return "note";
}
मैं शुद्ध को देख की कोशिश की, लेकिन मैं नहीं जानता कि यह क्या कहा जाता है कि मैं देख रहा हूँ, तो एक कठिन समय है। कोई मदद अच्छी होगी। धन्यवाद।
कृपया बताएं कि आप स्पष्ट तरीके से क्या कर रहे हैं –
@SanKrish: मैंने सवाल संशोधित किया है, कृपया एक नज़र डालें। –
क्या आप 'id' को jsp से नियंत्रक तक पास करने का प्रयास कर रहे हैं? –