Browse Source

1、依赖
2、测试数据库的代码

yegang 2 năm trước cách đây
mục cha
commit
0a477dcfc9

+ 36 - 2
pom.xml

@@ -24,14 +24,48 @@
         </dependency>
 
         <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- mysql -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.47</version>
+        </dependency>
+        <!-- mybatis plus -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.0.7.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-activemq</artifactId>
+            <version>2.0.0.RELEASE</version>
+        </dependency>
+        <!-- lombok -->
+        <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <optional>true</optional>
         </dependency>
+        <!-- redis -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <!--hutool工具类-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-core</artifactId>
+            <version>4.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>4.5.7</version>
         </dependency>
     </dependencies>
 

+ 3 - 0
src/main/java/com/sw/MaskApplication.java

@@ -1,8 +1,11 @@
 package com.sw;
 
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+
+@MapperScan("com.sw.dao")
 @SpringBootApplication
 public class MaskApplication {
 

+ 9 - 0
src/main/java/com/sw/controller/TestController.java

@@ -1,9 +1,14 @@
 package com.sw.controller;
 
+import com.sw.domain.SysTest;
+import com.sw.service.SysTestService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * 测试服务
  *
@@ -12,8 +17,12 @@ import org.springframework.web.bind.annotation.RestController;
  **/
 @RestController
 public class TestController {
+    @Autowired
+    SysTestService sysTestService;
     @RequestMapping("/test")
     public  String  test(){
+        List<SysTest> list = sysTestService.list();
+        System.out.println(list);
         return "test";
     }
 }

+ 15 - 0
src/main/java/com/sw/dao/SysTestDao.java

@@ -0,0 +1,15 @@
+package com.sw.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sw.domain.SysTest;
+
+/**
+ * (SysTest)表数据库访问层
+ *
+ * @author yegang
+ * @since 2022-02-17 16:35:24
+ */
+public interface SysTestDao extends BaseMapper<SysTest> {
+
+
+}

+ 28 - 0
src/main/java/com/sw/domain/SysTest.java

@@ -0,0 +1,28 @@
+package com.sw.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * (SysTest)实体类
+ *
+ * @author yegang
+ * @since 2022-02-17 16:35:22
+ */
+@Data
+@TableName("sys_test")
+public class SysTest implements Serializable {
+    private static final long serialVersionUID = 734298413127804175L;
+    /**
+     * 主键
+     */
+    private Integer id;
+    /**
+     * 名称
+     */
+    private String name;
+
+
+}

+ 15 - 0
src/main/java/com/sw/service/SysTestService.java

@@ -0,0 +1,15 @@
+package com.sw.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.sw.domain.SysTest;
+
+/**
+ * (SysTest)表服务接口
+ *
+ * @author yegang
+ * @since 2022-02-17 16:35:26
+ */
+public interface SysTestService extends IService<SysTest> {
+
+
+}

+ 23 - 0
src/main/java/com/sw/service/impl/SysTestServiceImpl.java

@@ -0,0 +1,23 @@
+package com.sw.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sw.dao.SysTestDao;
+import com.sw.domain.SysTest;
+import com.sw.service.SysTestService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * (SysTest)表服务实现类
+ *
+ * @author yegang
+ * @since 2022-02-17 16:35:27
+ */
+@Service("sysTestService")
+public class SysTestServiceImpl extends ServiceImpl<SysTestDao, SysTest> implements SysTestService {
+    @Resource
+    private SysTestDao sysTestDao;
+
+
+}

+ 40 - 0
src/main/resources/application.yml

@@ -3,3 +3,43 @@ server:
 spring:
   application:
     name: mask
+  datasource:
+    url: jdbc:mysql://124.70.152.102:3306/mask
+    username: sunwin
+    password: Sunwin@2020
+    driver-class-name: com.mysql.jdbc.Driver
+  redis:
+    # 数据库索引,默认0
+    database: 4
+    #    # 服务器IP地址
+    host: 192.168.20.83
+    # 连接端口
+    port: 6379
+    # Redis服务器连接密码(默认为空)
+    password: sunwin
+  activemq:
+    user: admin    # 连接用户名
+    password: admin   # 连接密码
+    broker-url: tcp://192.168.20.76:28085 # 消息组件的连接主机信息
+    packages:
+      trust-all: true
+mybatis-plus:
+  # 指向实体类包路径
+  type-aliases-package: com.sw.domain
+  # mapper xml 文件地址
+  mapper-locations: classpath:mapper/*.xml
+  # 检查 mybatis 配置是否存在,一般命名为 mybatis-config.xml
+  check-config-location: true
+  # 执行模式。默认是 SIMPLE
+  executor-type: simple
+  #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+  global-config:
+    db-config:
+      id-type: auto
+  #      logic-delete-value: 9 #默认值9
+  #      logic-not-delete-value: 0 #默认值0
+  configuration:
+    variables:
+      nextTermDays: 90
+      #mybatis-plus配置控制台打印完整带参数SQL语句
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 6 - 0
src/main/resources/mapper/SysTestMapper.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sw.dao.SysTestDao">
+
+
+</mapper>