亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

SpringBoot+Redis的入門教程

dmlllll / 3365人閱讀

摘要:歷史文章如何在安裝最新版安裝安裝最新版的入門教程教程內(nèi)容備注本系列開發(fā)工具均為構(gòu)建項目,選擇后面發(fā)現(xiàn)其實沒有用到三個基本的依賴。

本博客 貓叔的博客,轉(zhuǎn)載請申明出處

本系列教程為HMStrange項目附帶。

歷史文章

如何在VMware12安裝Centos7.6最新版

Centos7.6安裝Java8

Centos7.6安裝MySQL+Redis(最新版)

SpringBoot+MySQL+MyBatis的入門教程

教程內(nèi)容
備注:本系列開發(fā)工具均為IDEA
1、構(gòu)建項目,選擇Lombok(后面發(fā)現(xiàn)其實沒有用到)、Web、Redis三個基本的Maven依賴。

pom文件



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.4.RELEASE
         
    
    com.github.myself
    redisdemo
    0.0.1-SNAPSHOT
    redisdemo
    Demo project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

2、準備Redis,這里可以參考歷史文章的安裝Redis環(huán)節(jié),我使用Redis Desktop Manager桌面工具進行鏈接

3、構(gòu)建項目目錄,我構(gòu)建了一個普通的web項目目錄,切了dao層,僅僅由service、controller

4、填寫application.yml,默認生成不是yml,不過我覺得yml視覺效果好一些,就改了一下,我們需要填寫Redis鏈接信息
spring:
  redis:
    host: 192.168.192.133
5、構(gòu)建service接口,這里普通實現(xiàn)兩個set、get信息的業(yè)務(wù)
package com.github.myself.service;

/**
 * Created by MySelf on 2019/4/11.
 */
public interface MsgService {

    public String setMsg(String key,String msg);

    public String getMsg(String key);

}
6、接口實現(xiàn),引入RedisTemplate
package com.github.myself.service.impl;

import com.github.myself.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by MySelf on 2019/4/11.
 */
@Service
public class MsgServiceImpl implements MsgService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String setMsg(String key,String msg) {
        redisTemplate.opsForValue().set(key,msg);
        return "success";
    }

    @Override
    public String getMsg(String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }
}
7、controller層的業(yè)務(wù)實現(xiàn)了
package com.github.myself.controller;

import com.github.myself.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by MySelf on 2019/4/11.
 */
@RestController
@RequestMapping("/msg")
public class MsgController {

    @Autowired
    private MsgService msgService;

    @GetMapping("/set")
    public String setMsg(@RequestParam(value = "key") String key,@RequestParam(value = "msg") String msg){
        return msgService.setMsg(key,msg);
    }

    @GetMapping("/get")
    public String getMsg(@RequestParam(value = "key") String key){
        return msgService.getMsg(key);
    }

}
8、啟動項目,使用Postmane測試

9、項目下載地址

歡迎到HMStrange項目進行下載:https://github.com/UncleCatMy...

公眾號:Java貓說

學習交流群:728698035

現(xiàn)架構(gòu)設(shè)計(碼農(nóng))兼創(chuàng)業(yè)技術(shù)顧問,不羈平庸,熱愛開源,雜談程序人生與不定期干貨。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/77545.html

相關(guān)文章

  • SpringBoot非官方教程 | 第十四篇:在springboot中用redis實現(xiàn)消息隊列

    摘要:環(huán)境依賴創(chuàng)建一個新的工程,在其文件加入依賴創(chuàng)建一個消息接收者類,它是一個普通的類,需要注入到中。 這篇文章主要講述如何在springboot中用reids實現(xiàn)消息隊列。 準備階段 安裝redis,可參考我的另一篇文章,5分鐘帶你入門Redis。 java 1.8 maven 3.0 idea 環(huán)境依賴 創(chuàng)建一個新的springboot工程,在其pom文件,加入spring-boot-...

    APICloud 評論0 收藏0
  • SpringBoot非官方教程 | 第九篇: SpringBoot整合Redis

    摘要:經(jīng)過上述兩步的操作,你可以訪問數(shù)據(jù)了。數(shù)據(jù)訪問層通過來訪問分鐘過期單元測試啟動單元測試,你發(fā)現(xiàn)控制臺打印了單元測試通過源碼下載參考資料 這篇文章主要介紹springboot整合redis 引入依賴 在pom文件中添加redis依賴: org.springframework.boot spring-boot-starter-data-redis 配置數(shù)據(jù)源 spri...

    csRyan 評論0 收藏0
  • 兩年了,我寫了這些干貨!

    摘要:開公眾號差不多兩年了,有不少原創(chuàng)教程,當原創(chuàng)越來越多時,大家搜索起來就很不方便,因此做了一個索引幫助大家快速找到需要的文章系列處理登錄請求前后端分離一使用完美處理權(quán)限問題前后端分離二使用完美處理權(quán)限問題前后端分離三中密碼加鹽與中異常統(tǒng)一處理 開公眾號差不多兩年了,有不少原創(chuàng)教程,當原創(chuàng)越來越多時,大家搜索起來就很不方便,因此做了一個索引幫助大家快速找到需要的文章! Spring Boo...

    huayeluoliuhen 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<