Problem: In Ibatis, parameterMap cannot convert passed java attributes to database fields. I checked the Ibatis document. For Ado. Net, the column field exists, but not for java. I cannot understand why it is not applicable to java?
Ado.net configuration is roughly as follows, see: http://developer.51cto.com/art/200907/138508.htm
- ﹤parameterMap class="Employee" id="Employee_SelectParameterMap"﹥
-
- ﹤parameter column="EmployeeID" property="EmployeeID" dbType="int" type="int" direction="Input"/﹥
-
- ﹤parameter column="LastName" property="LastName" dbType="nvarchar" type="string" direction="Input"/﹥
-
- ﹤parameter column="Country" property="Country" dbType="nvarchar" type="string" direction="Input"/﹥
-
- ﹤/parameterMap﹥
The Java parameterMap configuration is roughly as follows: Note:$ Sort $ dir $,Prevent ibatis from adding"'"
- <parameterMap class="java.util.Map" id="paramQueryMap">
- <parameter property="appId" />
- <parameter property="listValue" />
- <parameter property="sort" />
- <parameter property="dir" />
- <parameter property="begin" />
- <parameter property="increment" />
- </parameterMap>
-
- <select id="getBlackList" resultMap="HummockBlackListResult"
- parameterMap="paramQueryMap">
- SELECT
- <include refid="columns" />
- <![CDATA[
- FROM black_list
- ]]>
- <dynamic prepend="where">
- <isNotEmpty prepend="and" property="appId">
- app_Id = #appId#
- </isNotEmpty>
- <isNotEmpty prepend="and" property="listValue">
- list_value =
- #listValue#
- </isNotEmpty>
- <isNotEmpty prepend="order by" property="sort">
- $sort$ $dir$
- </isNotEmpty>
- </dynamic>
- limit #begin#,#increment#
- </select>
You can use the following methods to perform a self-written conversion:
- Public class PropertyColumnWrapper {
- Private static Logger logger = LoggerFactory. getLogger (PropertyColumnWrapper. class );
-
- Public static String getColumn (String property ){
- If (StringUtils. isBlank (property )){
- Logger. warn ("property shocould not null ");
- Return null;
- }
- StringBuffer buffer = new StringBuffer (property );
- For (int I = 0; I <buffer. length (); I ++ ){
- Char c = buffer. charAt (I );
- If (c> = 'A' & c <= 'Z '){
- // After '_' is inserted, the position is + 1
- Buffer. insert (I ++ ,'_');
- }
- }
- Return buffer. toString ();
- }
-
- Public static String getProperty (String column ){
- If (StringUtils. isBlank (column )){
- Logger. warn ("column shocould not null ");
- Return null;
- }
- Return column. replaceAll ("_","");
- }
- }