我有这种情况。这是我的Village.java
:
public class Village{
private Integer vid;
private String villageName;
private String district;
public Integer getVid() {
return vid;
}
public void setVid(Integer vid) {
this.vid = vid;
}
public String getVillageName() {
return villageName;
}
public void setVillageName(String villageName) {
this.villageName = villageName;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
}
这是我的Dao.java
界面:
public interface Dao<T> {
public void insert();
public void update();
public void delete();
}
这是我的方面Village_Dao.aj
(你可以忽略静态方法逻辑):
import org.apache.ibatis.session.SqlSession;
import com.madx.finance.data.utils.persistence.Dao;
import com.madx.finance.data.utils.factory.ConnectionFactory;
public aspect Village_Dao {
declare parents: Village implements Dao<Village>;
public void Village.insert() {
Village.insertVillage(this);
}
public void Village.update() {
Village.updateVillage(this);
}
public void Village.delete() {
Village.deleteVillage(this.getVid());
}
public Village Village.getData() {
return Village.getDataVillage(this.getVid());
}
public static void Village.insertVillage(Village village) {
SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession();
VillageMapper mapper = session.getMapper(VillageMapper.class);
mapper.insertVillage(village);
session.commit();
session.close();
}
public static void Village.updateVillage(Village village) {
SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession();
VillageMapper mapper = session.getMapper(VillageMapper.class);
mapper.updateVillage(village);
session.commit();
session.close();
}
public static void Village.deleteVillage(Integer id) {
SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession();
VillageMapper mapper = session.getMapper(VillageMapper.class);
mapper.deleteVillage(id);
session.commit();
session.close();
}
public static Village Village.getDataVillage(Integer id) {
SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession();
VillageMapper mapper = session.getMapper(VillageMapper.class);
Village village = mapper.selectVillage(id);
session.close();
return village;
}
}
我正在尝试将其转换Village_Dao.aj
为带注释的版本,但没有成功Village_Dao_Java.java
。我只是设法使该类实现了 Dao,但我无法编写方法(在此文件中分别插入、更新和删除Village_Dao_Java.java
)。
这是Village_Dao_Java.java
(我阅读了这个链接但我无法让它适用于这种情况)的版本(仍然不完整):
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
import com.madx.finance.data.utils.persistence.Dao;
@Aspect
public class Village_Dao_Java {
@DeclareParents("com.madx.demo.Village")
private Dao<Village> implementedInterface;
}