diff --git a/nacos-server-producer/pom.xml b/nacos-server-producer/pom.xml
index 1e8f0eb61af02545f40508622a82f6b8f562c5e9..dce3eda8f2c06346d4f8e4facb0c9b5ef00d2119 100644
--- a/nacos-server-producer/pom.xml
+++ b/nacos-server-producer/pom.xml
@@ -2,18 +2,14 @@
4.0.0
-
com.kwan.springcloudalibaba
nacos-server-parent
1.0.0-SNAPSHOT
-
-
nacos-server-producer
nacos-server-producer
nacos-server-producer
-
1.8
UTF-8
@@ -27,12 +23,10 @@
nacos-server-common
1.0.0
-
org.springframework.boot
spring-boot-starter-web
-
org.springframework.boot
spring-boot-starter-test
@@ -54,6 +48,30 @@
org.projectlombok
lombok
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.4.3
+
+
+ com.alibaba
+ druid
+ 1.2.3
+
+
+ org.apache.commons
+ commons-lang3
+ 3.9
+
+
+ mysql
+ mysql-connector-java
+ 8.0.11
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ 1.1.10
+
-
-
+
\ No newline at end of file
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/NacosProducerApplication.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/NacosProducerApplication.java
index b3541f1c348e1b3f02ebd092b70f8bf560f9485a..8ade0276b9db4c50a7d3b70ebbc1edc0e2ad62d9 100644
--- a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/NacosProducerApplication.java
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/NacosProducerApplication.java
@@ -2,6 +2,7 @@ package com.kwan.springcloudalibaba;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
@@ -11,10 +12,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @version : 2.2.0
* @date : 2023/1/17 12:37
*/
-@SpringBootApplication
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class NacosProducerApplication {
public static void main(String[] args) {
SpringApplication.run(NacosProducerApplication.class, args);
+ System.out.println("-----------------------nacos-server-producer启动成功-----------------------");
}
}
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..97820296b00711f9d6fea7cd386ff3dfe2d9b35d
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/config/MyBatisPlusConfig.java
@@ -0,0 +1,31 @@
+package com.kwan.springcloudalibaba.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * mybatisplus配置
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2022/12/19 16:11
+ */
+@MapperScan("com.kwan.springcloudalibaba.mapper")//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
+@Configuration //配置类
+public class MyBatisPlusConfig {
+
+ @Bean
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
+ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+ //注册乐观锁插件
+ interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+ //分页插件
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+ return interceptor;
+ }
+}
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
index dc8989c585130dfe041efae78c185c179533edc6..adde51ac48b541f703de50e2c7f5204eb6013835 100644
--- a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/NacosProducerController.java
@@ -1,7 +1,6 @@
package com.kwan.springcloudalibaba.controller;
import com.kwan.springcloudalibaba.common.Result;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
@@ -14,16 +13,13 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/nacos/producer")
public class NacosProducerController {
- @Value("${user.name}")
- private String nameInfo;
-
/**
* 获取配置的变量
*/
@GetMapping(value = "/nameInfo", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result nameInfo() {
- return Result.ok(nameInfo);
+ return Result.ok();
}
}
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
new file mode 100644
index 0000000000000000000000000000000000000000..f43a54c456b9b0f2eb03f797f097601daec985b4
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/controller/UserController.java
@@ -0,0 +1,44 @@
+package com.kwan.springcloudalibaba.controller;
+
+
+import com.kwan.springcloudalibaba.entity.User;
+import com.kwan.springcloudalibaba.service.IUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 用户相关
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2022/12/19 16:08
+ */
+@Slf4j
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+ @Autowired
+ private IUserService userService;
+
+ @RequestMapping(value = "/all", method = RequestMethod.GET)
+ public List addAdvertise() {
+ log.info("测试日志={}", "success");
+ return userService.getUsers();
+ }
+
+
+ @RequestMapping(value = "/getUserById/{id}", method = RequestMethod.GET)
+ public User getUserById(@PathVariable Integer id) {
+ return userService.getUserById(id);
+ }
+
+
+ @RequestMapping(value = "/getUserByName", method = RequestMethod.GET)
+ public User getUserByName(@RequestParam String sex) {
+ return userService.getUserByName(sex);
+ }
+}
\ No newline at end of file
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/entity/User.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/entity/User.java
new file mode 100644
index 0000000000000000000000000000000000000000..1ba8ddaffad668e68ccbb8079e28f88e25446f47
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/entity/User.java
@@ -0,0 +1,24 @@
+package com.kwan.springcloudalibaba.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@TableName(value = "user")
+@AllArgsConstructor
+@NoArgsConstructor
+public class User {
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ private String name;
+
+ private String sex;
+}
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..16e7053a09b54b5b499edbea1f54f96e7b1c4be5
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/mapper/UserMapper.java
@@ -0,0 +1,20 @@
+package com.kwan.springcloudalibaba.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.kwan.springcloudalibaba.entity.User;
+import org.apache.ibatis.annotations.Mapper;
+
+
+/**
+ * mapper文件
+ *
+ * @author : qinyingjie
+ * @version : 2.2.0
+ * @date : 2022/12/19 16:12
+ */
+@Mapper
+public interface UserMapper extends BaseMapper {
+
+ User getUserByName(String sex);
+}
+
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
new file mode 100644
index 0000000000000000000000000000000000000000..da7a0d7b124d8625e6906b18268ddb12eb55a504
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/IUserService.java
@@ -0,0 +1,32 @@
+package com.kwan.springcloudalibaba.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.kwan.springcloudalibaba.entity.User;
+
+import java.util.List;
+
+public interface IUserService extends IService {
+
+ /**
+ * 获取所有用户
+ *
+ * @return
+ */
+ List getUsers();
+
+ /**
+ * 获取一个用户
+ *
+ * @return
+ */
+ User getUserById(Integer id);
+
+ /**
+ * 根据姓名查询
+ *
+ * @param sex
+ * @return
+ */
+ User getUserByName(String sex);
+}
diff --git a/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..37b986293c5de90f08939f161e81ffc2233fc02c
--- /dev/null
+++ b/nacos-server-producer/src/main/java/com/kwan/springcloudalibaba/service/impl/UserServiceImpl.java
@@ -0,0 +1,37 @@
+package com.kwan.springcloudalibaba.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.kwan.springcloudalibaba.entity.User;
+import com.kwan.springcloudalibaba.mapper.UserMapper;
+import com.kwan.springcloudalibaba.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Objects;
+
+@Service
+public class UserServiceImpl extends ServiceImpl implements IUserService {
+
+ @Autowired
+ private UserMapper userMapper;
+
+ @Override
+ public List getUsers() {
+ return userMapper.selectList(null);
+ }
+
+ @Override
+ public User getUserById(Integer id) {
+ return userMapper.selectById(id);
+ }
+
+ @Override
+ public User getUserByName(String sex) {
+ User userByName = userMapper.getUserByName(sex);
+ if (Objects.isNull(userByName)) {
+ userByName = new User();
+ }
+ return userByName;
+ }
+}
\ No newline at end of file
diff --git a/nacos-server-producer/src/main/resources/bootstrap.yml b/nacos-server-producer/src/main/resources/bootstrap.yml
index 726b8ec4a91305c747b02db449b750f4c651cb41..ef15f6ce97368b734b5e5a63096caecd9d990425 100644
--- a/nacos-server-producer/src/main/resources/bootstrap.yml
+++ b/nacos-server-producer/src/main/resources/bootstrap.yml
@@ -1,19 +1,7 @@
#端口号
server:
port: 9091
-
-#断电打开
-management:
- endpoint:
- health:
- show-details: always
- endpoints:
- jmx:
- exposure:
- include: '*'
- web:
- exposure:
- include: '*'
+
#spring配置
spring:
application:
@@ -28,5 +16,5 @@ spring:
server-addr: http://120.79.36.53:8848 #配置中心地址
file-extension: yaml #文件类型
group: DEV_GROUP #组别
- namespace: e750dcd5-657b-489b-8d15-b7b71aa3e984 #命名空间
+ namespace: 4cd9bd32-8f25-45cd-b919-df1a0df146e0 #命名空间
refresh-enabled: true #默认自动刷新
\ No newline at end of file
diff --git a/nacos-server-producer/src/main/resources/logback-spring.xml b/nacos-server-producer/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000000000000000000000000000000000000..86327aa5ccd3adb3f51a9e3be026eb4ed5ad50b1
--- /dev/null
+++ b/nacos-server-producer/src/main/resources/logback-spring.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ../logs/springboot-mybatis.log
+
+
+ %date [%level] [%thread] %logger{60} [%file : %line] %msg%n
+
+ UTF-8
+
+
+
+
+ ../logs/springboot-mybatis.log.%d{yyyy-MM-dd}.log
+
+ 30
+
+ 10GB
+
+
+
+
+
+
+ ../logs/error.log
+
+ %date [%level] [%thread] %logger{60} [%file : %line] %msg%n
+
+ UTF-8
+
+
+
+
+ ../logs/error.%d{yyyy-MM-dd}.log
+
+ 30
+
+ 10GB
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/nacos-server-producer/src/main/resources/mapper/UserMapper.xml b/nacos-server-producer/src/main/resources/mapper/UserMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..af5d2cf7996a072effdf920d352f031fce4c3edd
--- /dev/null
+++ b/nacos-server-producer/src/main/resources/mapper/UserMapper.xml
@@ -0,0 +1,9 @@
+
+
+
+
+