DAO 、Service 、 Controller 層
- DAO 層負(fù)責(zé)數(shù)據(jù)庫訪問,它封裝了對數(shù)據(jù)庫的訪問操作,例如查詢、插入、更新和刪除等。
@Query("select ol from OperaterLog ol where id =:aaid")
OperaterLog find(@Param("aaid")Long id);
- Service 層負(fù)責(zé)業(yè)務(wù)邏輯,Service 層位于 DAO 層之上,Service 層可以調(diào)用多個 DAO 層的接口來完成復(fù)雜的業(yè)務(wù)操作,也可以將多個 DAO 層的接口組合成一個新的接口,并將其返回給客戶端。Service 層的主要目的是將業(yè)務(wù)邏輯與數(shù)據(jù)庫訪問邏輯分離,使得程序員可以更容易地管理和維護(hù)業(yè)務(wù)邏輯。
public OperaterLog FindById(Long id){
return operatorLogDao.find(id);
}
- Controller 層負(fù)責(zé)客戶端請求處理,Controller 層位于 Service 層之上,Controller 層可以根據(jù)客戶端的請求調(diào)用相應(yīng)的 Service 層的接口來完成業(yè)務(wù)操作,并將處理結(jié)果返回給客戶端。Controller 層的主要目的是將客戶端與 Service 層分離,使得程序員可以更容易地管理和維護(hù)客戶端邏輯。
public OperaterLog index(Long id){
return operatorlogservice.FindById(id);
}
- 三層之間通過接口進(jìn)行交互,實(shí)現(xiàn)了業(yè)務(wù)邏輯和數(shù)據(jù)庫訪問邏輯的分離,使得程序員可以更容易地管理和維護(hù)代碼。
控制器文件
示例代碼-單個查找
@RequestMapping(value="/dbfind")
@ResponseBody
public OperaterLog index(Long id){
OperaterLog findById=operatorlogservice.FindById(id);
if(findById!=null){
OperaterLog operaterLog=new OperaterLog();
operaterLog.setId(findById.getId());
operaterLog.setOperator(findById.getOperator());
operaterLog.setCreateTime(findById.getCreateTime());
operaterLog.setUpdateTime(findById.getUpdateTime());
operaterLog.setContent(findById.getContent());
return operaterLog;
}
return null;
}
查找成功
示例代碼-列表查找
public List<OperaterLog> index(Long id){
return operatorlogservice.FindALL();
}
查找成功
文章來源:http://www.zghlxwxcb.cn/news/detail-730097.html
示例代碼-刪除
public Boolean index(Long id){
operatorlogservice.delete(id);
return true;
}
刪除成功
文章來源地址http://www.zghlxwxcb.cn/news/detail-730097.html
到了這里,關(guān)于Spring Boot:利用JPA進(jìn)行數(shù)據(jù)庫的查刪的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!