Struts2 multi-condition combination query and preparation of default data

Source: Internet
Author: User

When using SSH, findByExample and findByAll are generated in DaoImpl.


In general, we will use findByAll in the execute method to prepare data for the page.

 


If this Action is included in your jsp page, data overwrites will occur.


[Html] \
<S: action name = "category" executeResult = "false"> </s: action>

<S: action name = "category" executeResult = "false"> </s: action>
Now we can directly use findByExample in the execute method.

The query method does not need to be written in execute.

Code:


[Java]
Public String execute (){

List <Category> cList = (List <Category>) categoryService. findByExample (getCategory ());
Map map = (Map) ServletActionContext. getContext (). get ("request ");
Map. put ("categorylist", cList );
System. out. println ("query object, data size:" + cList. size ());

Return "success ";
}

Public String execute (){

List <Category> cList = (List <Category>) categoryService. findByExample (getCategory ());
Map map = (Map) ServletActionContext. getContext (). get ("request ");
Map. put ("categorylist", cList );
System. out. println ("query object, data size:" + cList. size ());

Return "success ";
}
In this way, at the beginning, there were no conditions, that is, preparing all the data,

Let the input condition, which is not null according to the condition and then comes to the product SQL statement

Similar to: select * from table where name = 222... sex = 2222 ....


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.