@Retention(value=RUNTIME) @Target(value=METHOD) public @interface BindSqlDelete
For example suppose we persist bean Person defined as follow:
@BindType
public class Person {
public long id;
public String name;
public String surname;
public String birthCity;
public Date birthDay;
}
The associated DAO interface is
@BindDao(Person.class)
public interface PersonDAO {
}
It's possible define a DELETE query with annotation BindSqlDelete. It is possibile to define query parameter simply using method parameter with same name of the bean property.
@BindDao(Person.class)
public interface PersonDAO {
@BindDelete(where="name=${name} and surname=${surname}")
void deleteOne(String name, @BindSqlParam("surname") temp);
@BindDelete(where="name=${name} and surname=${surname}")
long deleteTwo(String name, @BindSqlParam("surname") temp);
}
Each method parameter will be use like input parameter for query. The name of parameters will be used to map field bean and then the column name of the associated table. If you specify a return type for methods (like method
insertTwo), it has to be of type int, long, Integer, Long. In this case, the return value will be the id value of just inserted row.
The other way to define an INSERT query is using a bean as input parameter:
@BindDao(Person.class)
public interface PersonDAO
{
@BindDelete(where=" id = ${bean.id} ")
void deleteThree(Person bean);
}
You can use attribute value to define which property insert into query or you can use attribute excludedFields to avoid to insert some fields,
but you can not use both attributes in the same method definition. Values of this attribute will be used like bean property name. At the end of the insert, bean will have id value set to last row id used to insert bean into
table. If you specify a return type for methods, it has to be of type int, long, Integer, Long and it will contains same value like row id.
public abstract String where
Copyright © 2017. All rights reserved.