When multiple parameters are entered in ibatis, you can find that only one of the input parameters is allowed. Therefore, when multiple input parameters are required, you need to find a solution, I see the following two better methods to solve this problem:
1) Use string instead
<Select id = "checklogin" parameterclass = "Java. Lang. String" resultclass = "Java. Lang. Integer">
Select count (*) as value from userinfo where $ SQL $
</SELECT>
For example, in the map statement code above, set the input parameter to the string type, and directly use this string in the SELECT statement, therefore, you can manually implant the parameters to be matched in the Java program code.
String SQL = "uid = '" + username + "' and Pwd = '" + password + "'";
Integer r = (integer) sqlmap. queryforobject ("checklogin", SQL );
This method is simple, but it has many drawbacks. First, you must manually write the SQL statement code in Java. This is against the nature of ibatis to separate the operations at the data layer from the business logic operations. Second, this method may be exploited to cause SQL Injection problems. For example, add a sentence at the end of the SQL statement; drop some table. The results are obvious and catastrophic.
2) Use Map
<Select id = "checklogin2" parameterclass = "Java. util. Map" resultclass = "Java. Lang. Integer">
Select count (*) as value from userinfo where uid = # uid # And Pwd = # PWD #
</SELECT>
This method is much clearer, and you do not need to manually write SQL into Java.
Map map = new hashmap ();
Map. Put ("uid", username );
Map. Put ("PWD", password );
Integer r = (integer) sqlmap. queryforobject ("checklogin2", MAP );
Generate the required map in Java and pass it in as an input parameter. This method should be good and recommended.
3) Some people use the method of compiling JavaBean as needed, but the disadvantage of this method is that if your logical operation involves a lot of combinations of different attributes, you will waste a lot of resources to generate various beans.
Ibatis multiple parameters