In the 8th section we completed the query and delete the product category function, then the implementation of the query and delete the product function is very good to do, the principle and the 8th section is exactly the same, just modify some parameters, such as request different action. Because the query and delete products do not need to pop up a new UI window, so we just complete the appropriate part of the query.jsp and the corresponding background can be.
1. Query the realization of the commodity function
query function is mainly implemented in the query box, from the previous section, the query box is a text: "<input id= ' ss ' name= ' Serach '/>", we are through the ordinary text box into the query search text box to achieve, Here we add the code for the appropriate section in query.jsp:
$ (' #ss '). SearchBox ({
///Trigger Query Event
searcher:function (value,name) {//value represents the value entered
//Add trigger code
$ (' #dg '). DataGrid (' Load ', {//reload, parameter name specified for user input value
name:value
});
prompt: ' Please enter search keyword '
};
The test results are as follows:
The query is very simple, as with the last section of the load all goods, but the query when the parameter set to the user input value, load all the time parameter set to NULL.
2. Delete the realization of the product function
next to do the removal of the merchandise function, first of all, we query.jsp the corresponding parts of the code complement:
{iconcls: ' Icon-remove ', text: ' Delete merchandise ', handler:function () {//Add trigger code var rows = $ ("#dg"). DataGrid ("Getselec tions ")//To determine whether there is a checked row record, use Getselections to get all the selected rows//Returns the selected row, or if no rows are selected, returns an empty array if (rows.length = 0) {//pop-up hint information $.messa
Ger.show ({//syntax is similar to static method in Java, direct object invoke title: ' Error hint ', msg: ' Select at least one record ', timeout:2000, ShowType: ' Slide ',}); else {//Prompt for confirmation of deletion, if confirmed then perform the delete logical $.messager.confirm (' Delete confirmation dialog box ', ' Are you sure you want to delete this item?)
', function (r) {if (R) {//1. Get the corresponding ID from the obtained record, splice the value of the ID, and then send the background 1,2,3,4 var ids = "";
for (var i = 0; i < rows.length i + +) {IDs + + rows[i].id + ",";
ids = ids.substr (0, Ids.lastindexof (",")); 2. Send Ajax request $.post ("Product_deletebyids.action", {ids:ids},function (result) {if (result = = "true") {//delete the record just selected,
Otherwise, it affects the actions that are later updated $ ("#dg"). DataGrid ("Uncheckall"); Refresh the current page, the query we use the load, refresh the first page, reload is refreshing the current page $ ("#dg"). DataGrid ("Reload");/without parameter defaults to Queryparams} else {$.mes Sager.show ({title: 'Remove exception ', msg: ' Delete failed, please check operation ', timeout:2000, ShowType: ' Slide ',}
}, "text");
}
});
}
}
}
From the above code can be seen, delete operations need to select at least one record, when selected, when the deletion (that is, R is true), first get the user has checked which records, the ID number of these records stitching up, and then want to send the AJAX request backstage, Request Productaction in the Deletebyids method, will be stitching up the ID as a parameter to the past, if the deletion succeeds, then return a string "true" to the foreground, and then the front desk will just check the record cleared, so as not to affect the subsequent update operation, because the update also to check the record, Then refresh the current page and reload all the product information for the database.
The process is very clear, we write the background program, first from the service layer:
Public interface Productservice extends baseservice<product> {
//query merchandise information, cascading categories public
list<product > queryjoincategory (String type, int page, int size); Use the name of the product query
//Search by keyword query Total record number public
Long getcount (String type);
Delete multiple records public
void Deletebyids (String IDs) based on IDs;
@SuppressWarnings ("unchecked")
@Service ("Productservice") public
class Productserviceimpl extends Baseserviceimpl<product> implements Productservice {
//Omit other code
... @Override public
void Deletebyids (string IDs) {
string hql = ' Delete from Product p where p.id in ("+ IDs +") ;
GetSession (). CreateQuery (HQL). executeupdate ();
}
Next complete the Deletebyids method in Productaction:
@Controller ("Productaction")
@Scope ("prototype") Public
class Productaction extends Baseaction<product > {
//Omit other code ...
Public String Deletebyids () {
System.out.println (IDS);
Productservice.deletebyids (IDs);
If the deletion succeeds, we pass "true" as a stream to the foreground
InputStream = new Bytearrayinputstream ("true". GetBytes ());
return "stream";
}
In the same way as previously deleted commodity classes, the following are configured in Struts.xml:
<action name= "product_*" class= "productaction" method= "{1}" >
<!--omit additional configuration--> <result
" Stream "type=" stream ">
<param name=" InputName ">inputStream</param>
</result>
</action>
This allows the string "true" to be passed to the foreground, receiving the instructions to delete the success. Look at the effect:
The test was successful, so the search and deletion function of the product was finished.
This article address: http://blog.csdn.net/eson_15/article/details/51360804
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.