中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

開封做網(wǎng)站百度手機導(dǎo)航官方新版

開封做網(wǎng)站,百度手機導(dǎo)航官方新版,網(wǎng)站設(shè)計與制作服務(wù),百度做網(wǎng)站和推廣效果怎么樣文章目錄 SpringBoot項目引入Canal依賴配置文件項目結(jié)構(gòu)設(shè)置監(jiān)聽類其余類、接口內(nèi)容啟動類實體類Controller類Mapper接口Serice接口 運行測試 開始之前請確認docker中已運行mysql與canal容器,并完成了監(jiān)聽binlog配置 未完成可移步: Docker部署Canal監(jiān)聽…

文章目錄

  • SpringBoot項目
    • 引入Canal依賴
    • 配置文件
    • 項目結(jié)構(gòu)
    • 設(shè)置監(jiān)聽類
    • 其余類、接口內(nèi)容
    • 啟動類
    • 實體類
    • Controller類
    • Mapper接口
    • Serice接口
  • 運行
  • 測試

開始之前請確認docker中已運行mysql與canal容器,并完成了監(jiān)聽binlog配置
未完成可移步: Docker部署Canal監(jiān)聽MySQL的binlog

SpringBoot項目

本次在SpringBoot整合Easy-ES實現(xiàn)對ES的基礎(chǔ)操作項目基礎(chǔ)上進行操作
此部分操作請移步:SpringBoot整合Easy-ES實現(xiàn)對ES操作

引入Canal依賴

        <dependency><groupId>top.javatool</groupId><artifactId>canal-spring-boot-starter</artifactId><version>1.2.1-RELEASE</version></dependency>

配置文件

新增以下內(nèi)容
注意修改server,換成自己的canal地址,端口號

canal:server: canal地址:11111destination: example

項目結(jié)構(gòu)

在這里插入圖片描述

設(shè)置監(jiān)聽類

CanalTable注解是監(jiān)聽的表名,實現(xiàn)EntryHandler接口
重寫監(jiān)聽到mysql增刪改操作時,這里的進行自定義操作,方法也都是通過Easy-ES實現(xiàn)

@CanalTable("document")
@Component
public class DocumentHandler implements EntryHandler<Document> {@Resourceprivate IDocumentService documentService;/*** mysql中數(shù)據(jù)有新增時自動執(zhí)行* @param document 新增的數(shù)據(jù)*/@Overridepublic void insert(Document document) {try {documentService.addData(document);} catch (Exception e) {e.printStackTrace();}}/*** mysql中數(shù)據(jù)有修改時自動執(zhí)行* @param before 修改前的數(shù)據(jù)* @param after 修改后的數(shù)據(jù)*/@Overridepublic void update(Document before, Document after) {documentService.updateData(after);}/*** mysql中數(shù)據(jù)有刪除時自動執(zhí)行* @param document 要刪除的數(shù)據(jù)*/@Overridepublic void delete(Document document) {documentService.deleteData(document);}
}

其余類、接口內(nèi)容

啟動類

添加掃描ESMapper的注解,指定路徑

@EsMapperScan("com.mine.easyEs.mapper")

在這里插入圖片描述

實體類

@Data
public class Document {@Id/*** es中的唯一id*/private String id;/*** 文檔標題*/private String title;/*** 文檔內(nèi)容*/private String content;/*** 創(chuàng)建時間*/private Date createTime;
}

Controller類

包括對索引操作和對數(shù)據(jù)進行操作的接口

