Spring + struts + ibatis + extjs is used for development, and oracle is used for database
Ibtais configuration paging fuzzy query
Java code
<SqlMap namespace = "RYDM">
<! -- Load the paging object -->
<TypeAlias alias = "page" type = "com. portal. util. Page"/>
<! -- Load object -->
<TypeAlias alias = "abatorgenerated_RydmResult" type = "com. portal. model. Rydm"/>
<ResultMap id = "abatorgenerated_RydmResult" class = "com. portal. model. Rydm">
<Result column = "RYDM" property = "rydm" jdbcType = "VARCHAR"/>
<Result column = "RYMC" property = "rymc" jdbcType = "VARCHAR"/>
<Result column = "BMZDM" property = "bmzdm" jdbcType = "VARCHAR"/>
<SQL id = "findByPageCondition">
<IsNotEmpty property = "objCondition">
<IsNotEmpty property = "objCondition. bmzdm">
Bmzdm LIKE '% $ objCondition. bmzdm $ %'
</IsNotEmpty>
<IsNotEmpty property = "objCondition. rymc">
AND rymc LIKE '% $ objCondition. rymc $ %'
</IsNotEmpty>
</IsNotEmpty>
</SQL>
<Select id = "findByPage" parameterClass = "page"
ResultClass = "abatorgenerated_RydmResult">
SELECT * FROM (SELECT row _. *, rownum _ FROM
(Select ry. * from RYDM ry
Where 1 = 1
<Dynamic prepend = "AND">
<Include refid = "findByPageCondition"/>
</Dynamic>
) Row _ WHERE rownum & lt; = $ limit $) row _ WHERE rownum _ & gt; $ start $
Order by rydm
</Select>
<Select id = "findByCount" parameterClass = "page" resultClass = "int">
Select count (*) from rydm ry where 1 = 1
<Dynamic prepend = "AND">
<Include refid = "findByPageCondition"/>
</Dynamic>
</Select>
Generic paging Model
Java code
Public class Page implements java. io. Serializable {
Public void setPageProperty (Page page ){
If (page. getStart ()> 0 ){
// Set the Data fetch Interval
Int endPage = page. getStart () + page. getLimit ();
Int stratPage = page. getStart ();
This. setStart (stratPage );
This. setLimit (endPage );
} Else {
This. setLimit (page. getLimit ());
This. setStart (0 );
}
}
/** Total number of records */
Private int totalProperty;
/** Paging result */
Private List root;
/** Start page number */
Private int start;
/** Number of pages per page */
Private int limit;
/** Success or failure */
Private boolean success;
/** Query condition */
Private Object objCondition;
Entity class
Java code
Public class Rydm implements Serializable {
/**
* This field was generated by Abator for iBATIS.
* This field corresponds to the database column RYDM. RYDM
*
* @ Abatorgenerated Sat Aug 06 16:55:26 CST 2011
*/
Private String rydm;
Private String rymc;
Private String bmzdm;
Service layer call
Java code
Public class RydmServiceImpl extends SqlMapClientDaoSupport implements
RydmService {
Public Page findByPageRydm (Page page) throws BusinessException {
Page. setTotalProperty (Integer) getSqlMapClientTemplate ()
. QueryForObject ("RYDM. findByCount", page ));
Page. setPageProperty (page );
Page. setRoot (getSqlMapClientTemplate (). queryForList (
"RYDM. findByPage", page ));
Return page;
}
Action
Java code
Public class UsersAction extends ActionSupport implements ServletRequestAware,
SessionAware {
Public String message;
Public String conditions;
Protected Map session; // session Object
Protected HttpServletRequest request; // request object
/*
* Query user information
*/
Public String listUser (){
Rydm user = new Rydm ();
User. setBmzdm (request. getParameter ("bmzdm"). toString ());
User. setRymc (request. getParameter ("rymc"). toString ());
Int start = 0;
Int Limit = 10;
Page page = new Page ();
Try {
Start = Integer. valueOf (getRequest (). getParameter ("start "));
Limit = Integer. valueOf (getRequest (). getParameter ("limit "));
} Catch (NumberFormatException e ){
}
Page. setStart (start );
Page. setLimit (Limit );
// Use an object as the query parameter to pass in ibtais
Page. setObjCondition (user );
Page = userService. findByPage (page );
} Catch (BusinessException e ){
Log. warn ("UsersAction. class query user information exception" + e. getMessage (), e );
}
Return SUCCESS;
}
}
I used ext for the returned configuration, so the converted json is displayed to the client.
Java code
<Package name = "admin" extends = "json-default" namespace = "/admin">
<Action name = "listUser" class = "userAction" method = "listUser">
<Result type = "json">
<Param name = "root"> page </param>
<Param name = "excludeProperties"> limit, start, objCondition </param>
</Result>
</Action>
</Package>
Extjs parameter query
Js Code
Var rydm_store = new Ext. data. Store ({
Proxy: new Ext. data. HttpProxy ({
Url: "/extDemo/admin/userList. action ",
Method: "post"
}),
Reader: new Ext. data. JsonReader ({
TotalProperty: 'totalproperties ',
Root: 'root ',
Fields :[{
Name: 'bmzdm ',
Type: 'string'
},{
Name: 'bmmc ',
Type: 'string'
}]
})
});
Var btn_search_rydm = new Ext. Button ({
Text: 'query ',
IconCls: 'icon-search ',
Handler: queryRydm
});
Var queryRydm = function (){
Rydm_store.baseParams.bmzdm = bmzdm_search_rydn.getValue ();
Rydm_store.baseParams.rymc = text_search_rydm.getValue ();
Rydm_store.load ({params: {start: 0, limit: 15 }});
}
This article is from "aline"