码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • spring boot + springcloud教程


    spring boot + springcloud

    注册中心Eureka搭建

    1、创建一个maven项目erp

    2、在这个erp目录下创建eureka-server注册中心

    配置文件

    3、最外的erp配置文件pom.xml,依赖

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.5.RELEASE
        
    
    
    
        1.8
        Greenwich.SR1
        2.1.5
        5.1.46
    
    
    
        
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
            
            
                tk.mybatis
                mapper-spring-boot-starter
                ${mapper.starter.version}
            
            
            
                mysql
                mysql-connector-java
                ${mysql.version}
            
            
                org.springframework.cloud
                spring-cloud-starter-config
            
        
    
    
        
            org.projectlombok
            lombok
        
    
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    4、eureka-server配置中心pom.xml依赖

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    5、创建eureka注册中心启动类

    com.erp.EurekaServerApplication.java

    package com.erp;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    //声明当前应用时Eureka服务
    @EnableEurekaServer
    @SpringBootApplication
    @EnableDiscoveryClient //开启Eureka客户端发现功能
    public class EurekaServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(EurekaServerApplication.class, args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    6、创建application.yml配置文件

    server:
      port: 8080
    spring:
      application:
        name: eureka-server
    eureka:
      client:
        service-url:
          # eureka 服务地址,如果是集群的话;需要指定其它集群eureka地址
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
        # 不注册自己
        register-with-eureka: false
        # 不拉取服务
        fetch-registry: false
      server:
        # 服务失效剔除时间间隔,默认60秒
        eviction-interval-timer-in-ms: 60000
        # 关闭自我保护模式(默认是打开的)
        enable-self-preservation: false
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    获得时间戳和转日期

    Long sj = System.currentTimeMillis();//时间戳
    Long mingt = System.currentTimeMillis() + (1000 * 60 * 60 * 24);              //第二天
    
    转日期
    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String dateStr = dateformat.format(sj);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    字符串转数字类型

    long userid = Integer.parseInt(pindex_id);
    
    • 1

    List<>Map转map,强转类型输出

    List转map,强转类型输出
    
    String appid = user.getAppid();
    List lists = appletsPindexidService.findOpenid(appid);
    Map map = lists.get(0);
    Long cid = Long.valueOf(map.get("company_id").toString());
    Long jid = Long.valueOf(map.get("jurisdiction_id").toString());
    user.setCompany_id(cid);
    user.setJurisdiction_id(jid);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    创建List Object包几个对象

    User user = userService.findById(userid);
    List list = new ArrayList();
    List houses = houseService.findHid(user.getHouse_id());
    list.add(houses);
    return new Result(true, StatusCode.OK,"查询成功",list);
    
    • 1
    • 2
    • 3
    • 4
    • 5

    if判断不等于空和是不是相等

    if(!"".equals(searchMap.get("region")) || searchMap.get("region")!=null){
    
    }
    //判断相等
    if(map.get("typa_butler").equals(1)){
    	
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    判断等于.equals

    if(searchMap.get("typa").equals("2")){
        strs = "2";
    }
    
    • 1
    • 2
    • 3

    获得有几个数组

    List userMay = userService.listAll(userAll);
    userMay.size()
    
    • 1
    • 2

    js转时间戳

    var sj = parseInt(datesa[i].date);//转数字
    
    function timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return Y + M + D + h + m + s;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    日期转时间戳,获得12个月

    /**
    * 获得12个月时间戳
    * */
    public List getMonthStr() throws Exception {
        List list = new ArrayList();
        Long sj = System.currentTimeMillis();//时间戳
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy");
        String dateStr = dateformat.format(sj);
        for (int i=1;i<=12;i++){
            List li = new ArrayList();
            li.add(dateStr+"-"+i);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            String mydate = dateStr+"-"+i;
            Date datetime = sdf.parse(mydate);//将你的日期转换为时间戳
            Long time = datetime.getTime();
            time = time/1000;
            li.add(time);
            list.add(li);
        }
        return list;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    Map新增

    Map map = new HashMap<>();
    map.putIfAbsent("checked",true);
    map.putIfAbsent("zhankai",true);
    
    • 1
    • 2
    • 3

    获得字符串后6位

    String merchantNo = pay.get(0).get("merchantNo").toString();
    String mno = merchantNo.substring(merchantNo.length()-6);
    
    • 1
    • 2

    获得IP地址

    @RequestMapping(value = "/orderGoodsAdd",method = RequestMethod.POST)
    public static String getIpAddress(HttpServletRequest request) {  
        String ip = request.getHeader("x-forwarded-for");  
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        	ip = request.getHeader("Proxy-Client-IP");  
        }  
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        	ip = request.getHeader("WL-Proxy-Client-IP");  
        }  
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        	ip = request.getHeader("HTTP_CLIENT_IP");  
        }  
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        	ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
        }  
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        	ip = request.getRemoteAddr();  
        }  
        return ip;  
    }  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    遍历修改新增List<,Map>

    	/**
        * 报事报修和投诉建议查询接口
        * */
        @GetMapping("/houseid")
        public Result houseid(@RequestParam Map searchMap){
            String houseid = searchMap.get("houseid").toString();
            String strs = null;
            if(searchMap.get("typa").equals("1")){
                strs = "typa<6 and (typa_butler=1 or typa_butler=4)";
            }
            if(searchMap.get("typa").equals("2")){
                strs = "typa>=6 and (typa_butler=1 or typa_butler=4)";
            }
            List list = repairService.listHouseid(houseid,strs);
            for(int i=0;i map = (HashMap) list.get(i);
                SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String date;
                if(map.get("typa_butler").equals(1)){
                    Long sj = Long.valueOf(map.get("date").toString());
                    date = dateformat.format(sj);
                }else{
                    String sjs = map.get("date")+"000";
                    Long sj = Long.valueOf(sjs);
                    date = dateformat.format(sj);
                }
                map.put("date",date);
    
                list.set(i,map);
            }
            return new Result(true,StatusCode.OK,"查询成功",list);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
  • 相关阅读:
    windows编译ollvm笔记
    JavaWeb三大组件之Filter
    阿里云Nas文件存储的各种场景使用
    老张的思考
    安全驱动怎么设计(一)
    计算机算法分析与设计(4)---凸多边形的最优三角划分(含C++代码)
    ubuntu开启防火墙端口号
    【软件】Ubuntu16.04升级git最新版,升级python到3.7.
    JVM 内存区域
    Element的步骤条el-steps加入插槽内容
  • 原文地址:https://blog.csdn.net/qq_34631220/article/details/128171944
    • 最新文章
    • 攻防演习之三天拿下官网站群
      数据安全治理学习——前期安全规划和安全管理体系建设
      企业安全 | 企业内一次钓鱼演练准备过程
      内网渗透测试 | Kerberos协议及其部分攻击手法
      0day的产生 | 不懂代码的"代码审计"
      安装scrcpy-client模块av模块异常,环境问题解决方案
      leetcode hot100【LeetCode 279. 完全平方数】java实现
      OpenWrt下安装Mosquitto
      AnatoMask论文汇总
      【AI日记】24.11.01 LangChain、openai api和github copilot
    • 热门文章
    • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
      奉劝各位学弟学妹们,该打造你的技术影响力了!
      五年了,我在 CSDN 的两个一百万。
      Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
      面试官都震惊,你这网络基础可以啊!
      你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
      心情不好的时候,用 Python 画棵樱花树送给自己吧
      通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
      13 万字 C 语言从入门到精通保姆级教程2021 年版
      10行代码集2000张美女图,Python爬虫120例,再上征途
    Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
    正则表达式工具 cron表达式工具 密码生成工具

    京公网安备 11010502049817号