@RestController
@RequestMapping("/ee")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DocumentController {private final IDocumentService documentService;/*** 創(chuàng)建索引* @return 結(jié)果信息* @throws Exception*/@GetMapping("/createIndex")public String createIndex() throws Exception {return documentService.createIndex();}/*** 刪除索引* @return 結(jié)果信息*/@GetMapping("/deleteIndex")public String deleteIndex(){return documentService.deleteIndex();}/*** 查詢ES所有數(shù)據(jù)* @return 查詢Document結(jié)果對象集合*/@GetMapping("/findAll")public List<Document> findAll(){return documentService.findAllData();}/*** ES新增數(shù)據(jù)* @param document 新增數(shù)據(jù)對象* @return 結(jié)果信息* @throws Exception*/@GetMapping("/add")public String addData(Document document) throws Exception {return documentService.addData(document);}/*** 修改ES數(shù)據(jù)* @param document 修改數(shù)據(jù)對象*/@GetMapping("/update")public String updateData(Document document){return documentService.updateData(document);}/*** 根據(jù)id刪除ES數(shù)據(jù)* @param id 需要刪除的數(shù)據(jù)的id* @return*/@GetMapping("/delete")public String deleteData(String id){return documentService.deleteDataById(id);}/*** 分詞匹配查詢content字段* @param value 查詢內(nèi)容* @return*/@GetMapping("/match")public List<Document> findMatch(String value){return documentService.findMatch(value);}}

Mapper接口

繼承BaseMapper,整體操作都與MybatisPlus類似

public interface DocumentMapper extends BaseEsMapper<Document> {
}

Serice接口

public interface IDocumentService {/*** 查詢ES所有數(shù)據(jù)* @return 查詢Document結(jié)果對象集合*/List<Document> findAllData();/*** 創(chuàng)建索引* @return 結(jié)果信息* @throws Exception*/String createIndex() throws Exception;/*** 刪除索引* @return 結(jié)果信息*/String deleteIndex();/*** ES新增數(shù)據(jù)* @param document 新增數(shù)據(jù)實體類* @return 結(jié)果信息* @throws Exception*/String addData(Document document) throws Exception;/*** 根據(jù)id刪除ES數(shù)據(jù)* @param id 需要刪除的數(shù)據(jù)的id* @return*/String deleteDataById(String id);String deleteData(Document document);/*** 修改ES數(shù)據(jù)* @param document 修改數(shù)據(jù)對象*/String updateData(Document document);/*** 分詞匹配查詢content字段* @param value 查詢內(nèi)容* @return*/List<Document> findMatch(String value);
}

Service實現(xiàn)類

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DocumentServiceImpl implements IDocumentService {private final DocumentMapper documentMapper;/*** 查詢ES所有數(shù)據(jù)* @return 查詢Document結(jié)果對象集合*/@Overridepublic List<Document> findAllData() {LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();wrapper.matchAllQuery();return documentMapper.selectList(wrapper);}/*** 創(chuàng)建索引* @return 結(jié)果信息* @throws Exception*/@Overridepublic String createIndex() throws Exception {StringBuilder msg = new StringBuilder();String indexName = Document.class.getSimpleName().toLowerCase();boolean existsIndex = documentMapper.existsIndex(indexName);if (existsIndex){throw new Exception("Document實體對應(yīng)索引已存在,刪除索引接口:deleteIndex");}boolean success = documentMapper.createIndex();if (success){msg.append("Document索引創(chuàng)建成功");}else {msg.append("索引創(chuàng)建失敗");}return msg.toString();}/*** 刪除索引* @return 結(jié)果信息*/@Overridepublic String deleteIndex() {StringBuilder msg = new StringBuilder();String indexName = Document.class.getSimpleName().toLowerCase();if (documentMapper.deleteIndex(indexName)){msg.append("刪除成功");}else {msg.append("刪除失敗");}return msg.toString();}/*** ES新增數(shù)據(jù)* @param document 新增數(shù)據(jù)實體類* @return 結(jié)果信息* @throws Exception*/@Overridepublic String addData(Document document) throws Exception {if (StringUtils.isEmpty(document.getTitle()) || StringUtils.isEmpty(document.getContent())) {throw new Exception("請補全title及content數(shù)據(jù)");}document.setCreateTime(new Date());documentMapper.insert(document);return "Added successfully!";}/*** 根據(jù)id刪除ES數(shù)據(jù)* @param id 需要刪除的數(shù)據(jù)的id* @return*/@Overridepublic String deleteDataById(String id) {documentMapper.deleteById(id);return "Success";}@Overridepublic String deleteData(Document document) {documentMapper.deleteById(document.getId());return "Success";}/*** 修改ES數(shù)據(jù)* @param document 修改數(shù)據(jù)對象*/@Overridepublic String updateData(Document document) {documentMapper.updateById(document);return "Success";}/*** 分詞匹配查詢content字段* @param value 查詢內(nèi)容* @return*/@Overridepublic List<Document> findMatch(String value) {LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();wrapper.match(Document::getContent,value);wrapper.orderByDesc(Document::getCreateTime);List<Document> documents = documentMapper.selectList(wrapper);return documents;}
}

