mybatis annotation select query with parameter which is use multiple times in conditions -
i have problem mybatis annotation query following error.
org.apache.ibatis.binding.bindingexception: parameter 'strdatestart' not found. available parameters [0, 1, param1, param2]
the following code in mapper class.
`@select("select * result where"and proc_date >= '#{strdatestart}'"+ "and proc_date >= '#{strdateend}'"+ "and update_date <= '#{strdatestart}'"+ "and update_date <= '#{strdateend}'") public arraylist<resultdao> select(string strdatestart,string strdateend);`
giving same name parameters in query , args in method , can use multiple times in conditions same parameter?
the problem solved
1. delete single quotes surround variables #{strdatexxxx}
2. creating class conditions below code.
`public class selectconditions { string strdatestart; string strdateend; public string getstrdatestart() { return strdatestart; } public void setstrdatestart(string strdatestart) { this.strdatestart = strdatestart; } public string getstrdateend() { return strdateend; } public void setstrdateend(string strdateend) { this.strdateend = strdateend; } public selectconditions(string strdatestart, string strdateend) { this.strdatestart = strdatestart; this.strdateend = strdateend; }`
3. change mapper class passing condition class
`@select("select * result where"and proc_date >= #{strdatestart}"+ "and proc_date >= #{strdateend}"+ "and update_date <= #{strdatestart}"+ "and update_date <= #{strdateend}") public arraylist select(selectconditions conditions)`
Comments
Post a Comment