我有這種情況。 這是我Village.java
:使用Aspect註釋將Inter-Type中的.aj轉換爲.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
中單獨插入,更新e刪除)。
這是Village_Dao_Java.java
(我讀這link,但我無法得到它的這種情況下工作)的版本(還沒有完成):
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;
}
是的,我同意這正是我在這些日子裏達成的結論。我試圖用java保留所有的東西,但正如你告訴我的那樣,這個選擇背後並沒有真正的原因,它只是兩種方法之間的比較練習。但是在java中沒有辦法做到這一點,「這個」問題是主要原因。謝謝! – madx