自用问题1

java的bean类,为什么用包装类型定义类型,比如Integer 而不是int

int有默认值

springboot,使用get带数组参数的时候,该怎么写。

浏览器访问:http://localhost:8080/selectByBatchId?emps=1&&emps=2
controller层代码:
@GetMapping("/selectByBatchId")
public List selectByBatchId( @RequestParam(“emps”) String [] emps){
return employeeService.selectByBatchId(emps);
}

springboot,使用get带map参数的时候,该怎么写。

浏览器访问:http://localhost:8080/selectByBatchIdMap?last_name=wang&&age=21
controller层代码:
@GetMapping("/selectByBatchIdMap")
public List selectByBatchId(@RequestParam Map<String, Object> emp){
return employeeService.selectByBatchId(emp);
}

springcloud的Eureka,集群配置,切记,spring.application.name中不能出现下划线,否则找不到报500.

springcloud的Eureka,与OpenFeign的配置:

yml配置文件 内联代码片

server:
  port: 80

eureka:
  client:
    register-with-eureka: true          #这里一定要注意,我看教学视频里这里是false,但是false根本没法用到负载均衡功能,
                                        #所以只要访问controller层servelet就要报错,或者主启动类加上@RibbonClient注解,但是那样一来就有点呆,20201119踩坑。
    service-url:
      #defaultZone: http://localhost:7001/eureka
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
    fetch-registry: true
spring:
  application:
    name: rd-app-userconsumer-service

Controller 内联代码片

@RestController
public class WxUserFeignController {

    @Resource
    private UserFeignService userFeignService;

    @GetMapping("/consumer/getWxUserById/{id}")
    public CommonResult<WxUserEntity> getWxUserById(@PathVariable Long id) {
    return userFeignService.getWxUserById(id);
    }
}

Feign接口 内联代码片

// An highlighted block
@Component
@FeignClient(value = "RD-APP-USERPAYMENT-SERVICE")
public interface UserFeignService {

   @GetMapping("/getWxUserById/{id}")
   public CommonResult<WxUserEntity> getWxUserById(@PathVariable("id")Long id);
}

主启动类 `内联代码片````javascript
// An highlighted block
@EnableFeignClients
//@EnableEurekaClient从Spring Cloud Edgware开始,@EnableEurekaClient 或 @EnableDiscoveryClient 是可省略的。只需加上相关依赖,并进行相应配置,即可将微服务注册到服务发现组件上。
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
//@RibbonClient(name="RD-APP-USERPAYMENT-SERVICE",configuration = MySelfRule.class)//这里是定义了自己的负载均衡算法后才加上的注解
public class FeignUserMain80 {
    public static void main(String[] args) {
        SpringApplication.run(FeignUserMain80.class,args);
    }
}

上面是消费端的配置,下面是服务端的Controller
Controller `内联代码片`。
```javascript
// An highlighted block
// when I wrote this,only God and I understood what I was doing
//Now,God only knows
@RestController
public class WxUserController {

    @Autowired
    private WxUserService wxUserService;

    @Resource
    private DiscoveryClient discoveryClient;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/getWxUserById/{id}")
    public CommonResult<WxUserEntity> getWxUserById(@PathVariable Long id){
        System.out.println(id);
        System.out.println(wxUserService.getWxUserById(id));
        WxUserEntity wxUser = wxUserService.getWxUserById(id);
        System.out.println("----------------8001-----------------");
        if(wxUser != null){
            return new CommonResult<>(200,"查询成功,serverPort:"+serverPort,wxUser);
        }
        else {
            return new CommonResult<>(400,"没有对应的记录,查询id"+id,null);
        }
    }

以上,踩坑的一点就是,消费端得注册进入Eureka,不然访问服务的时候回报错,如果主启动类加上@Ribbonclient(xxxxxx)注解的配置也可以,但是那样负载均衡就是Ribbon在起作用了,所以仍然还是需要Feign注册进入Eureka。

字符串转List集合:

List<Long> ibIdList = JsonUtils.readValue(lpCiEpUser.getIbIds(), new TypeReference<List<Long>>() {});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值