運行

可以看到,正在監(jiān)聽,只不過目前我們沒有對數(shù)據(jù)庫進行操作。
在這里插入圖片描述

測試

我們在數(shù)據(jù)庫新增一條數(shù)據(jù)
在這里插入圖片描述
此時插入的這條數(shù)據(jù)被監(jiān)聽到了
在這里插入圖片描述

通過測試方法查看ES中是否插入了這條數(shù)據(jù)

@Testpublic void testSelect() {// 測試查詢String title = "3";Document document = EsWrappers.lambdaChainQuery(documentMapper).eq(Document::getTitle, title).one();System.out.println(document);Assertions.assertEquals(title,document.getTitle());}

在這里插入圖片描述
查到了在mysql新插入的這條數(shù)據(jù)
數(shù)據(jù)同步成功

http://www.risenshineclean.com/news/1696.html

相關(guān)文章:

  • 第一家中文商務(wù)網(wǎng)站明年2024年有疫情嗎
  • 湖南省住房城鄉(xiāng)建設(shè)廳網(wǎng)站磁力搜索
  • 做網(wǎng)站主要欄目內(nèi)競價托管信息
  • 網(wǎng)站后臺如何做做搜索引擎優(yōu)化的企業(yè)
  • 門戶網(wǎng)站開發(fā)報價單企業(yè)的網(wǎng)絡(luò)推廣
  • 文山州住房建設(shè)網(wǎng)站企業(yè)網(wǎng)絡(luò)推廣計劃
  • 微信小程序模版廣州seo網(wǎng)站推廣公司
  • 南通高端網(wǎng)站建設(shè)公司培訓(xùn)網(wǎng)頁
  • 承德做網(wǎng)站優(yōu)化搜狗網(wǎng)址大全
  • 國內(nèi)產(chǎn)品推廣網(wǎng)站廣州市疫情最新情況
  • 編程和做網(wǎng)站有關(guān)系嗎招商外包
  • 微信api文檔徐州seo代理計費
  • 泉州市住房與城鄉(xiāng)建設(shè)局網(wǎng)站seo外鏈是什么意思
  • 手機網(wǎng)站 pc網(wǎng)站模板百度近日收錄查詢
  • 深圳疫情防控最新通知seo網(wǎng)站關(guān)鍵詞優(yōu)化
  • 怎么判斷網(wǎng)站建設(shè)年齡新媒體運營主要做什么
  • 網(wǎng)站寶 西部數(shù)碼網(wǎng)站管理助手廣告最多的網(wǎng)站
  • 淘寶客優(yōu)惠券網(wǎng)站建設(shè)加盟官網(wǎng)怎么做百度推廣運營
  • 網(wǎng)站模板可視化編輯百度霸屏培訓(xùn)
  • php企業(yè)網(wǎng)站源代碼如何自己搭建網(wǎng)站
  • 懷化三中網(wǎng)站營銷活動
  • 類似于wordpress搜索引擎seo推廣
  • 3合1網(wǎng)站建設(shè)公司網(wǎng)絡(luò)營銷策劃的具體流程是
  • 網(wǎng)站建設(shè)qianhaiyouseo是什么職位的簡稱
  • web網(wǎng)站開發(fā)歷史河南網(wǎng)站關(guān)鍵詞優(yōu)化代理
  • 工程施工合同協(xié)議書范本什么是seo營銷
  • 網(wǎng)站建設(shè)一意見搜索引擎入口google
  • 阿里云oss做網(wǎng)站白度
  • 百度做公司網(wǎng)站有用嗎淘寶seo搜索引擎原理
  • 有規(guī)范seo 關(guān)鍵詞優(yōu)化