ibatisÖÐÖ±Ö´ÐÐsql£¬·µ»Ø´æ´¢MapµÄListÀàÐÍ
ibatis×÷Ϊһ¸öÇáÁ¿¼¶µÄorm¹¤¾ßÏÖÔڷdz£Á÷ÐУ¬ÎÒÔÚʹÓÃÖз¢ÏÖ£¬ÓÐʱ½ö½öÏ£Íû·µ»ØÒ»¸öÀàÐÍΪmapµÄlist¾Í¿ÉÒÔÁË£¬
±ÈÈç¼òµ¥µÄ²éѯͳ¼ÆÖ®ÀàµÄ£¬Ã»ÓбØÒª¶¨ÒåÌ«¶àµÄpojo£¬Òò´ËÏëÄܲ»ÄÜÔÚibatisÖÐÖ±½Ó´«ÈësqlÓï¾äÀ´Ö´ÐУ¬È»ºó·µ»ØmapÄØ£¿
´ÓÍøÉÏËÑÁËһϣ¬»¹ÕæÓУ¬ÊµÑé³É¹¦ºó×ܽáһϣ¬´ó¼Ò¹²Í¬½ø²½¡£ ÆäʵºÜ¼òµ¥£¬¾ÍÊÇÔÚÅäÖÃÎļþÖÐÌí¼ÓÒÔϵÄÅäÖã¬
<!-- ²âÊÔSql -->
<select id="sqlQuery" parameterClass="java.lang.String" resultClass="java.util.HashMap">
<![CDATA[
$sql$
]]>
</select>
ʹÓ÷½·¨¾Í¸ü¼òµ¥ÁË£¬Æ´ºÃsqlÓï¾äºó£¬µ÷ÓÃ
sqlMapper.queryForList("sqlQuery", sql)¾ÍµÃµ½Á˲éѯ½á¹û£¬
µ±È»Õâ¸ö½á¹ûΪList£¬²¢ÇÒlistÖеÄÔªËØΪMapÀàÐÍ£¬Ñ»·List£¬¾ÍµÃµ½²éѯÃ÷ϸ¡£
ÒÔÉÏ·½·¨¶ÔÓÚ·ÖÀà»ã×ÜÀàµÄ²éѯͳ¼Æ¹¦ÄÜÓÈÆäʵÓá£Èç¹ûÖ»ÊÇcount()µÄ»°£¬¾ÍÈ¡ListµÄµÚÒ»¸öÔªËؾÍÐÐÁË¡£ ÎÒÃÇ¿ÉÒÔ°ÑÕâ¸ö·½·¨³é³öÀ´Ð´µ½Ò»¸öutilÀàÖУ¬·½·¨ÈçÏÂ
/**
* ²éѯ²¢·µ»ØList
*/
public static List queryForList(String sql){
List rtn = null;
try{
rtn = sqlMapper.queryForList("sqlQuery", sql);
}catch(SQLException sqle){
sqle.printStackTrace();
}
return rtn;
}
ÕâÑùÓÃÆðÀ´¾Í·½±ã¶àÁË¡£Èç¹û´ó¼Ò»¹ÓÐÆäËüµÄºÃ·½·¨£¬Ò»ÆðÌÖÂÛһϡ£ ÎÒµÄÍƹ㣺ÀÏÀÖÍø
Ïà¹ØÎĵµ£º
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ
......
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER function [dbo].[Get_StrArrayStrOfIndex]
(
@str varchar(1024), --Òª·Ö¸îµÄ×Ö·û´®
@split varchar(10), --·Ö¸ô·ûºÅ
@index int --È¡µÚ¼¸¸öÔªËØ
)
returns varchar(1024)
as
begin
declare @location int
de ......
Public Function GetDataTable()
Dim myComm As New SqlClient.SqlCommand("SELECT cauth_id,cauth_name,igrade,csupauth_id,csupauth_name from MAIN_TREE01 ", sqlconnection1)
Dim sdapt As New SqlClient.SqlDataAdapter(myComm)
Dim ds As New DataSet
sdapt.Fill(ds)
R ......
create PROC [dbo].[P_viewPage_A]
/*
¸ßЧͨÓ÷ÖÒ³´æ´¢¹ý³Ì(Ë«Ïò¼ìË÷)
¾´¸æ£ºÊÊÓÃÓÚµ¥Ò»Ö÷¼ü»ò´æÔÚΨһֵÁеıí»òÊÓͼ
ps:SqlÓï¾äΪ8000×Ö½Ú,µ÷ÓÃʱÇë×¢Òâ´«Èë²ÎÊý¼°sql×ܳ¤¶È²»Òª³¬¹ýÖ¸¶¨·¶Î§
*/
@TableName VARCHAR(200), --±íÃû
@FieldList VARCHAR(2000), --ÏÔʾÁÐà ......