Qing 11 сар өмнө
parent
commit
c2348a899f

+ 6 - 0
novel-demo/pom.xml

@@ -116,6 +116,12 @@
             <scope>runtime</scope>
             <scope>runtime</scope>
         </dependency>
         </dependency>
 
 
+        <!-- springboot整合redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+
     </dependencies>
     </dependencies>
 
 
     <build>
     <build>

+ 21 - 0
novel-demo/src/main/java/com/sf/config/SwaggerConfig.java

@@ -0,0 +1,21 @@
+package com.sf.config;
+
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.info.License;
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.info.Info;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+//@OpenAPIDefinition(info = @io.swagger.v3.oas.annotations.info.Info(title = "novel 项目接口文档", version = "v3.2.0", license = @License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0")))
+@Configuration
+public class SwaggerConfig {
+
+    @Bean
+    public OpenAPI openAPI(){
+        OpenAPI openAPI = new OpenAPI();
+        openAPI.info(
+                new Info().title("阅读类门户网站").description("基于springboot和mybatis-plus实现").version("v1.0"));
+        return openAPI;
+    }
+}

+ 6 - 1
novel-demo/src/main/java/com/sf/controller/BookInfoController.java

@@ -8,7 +8,9 @@ import com.sf.dto.resp.BookRankRespDto;
 import com.sf.dto.resp.PageRespDto;
 import com.sf.dto.resp.PageRespDto;
 import com.sf.entity.BookInfo;
 import com.sf.entity.BookInfo;
 import com.sf.service.IBookInfoService;
 import com.sf.service.IBookInfoService;
+import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -23,6 +25,7 @@ import java.util.List;
  * @author baomidou
  * @author baomidou
  * @since 2024-05-25
  * @since 2024-05-25
  */
  */
