From ea47eff3bc263ec2079e3fb9369edcf2983eaa16 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Tue, 10 Jan 2023 11:00:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:ribbon=E8=B4=9F=E8=BD=BD=E5=9D=87=E8=A1=A1?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- .../pom.xml | 14 ++-- .../springcloud/GoodsApplication9100.java | 4 +- .../controller/HelloController.java | 0 .../controller/KwanGoodsInfoController.java | 0 .../springcloud/dao/KwanGoodsInfoDao.java | 0 .../springcloud/entity/KwanGoodsInfo.java | 0 .../service/KwanGoodsInfoService.java | 0 .../impl/KwanGoodsInfoServiceImpl.java | 0 .../src/main/resources/application.yaml | 5 ++ .../springcloud/GoodsApplicationTests.java | 0 springcloud-service-goods-9200/pom.xml | 77 ++++++++++++++++++ .../springcloud/GoodsApplication9200.java | 15 ++++ .../controller/HelloController.java | 40 ++++++++++ .../controller/KwanGoodsInfoController.java | 80 +++++++++++++++++++ .../springcloud/dao/KwanGoodsInfoDao.java | 17 ++++ .../springcloud/entity/KwanGoodsInfo.java | 55 +++++++++++++ .../service/KwanGoodsInfoService.java | 16 ++++ .../impl/KwanGoodsInfoServiceImpl.java | 19 +++++ .../src/main/resources/application.yaml | 50 ++++++++++++ .../springcloud/GoodsApplicationTests.java | 13 +++ springcloud-service-goods-9300/pom.xml | 77 ++++++++++++++++++ .../springcloud/GoodsApplication9300.java | 15 ++++ .../controller/HelloController.java | 40 ++++++++++ .../controller/KwanGoodsInfoController.java | 80 +++++++++++++++++++ .../springcloud/dao/KwanGoodsInfoDao.java | 17 ++++ .../springcloud/entity/KwanGoodsInfo.java | 55 +++++++++++++ .../service/KwanGoodsInfoService.java | 16 ++++ .../impl/KwanGoodsInfoServiceImpl.java | 19 +++++ .../src/main/resources/application.yaml | 50 ++++++++++++ .../springcloud/GoodsApplicationTests.java | 13 +++ 31 files changed, 781 insertions(+), 10 deletions(-) rename {springcloud-service-goods => springcloud-service-goods-9100}/pom.xml (87%) rename springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java => springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/GoodsApplication9100.java (75%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/controller/HelloController.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java (100%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/main/resources/application.yaml (70%) rename {springcloud-service-goods => springcloud-service-goods-9100}/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java (100%) create mode 100644 springcloud-service-goods-9200/pom.xml create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/GoodsApplication9200.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/HelloController.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java create mode 100644 springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java create mode 100644 springcloud-service-goods-9200/src/main/resources/application.yaml create mode 100644 springcloud-service-goods-9200/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java create mode 100644 springcloud-service-goods-9300/pom.xml create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/GoodsApplication9300.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/HelloController.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java create mode 100644 springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java create mode 100644 springcloud-service-goods-9300/src/main/resources/application.yaml create mode 100644 springcloud-service-goods-9300/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java diff --git a/pom.xml b/pom.xml index 54bb1b4..b9066ab 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,9 @@ - springcloud-service-goods + springcloud-service-goods-9100 + springcloud-service-goods-9200 + springcloud-service-goods-9300 springcloud-service-common springcloud-service-portal springcloud-service-eureka diff --git a/springcloud-service-goods/pom.xml b/springcloud-service-goods-9100/pom.xml similarity index 87% rename from springcloud-service-goods/pom.xml rename to springcloud-service-goods-9100/pom.xml index 43a7b29..e3ab9ab 100644 --- a/springcloud-service-goods/pom.xml +++ b/springcloud-service-goods-9100/pom.xml @@ -7,9 +7,9 @@ springcloud-service-parent 1.0.0 - springcloud-service-goods + springcloud-service-goods-9100 0.0.1-SNAPSHOT - springcloud-service-goods + springcloud-service-goods-9100 UTF-8 UTF-8 @@ -48,11 +48,11 @@ 8.0.11 - - - - - + + + + + org.springframework.boot diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/GoodsApplication9100.java similarity index 75% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/GoodsApplication9100.java index c02e71b..b66d873 100644 --- a/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java +++ b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/GoodsApplication9100.java @@ -6,10 +6,10 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableEurekaClient @SpringBootApplication -public class GoodsApplication { +public class GoodsApplication9100 { public static void main(String[] args) { - SpringApplication.run(GoodsApplication.class, args); + SpringApplication.run(GoodsApplication9100.class, args); } } diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/HelloController.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/HelloController.java diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java b/springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java similarity index 100% rename from springcloud-service-goods/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java rename to springcloud-service-goods-9100/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java diff --git a/springcloud-service-goods/src/main/resources/application.yaml b/springcloud-service-goods-9100/src/main/resources/application.yaml similarity index 70% rename from springcloud-service-goods/src/main/resources/application.yaml rename to springcloud-service-goods-9100/src/main/resources/application.yaml index 0fe0e38..187b005 100644 --- a/springcloud-service-goods/src/main/resources/application.yaml +++ b/springcloud-service-goods-9100/src/main/resources/application.yaml @@ -18,6 +18,11 @@ eureka: client: service-url: defaultZone: http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/ + instance: + lease-renewal-interval-in-seconds: 2 #每间隔2s,向服务端发送一次心跳,证明自己依然"存活” + lease-expiration-duration-in-seconds: 10 #告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉 + prefer-ip-address: true #告诉服务端,服务实例以IP作为链接,而不是取机器名 + instance-id: springcloud-service-goods-9100 #告诉服务端,服务实例的id,id要是唯一的 management: endpoints: diff --git a/springcloud-service-goods/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java b/springcloud-service-goods-9100/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java similarity index 100% rename from springcloud-service-goods/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java rename to springcloud-service-goods-9100/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java diff --git a/springcloud-service-goods-9200/pom.xml b/springcloud-service-goods-9200/pom.xml new file mode 100644 index 0000000..d06743f --- /dev/null +++ b/springcloud-service-goods-9200/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + com.kwan.springcloud + springcloud-service-parent + 1.0.0 + + springcloud-service-goods-9200 + 0.0.1-SNAPSHOT + springcloud-service-goods-9200 + + UTF-8 + UTF-8 + 1.8 + Hoxton.SR12 + + + + com.kwan.springcloud + springcloud-service-common + 1.0.0 + compile + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + mysql + mysql-connector-java + 8.0.11 + + + + + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/GoodsApplication9200.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/GoodsApplication9200.java new file mode 100644 index 0000000..68e2ee1 --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/GoodsApplication9200.java @@ -0,0 +1,15 @@ +package com.kwan.springcloud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; + +@EnableEurekaClient +@SpringBootApplication +public class GoodsApplication9200 { + + public static void main(String[] args) { + SpringApplication.run(GoodsApplication9200.class, args); + } + +} diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/HelloController.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/HelloController.java new file mode 100644 index 0000000..71ebdda --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/HelloController.java @@ -0,0 +1,40 @@ +package com.kwan.springcloud.controller; + + +import com.alibaba.fastjson.JSONArray; +import com.kwan.springcloud.response.Result; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Slf4j +@RestController +public class HelloController { + + @Autowired + private DiscoveryClient client; + @Autowired + private Registration registration; + + + /** + * produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE + * 解决不是json显示问题 + */ + @RequestMapping(value = "/hello", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) + public Result index() { + List instances = client.getInstances(registration.getServiceId()); + log.info(JSONArray.toJSONString(instances)); + return Result.ok(instances); + } + +} + + diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java new file mode 100644 index 0000000..35e64f9 --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java @@ -0,0 +1,80 @@ +package com.kwan.springcloud.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.response.Result; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.List; + +@RestController +@RequestMapping("kwanGoodsInfo") +public class KwanGoodsInfoController { + /** + * 服务对象 + */ + @Resource + private KwanGoodsInfoService kwanGoodsInfoService; + + /** + * 分页查询所有数据 + * + * @param page 分页对象 + * @param kwanGoodsInfo 查询实体 + * @return 所有数据 + */ + @GetMapping + public Result selectAll(Page page, KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.page(page, new QueryWrapper<>(kwanGoodsInfo))); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) + public Result selectOne(@PathVariable Serializable id) { + return Result.ok(this.kwanGoodsInfoService.getById(id)); + } + + /** + * 新增数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 新增结果 + */ + @PostMapping + public Result insert(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.save(kwanGoodsInfo)); + } + + /** + * 修改数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 修改结果 + */ + @PutMapping + public Result update(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.updateById(kwanGoodsInfo)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @DeleteMapping + public Result delete(@RequestParam("idList") List idList) { + return Result.ok(this.kwanGoodsInfoService.removeByIds(idList)); + } +} + diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java new file mode 100644 index 0000000..bd34f72 --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java @@ -0,0 +1,17 @@ +package com.kwan.springcloud.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import org.apache.ibatis.annotations.Mapper; + +/** + * (KwanGoodsInfo)表数据库访问层 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +@Mapper +public interface KwanGoodsInfoDao extends BaseMapper { + +} + diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java new file mode 100644 index 0000000..eee4643 --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java @@ -0,0 +1,55 @@ +package com.kwan.springcloud.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; + +import java.io.Serializable; + +/** + * (KwanGoodsInfo)表实体类 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +public class KwanGoodsInfo extends Model { + + private Integer id; + //商品名称 + private String goodsName; + //商品价格 + private Integer goodsPrice; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public Integer getGoodsPrice() { + return goodsPrice; + } + + public void setGoodsPrice(Integer goodsPrice) { + this.goodsPrice = goodsPrice; + } + + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + public Serializable pkVal() { + return this.id; + } +} diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java new file mode 100644 index 0000000..1913635 --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java @@ -0,0 +1,16 @@ +package com.kwan.springcloud.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springcloud.entity.KwanGoodsInfo; + +/** + * (KwanGoodsInfo)表服务接口 + * + * @author makejava + * @since 2023-01-08 10:21:29 + */ +public interface KwanGoodsInfoService extends IService { + +} + diff --git a/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java new file mode 100644 index 0000000..6c6739d --- /dev/null +++ b/springcloud-service-goods-9200/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.kwan.springcloud.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springcloud.dao.KwanGoodsInfoDao; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.stereotype.Service; + +/** + * (KwanGoodsInfo)表服务实现类 + * + * @author makejava + * @since 2023-01-08 10:21:30 + */ +@Service("kwanGoodsInfoService") +public class KwanGoodsInfoServiceImpl extends ServiceImpl implements KwanGoodsInfoService { + +} + diff --git a/springcloud-service-goods-9200/src/main/resources/application.yaml b/springcloud-service-goods-9200/src/main/resources/application.yaml new file mode 100644 index 0000000..3c2010e --- /dev/null +++ b/springcloud-service-goods-9200/src/main/resources/application.yaml @@ -0,0 +1,50 @@ +#端口号 +server: + port: 9200 + +#兼容swagger配置 +spring: + # mysql + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + username: root + password: 716288qwe + application: + name: goods-service #服务名称 + +#服务提供者 +eureka: + client: + service-url: + defaultZone: http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/ + instance: + lease-renewal-interval-in-seconds: 2 #每间隔2s,向服务端发送一次心跳,证明自己依然"存活” + lease-expiration-duration-in-seconds: 10 #告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉 + prefer-ip-address: true #告诉服务端,服务实例以IP作为链接,而不是取机器名 + instance-id: springcloud-service-goods-9200 #告诉服务端,服务实例的id,id要是唯一的 + +management: + endpoints: + web: + base-path: /actuator #修改访问路径 2.0之前默认是/ 2.0默认是 /actuator 可以通过这个属性值修改 + health: + show-details: always #显示健康具体信息 默认不会显示详细信息 + +#mybatis-plus配置 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true + call-setters-on-nulls: true + auto-mapping-behavior: full + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath*:mapper/**/*Mapper.xml + global-config: + banner: false + # 逻辑删除配置 + db-config: + id-type: AUTO + logic-delete-field: delFlag + logic-delete-value: 1 + logic-not-delete-value: 0 + table-underline: true \ No newline at end of file diff --git a/springcloud-service-goods-9200/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java b/springcloud-service-goods-9200/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java new file mode 100644 index 0000000..bf3fb84 --- /dev/null +++ b/springcloud-service-goods-9200/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java @@ -0,0 +1,13 @@ +package com.kwan.springcloud; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GoodsApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/springcloud-service-goods-9300/pom.xml b/springcloud-service-goods-9300/pom.xml new file mode 100644 index 0000000..4af6d07 --- /dev/null +++ b/springcloud-service-goods-9300/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + com.kwan.springcloud + springcloud-service-parent + 1.0.0 + + springcloud-service-goods-9300 + 0.0.1-SNAPSHOT + springcloud-service-goods-9300 + + UTF-8 + UTF-8 + 1.8 + Hoxton.SR12 + + + + com.kwan.springcloud + springcloud-service-common + 1.0.0 + compile + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3 + + + + mysql + mysql-connector-java + 8.0.11 + + + + + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/GoodsApplication9300.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/GoodsApplication9300.java new file mode 100644 index 0000000..33ed44d --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/GoodsApplication9300.java @@ -0,0 +1,15 @@ +package com.kwan.springcloud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; + +@EnableEurekaClient +@SpringBootApplication +public class GoodsApplication9300 { + + public static void main(String[] args) { + SpringApplication.run(GoodsApplication9300.class, args); + } + +} diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/HelloController.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/HelloController.java new file mode 100644 index 0000000..71ebdda --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/HelloController.java @@ -0,0 +1,40 @@ +package com.kwan.springcloud.controller; + + +import com.alibaba.fastjson.JSONArray; +import com.kwan.springcloud.response.Result; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Slf4j +@RestController +public class HelloController { + + @Autowired + private DiscoveryClient client; + @Autowired + private Registration registration; + + + /** + * produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE + * 解决不是json显示问题 + */ + @RequestMapping(value = "/hello", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) + public Result index() { + List instances = client.getInstances(registration.getServiceId()); + log.info(JSONArray.toJSONString(instances)); + return Result.ok(instances); + } + +} + + diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java new file mode 100644 index 0000000..35e64f9 --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java @@ -0,0 +1,80 @@ +package com.kwan.springcloud.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.response.Result; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.List; + +@RestController +@RequestMapping("kwanGoodsInfo") +public class KwanGoodsInfoController { + /** + * 服务对象 + */ + @Resource + private KwanGoodsInfoService kwanGoodsInfoService; + + /** + * 分页查询所有数据 + * + * @param page 分页对象 + * @param kwanGoodsInfo 查询实体 + * @return 所有数据 + */ + @GetMapping + public Result selectAll(Page page, KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.page(page, new QueryWrapper<>(kwanGoodsInfo))); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) + public Result selectOne(@PathVariable Serializable id) { + return Result.ok(this.kwanGoodsInfoService.getById(id)); + } + + /** + * 新增数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 新增结果 + */ + @PostMapping + public Result insert(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.save(kwanGoodsInfo)); + } + + /** + * 修改数据 + * + * @param kwanGoodsInfo 实体对象 + * @return 修改结果 + */ + @PutMapping + public Result update(@RequestBody KwanGoodsInfo kwanGoodsInfo) { + return Result.ok(this.kwanGoodsInfoService.updateById(kwanGoodsInfo)); + } + + /** + * 删除数据 + * + * @param idList 主键结合 + * @return 删除结果 + */ + @DeleteMapping + public Result delete(@RequestParam("idList") List idList) { + return Result.ok(this.kwanGoodsInfoService.removeByIds(idList)); + } +} + diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java new file mode 100644 index 0000000..bd34f72 --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/dao/KwanGoodsInfoDao.java @@ -0,0 +1,17 @@ +package com.kwan.springcloud.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import org.apache.ibatis.annotations.Mapper; + +/** + * (KwanGoodsInfo)表数据库访问层 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +@Mapper +public interface KwanGoodsInfoDao extends BaseMapper { + +} + diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java new file mode 100644 index 0000000..eee4643 --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/entity/KwanGoodsInfo.java @@ -0,0 +1,55 @@ +package com.kwan.springcloud.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; + +import java.io.Serializable; + +/** + * (KwanGoodsInfo)表实体类 + * + * @author makejava + * @since 2023-01-08 10:21:28 + */ +public class KwanGoodsInfo extends Model { + + private Integer id; + //商品名称 + private String goodsName; + //商品价格 + private Integer goodsPrice; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName; + } + + public Integer getGoodsPrice() { + return goodsPrice; + } + + public void setGoodsPrice(Integer goodsPrice) { + this.goodsPrice = goodsPrice; + } + + /** + * 获取主键值 + * + * @return 主键值 + */ + @Override + public Serializable pkVal() { + return this.id; + } +} diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java new file mode 100644 index 0000000..1913635 --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/KwanGoodsInfoService.java @@ -0,0 +1,16 @@ +package com.kwan.springcloud.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springcloud.entity.KwanGoodsInfo; + +/** + * (KwanGoodsInfo)表服务接口 + * + * @author makejava + * @since 2023-01-08 10:21:29 + */ +public interface KwanGoodsInfoService extends IService { + +} + diff --git a/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java new file mode 100644 index 0000000..6c6739d --- /dev/null +++ b/springcloud-service-goods-9300/src/main/java/com/kwan/springcloud/service/impl/KwanGoodsInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.kwan.springcloud.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springcloud.dao.KwanGoodsInfoDao; +import com.kwan.springcloud.entity.KwanGoodsInfo; +import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.stereotype.Service; + +/** + * (KwanGoodsInfo)表服务实现类 + * + * @author makejava + * @since 2023-01-08 10:21:30 + */ +@Service("kwanGoodsInfoService") +public class KwanGoodsInfoServiceImpl extends ServiceImpl implements KwanGoodsInfoService { + +} + diff --git a/springcloud-service-goods-9300/src/main/resources/application.yaml b/springcloud-service-goods-9300/src/main/resources/application.yaml new file mode 100644 index 0000000..872152e --- /dev/null +++ b/springcloud-service-goods-9300/src/main/resources/application.yaml @@ -0,0 +1,50 @@ +#端口号 +server: + port: 9300 + +#兼容swagger配置 +spring: + # mysql + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + username: root + password: 716288qwe + application: + name: goods-service #服务名称 + +#服务提供者 +eureka: + client: + service-url: + defaultZone: http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/ + instance: + lease-renewal-interval-in-seconds: 2 #每间隔2s,向服务端发送一次心跳,证明自己依然"存活” + lease-expiration-duration-in-seconds: 10 #告诉服务端,如果我10s之内没有给你发心跳,就代表我故障了,将我踢出掉 + prefer-ip-address: true #告诉服务端,服务实例以IP作为链接,而不是取机器名 + instance-id: springcloud-service-goods-9300 #告诉服务端,服务实例的id,id要是唯一的 + +management: + endpoints: + web: + base-path: /actuator #修改访问路径 2.0之前默认是/ 2.0默认是 /actuator 可以通过这个属性值修改 + health: + show-details: always #显示健康具体信息 默认不会显示详细信息 + +#mybatis-plus配置 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true + call-setters-on-nulls: true + auto-mapping-behavior: full + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath*:mapper/**/*Mapper.xml + global-config: + banner: false + # 逻辑删除配置 + db-config: + id-type: AUTO + logic-delete-field: delFlag + logic-delete-value: 1 + logic-not-delete-value: 0 + table-underline: true \ No newline at end of file diff --git a/springcloud-service-goods-9300/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java b/springcloud-service-goods-9300/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java new file mode 100644 index 0000000..bf3fb84 --- /dev/null +++ b/springcloud-service-goods-9300/src/test/java/com/kwan/springcloud/GoodsApplicationTests.java @@ -0,0 +1,13 @@ +package com.kwan.springcloud; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GoodsApplicationTests { + + @Test + void contextLoads() { + } + +} -- GitLab