+@Tag(name = "BookInfoController",description = "小说信息模块")
 @RestController
 @RestController
 //@RequestMapping("/api/front/book")
 //@RequestMapping("/api/front/book")
 public class BookInfoController {
 public class BookInfoController {
@@ -37,9 +40,11 @@ public class BookInfoController {
         return bookInfoService.list();
         return bookInfoService.list();
     }
     }
 
 
+    @Operation(summary = "小说信息查询接口")
     // http://127.0.0.1:8888/api/front/book/{id}
     // http://127.0.0.1:8888/api/front/book/{id}
     @GetMapping("/api/front/book/{id}")
     @GetMapping("/api/front/book/{id}")
-    public RestResp<BookInfoRespDto> getBookInfoById(@PathVariable Long id){
+    public RestResp<BookInfoRespDto> getBookInfoById(
+            @Parameter(description = "小说id") @PathVariable("id") Long id){
         // getById是mybatis plus提供的方法
         // getById是mybatis plus提供的方法
         // 从对应表中 where id = '' 中的数据取出
         // 从对应表中 where id = '' 中的数据取出
         // mapper中 对应的方法叫  selectById
         // mapper中 对应的方法叫  selectById

+ 5 - 0
novel-demo/src/main/java/com/sf/jdk17/Car.java

@@ -0,0 +1,5 @@
+package com.sf.jdk17;
+
+// 在声明实现类的时候  被non-sealed 不封闭的 关键词来描述
+public non-sealed class Car implements Service{
+}

+ 84 - 0
novel-demo/src/main/java/com/sf/jdk17/Demo.java

@@ -0,0 +1,84 @@
+package com.sf.jdk17;
+
+public class Demo {
+
+    public static void main(String[] args) {
+        // 1、变量声明  支持var
+        var abc = 1;
+
+        // 2、switch使用 支持更多写法
+        String x = "3";
+        int i;
+        switch (x) {
+            case "1":
+                i = 1;
+                break;
+            case "2":
+                i = 2;
+                break;
+            default:
+                i = x.length();
+                break;
+
+        }
+
+        // jdk13 在switch中支持lambda表达式
+        int i1 = switch (x) {
+            case "1" -> 1;
+            case "2" -> 2;
+            default -> {
+                int len = x.length();
+                yield len;
+            }
+        };
+
+        int i2 = switch (x) {
+            case "1":
+                yield 1;   // 使用yield代替break -》 i = 1;break;
+            case "2":
+                yield 2;
+            default: {
+                int len = x.length();
+                yield len;
+            }
+        };
+
+        // 3、文本块
+        String str = "111111111111" +
+                "222" +
+                "2" +
+                "2";
+
+        String str1 = """
+                1111111111
+                111
+                111
+                11
+                """;
+
+        // 4、封闭的接口  只能通过被允许的类来实现
+//        public sealed interface Service permits Car {
+//
+//        }
+//         在声明实现类的时候  被non-sealed 不封闭的 关键词来描述
+//        public non-sealed class Car implements Service{
+//        }
+
+        // 5、instanceof的使用
+        Object number = "1";
+        if (number instanceof Integer) {
+            Integer iNum = (Integer) number;
+            System.out.println(iNum);
+        } else if (number instanceof String) {
+            String strNum = (String) number;
+        }
+
+        if (number instanceof Integer iNum) {
+            System.out.println(iNum);
+        } else if(number instanceof String strNum) {
+        }
+
+        // 6、进一步在使用switch时,可以替代对instanceof的多重判断
+
+    }
+}

+ 6 - 0
novel-demo/src/main/java/com/sf/jdk17/Service.java

@@ -0,0 +1,6 @@
+package com.sf.jdk17;
+
+// 封闭的接口  只能通过被允许的类来实现
+public sealed interface Service permits Car {
+
+}

+ 5 - 0
novel-demo/src/main/resources/application.yml

@@ -23,3 +23,8 @@ spring:
       # 由于 Javascript 标准规定所有数字处理都应使用 64 位 IEEE 754 浮点值完成,
       # 由于 Javascript 标准规定所有数字处理都应使用 64 位 IEEE 754 浮点值完成,
       # 结果是某些 64 位整数值无法准确表示(尾数只有 51 位宽)
       # 结果是某些 64 位整数值无法准确表示(尾数只有 51 位宽)
       write-numbers-as-strings: true
       write-numbers-as-strings: true
+  data:
+    redis:
+      host: localhost
+      port: 6379
+      password:

+ 17 - 10
novel-demo/src/test/java/com/sf/NovelDemoApplicationTests.java

@@ -36,8 +36,8 @@ class NovelDemoApplicationTests {
 //        List<BookInfo> bookInfos = bookInfoMapper.selectList(null);
 //        List<BookInfo> bookInfos = bookInfoMapper.selectList(null);
         // 使用条件构造器
         // 使用条件构造器
         QueryWrapper queryWrapper = new QueryWrapper();
         QueryWrapper queryWrapper = new QueryWrapper();
-        queryWrapper.eq("category_name","历史军事");
-        queryWrapper.eq("author_name","当年明月");
+        queryWrapper.eq("category_name", "历史军事");
+        queryWrapper.eq("author_name", "当年明月");
         // where id = '1337762752513486849'
         // where id = '1337762752513486849'
         List<BookInfo> bookInfos1 = bookInfoMapper.selectList(queryWrapper);
         List<BookInfo> bookInfos1 = bookInfoMapper.selectList(queryWrapper);
         System.out.println(bookInfos1);
         System.out.println(bookInfos1);
@@ -45,8 +45,8 @@ class NovelDemoApplicationTests {
         // 使用lambda表达式的条件构造器
         // 使用lambda表达式的条件构造器
         // :: 类的方法
         // :: 类的方法
         LambdaQueryWrapper<BookInfo> queryWrapper1 = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<BookInfo> queryWrapper1 = new LambdaQueryWrapper<>();
-        queryWrapper1.eq(BookInfo::getCategoryName,"历史军事");
-        queryWrapper1.eq(BookInfo::getAuthorName,"当年明月");
+        queryWrapper1.eq(BookInfo::getCategoryName, "历史军事");
+        queryWrapper1.eq(BookInfo::getAuthorName, "当年明月");
         List<BookInfo> bookInfos2 = bookInfoMapper.selectList(queryWrapper1);
         List<BookInfo> bookInfos2 = bookInfoMapper.selectList(queryWrapper1);
         System.out.println(bookInfos2);
         System.out.println(bookInfos2);
 
 
@@ -58,23 +58,23 @@ class NovelDemoApplicationTests {
     // 练习  筛选访问次数visit_count > 200 且  书籍字数 word_count < 400000 的书籍
     // 练习  筛选访问次数visit_count > 200 且  书籍字数 word_count < 400000 的书籍
 
 
     @Test
     @Test
-    public void test(){
+    public void test() {
         QueryWrapper queryWrapper = new QueryWrapper();
         QueryWrapper queryWrapper = new QueryWrapper();
-        queryWrapper.gt("visit_count","200");
-        queryWrapper.lt("word_count","400000");
+        queryWrapper.gt("visit_count", "200");
+        queryWrapper.lt("word_count", "400000");
         List<BookInfo> bookInfos1 = bookInfoMapper.selectList(queryWrapper);
         List<BookInfo> bookInfos1 = bookInfoMapper.selectList(queryWrapper);
         System.out.println(bookInfos1.size());
         System.out.println(bookInfos1.size());
         System.out.println(bookInfos1);
         System.out.println(bookInfos1);
     }
     }
 
 
     @Test
     @Test
-    public void test1(){
+    public void test1() {
         System.out.println(corsProperties);
         System.out.println(corsProperties);
     }
     }
 
 
 
 
     @Test
     @Test
-    public void test2(){
+    public void test2() {
 //        IPage<BookInfo> page = new Page<>(1,10);
 //        IPage<BookInfo> page = new Page<>(1,10);
         IPage<BookInfo> page = new Page<>();
         IPage<BookInfo> page = new Page<>();
         // 当前页数  页面大小
         // 当前页数  页面大小
@@ -90,7 +90,7 @@ class NovelDemoApplicationTests {
 
 
 
 
     @Test
     @Test
-    public void test3(){
+    public void test3() {
 //        IPage<BookInfo> page = new Page<>(1,10);
 //        IPage<BookInfo> page = new Page<>(1,10);
         IPage<BookInfo> page = new Page<>();
         IPage<BookInfo> page = new Page<>();
         // 当前页数  页面大小
         // 当前页数  页面大小
@@ -103,4 +103,11 @@ class NovelDemoApplicationTests {
         System.out.println(bookInfos);
         System.out.println(bookInfos);
     }
     }
 
 
+
+    @Test
+    public void test4() {
+
+
+    }
+
 }
 }

+ 20 - 0
novel-demo/src/test/java/com/sf/RedisTests.java

@@ -0,0 +1,20 @@
+package com.sf;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.redis.core.RedisTemplate;
+
+@SpringBootTest
+public class RedisTests {
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    @Test
+    public void test() {
+        redisTemplate.opsForValue().set("k111", "v111");
+        Object object = redisTemplate.opsForValue().get("k111");
+        System.out.println(object);
+    }
+}