项目总结

2019年12月2日


登录接口

       账户为admin

      密码  Admin123   -3123123  2次base64加密


swagger.html 验证接口


swagger登陆被过滤了就去拷贝过来的url到访问swagger的congfig下的corsConfig



       and device.battery = ]]> #{maxBattery}小于



        and device.battery #{minBattery}大于





API项目规范


在自己的项目建API包

       创建XXAPI接口

       然后在自己的项目中调用自己上面生成的XXAPI 全限定包名



2019年12月6日


Linkedhashmap 强转为 自定义对象

String s =JSONUtil.toJsonStr(Map);

UserManageInfo.ProfessionalTitleprofessionalTitle = JSONObject.parseObject(s, Bean.class);


2019年12月21日

Java8新特性

1.把address对象的name属性装到新的list里面

Liststrings = addresses.stream().map(Address ->Address.getName()).collect(Collectors.toList());


2 把Person对象的id,name的value装入map,key1,key2,前后的key相同

Map

String> map = list.stream().collect(Collectors.toMap(Person::getId,

Person::getName, (key1, key2) -> key2))

3 把Person的name属性加,拼接String

String s =

list.stream().map(Person::getName).collect(Collectors.joining(","))

4 把map中key为name的value,且不为null的装入list

List

strings = lists.stream().map(e -> e.get("name")).filter(Objects::nonNull).map(e -> e.toString()).collect(Collectors.toList());

5把address对象的age排倒序,然后加5输出

addresses.stream().sorted(Comparator.comparing(Address::getAge).reversed()).forEach(Address->System.out.println(Address.getAge()+5));




2019年12月31日星期二

Springboot集成rabbitmq


[if !supportLists]1.    [endif]添加maven依赖

org.springframework.boot

spring-boot-starter-amqp

[if !supportLists]2.    [endif]安装rabbitmq服务器,配置配置文件

spring.application.name=Spring-boot-rabbitmq

spring.rabbitmq.host=192.168.0.86

spring.rabbitmq.port=5672

spring.rabbitmq.username=admin

spring.rabbitmq.password=123456

3.准备一个消息实体类,配置文件可定义为一个实体类, ConfigurationProperties

4.定义一个配置类,启动时候连接mq服务器

5.定义生产者和消费者连接对象配置类



Springboot项目部署方式

[if !supportLists]1.    [endif]jar包

1pom打包方式未jar,

2执行命令mvn clean package  -Dmaven.test.skip=true

3执行 [nohup](后台执行) java-jar app.jar [--spring.profiles.active=dev](选择配置文件)

[if !supportLists]2.    [endif]war包

[if !supportLists]1.    [endif]打包方式为war

[if !supportLists]2.    [endif]打包排除tomcatprovided

[if !supportLists]3.    [endif]执行命令mvn clean package  -Dmaven.test.skip=true

[if !supportLists]4.    [endif]启动类继承继承SpringBootServletInitializer ,覆盖configure()

[if !supportLists]5.    [endif]放入tomcat webapp下 自动解压部署

public class AiSampleApplication extendsSpringBootServletInitializer {

   @Override

   protected SpringApplicationBuilder configure(SpringApplicationBuilderapplication) {

       return application.sources(AiSampleApplication.class);

    }

   public static void main(String[] args) {

       SpringApplication.run(AiSampleApplication.class);

    }

}



Jekins部署springboot项目

http://www.ityouknow.com/springboot/2017/11/11/spring-boot-jenkins.html

支持 Quartz

Spring Boot1.0并没有提供对 Quartz 的支持,之前出现了各种集成方案,Spring Boot2.0给出了最简单的集成方式。

OAuth 2.0

同时也加入了对于OAuth 2.0的支持, 使得开发人员更加友好的使用spring-security来完成权限模块的开发


Spring Webflux

https://github.com/ityouknow/spring-boot-examples#start-of-content



2019年12月31日

Springclound

[if !supportLists]1.    [endif]eureka注册中心集群:


---

spring:

 application:

   name: spring-cloud-eureka

 profiles: peer1

server:

 port: 8000

eureka:

 instance:

   hostname: peer1

 client:

   serviceUrl:

     defaultZone: http://peer2:8001/eureka/,http://peer3:8002/eureka/

---

spring:

 application:

   name: spring-cloud-eureka

 profiles: peer2

server:

 port: 8001

eureka:

 instance:

   hostname: peer2

 client:

   serviceUrl:

     defaultZone: http://peer1:8000/eureka/,http://peer3:8002/eureka/

---

spring:

 application:

   name: spring-cloud-eureka

 profiles: peer3

server:

 port: 8002

eureka:

 instance:

   hostname: peer3

 client:

   serviceUrl:

     defaultZone:http://peer1:8000/eureka/,http://peer2:8001/eureka/

每台注册中心defaultZone分别又指向其它两个节点即可,使用application.yml来配置。


[if !supportLists]2.   [endif]配置熔断机制

[if !supportLists]1.   [endif]feign.hystrix.enabled=true

[if !supportLists]2.   [endif]创建回调类

创建HelloRemoteHystrix类继承与HelloRemote实现回调的方法

@Component

publicclassHelloRemoteHystriximplementsHelloRemote{}

 

3.添加fallback属性

在HelloRemote类添加指定fallback类,在服务熔断的时候返回fallback类中的内容。

@FeignClient(name="spring-cloud-producer",fallback=HelloRemoteHystrix.class)

publicinterfaceHelloRemote{}

 

3. Zuul的配置,调试

http://www.ityouknow.com/springcloud/2018/01/20/spring-cloud-zuul.html




2020年1月4日

@DateTimeFormat(pattern = “yyyy-MM-dd HH:mm:ss”)是将String转换成Date,一般前台给后台传值时用 

@JsonFormat(pattern

=

“yyyy-MM-dd HH:mm:ss”, timezone=”GMT+8”)将Date转换成String 一般后台传值给前台时

 

 

2020年1月6日

实现定时任务的几种方式

1.jvm的task timer,只能单线程

2.spring的@scheduled(不支持集群)


缺点是:如果使用服务器集群部署方式的时候,其自身无法解决定时任务重复执行的问题。

类@component方式@ scheduled,启动类注解4.启动类@EnableScheduling


配置多线程执行:

[if !supportLists]1.  [endif]加上异步注解

给类添加注解@EnableAsync,并给方法添加注解@Async

2.配置多线程池 定时器

 @EnableScheduling

  @Configuration

  public class SchedulerConfig implementsSchedulingConfigurer {

  @Bean 郑州做人流手术http://rl.zyfuke.com/

  public ScheduledExecutorServiceconcurrentTaskScheduler(){

  ScheduledThreadPoolExecutor executorService = newScheduledThreadPoolExecutor(20);

  executorService.setMaximumPoolSize(20);

  executorService.setRejectedExecutionHandler(newScheduledThreadPoolExecutor.CallerRunsPolicy());

  return executorService;

  }

  @Override

  public void configureTasks(ScheduledTaskRegistrartaskRegistrar) {

  taskRegistrar.setScheduler(concurrentTaskScheduler());

  }

  }

  其中Scheduler 支持两种,种分别是:TaskScheduler 和ScheduledExecutorService

  public void setScheduler(@Nullable Object scheduler) {

  if (scheduler == null) {

  this.taskScheduler = null;

  }

  else if (scheduler instanceof TaskScheduler) {

  this.taskScheduler = (TaskScheduler) scheduler;

  }

  else if (scheduler instanceof ScheduledExecutorService) {

  this.taskScheduler = newConcurrentTaskScheduler(((ScheduledExecutorService) scheduler));

  }

  else {

  throw new IllegalArgumentException("Unsupportedscheduler type: " + scheduler.getClass());

  }

  }


3.quartz

[if !supportLists]o    [endif]Quartz的某次执行任务过程中抛出异常,不影响下一次任务的执行,当下一次执行时间到来时,定时器会再次执行任务。

[if !supportLists]o    [endif]TimerTask不同,一旦某个任务在执行过程中抛出异常,则整个定时器生命周期就结束,以后永远不会再执行定时器任务

Quartz每次执行都创建一个新的任务类对象。

TimerTask则每次使用同一个任务类对象。


1添加依赖,添加数据库和quartz配置文件

2.定义一个quartz工具类@component,注入Scheduler

3.定义一些给外面调用的方法,addjob,deletejob等, Scheduler来调API

定义要使用定时器的组件类实现Job接口, 复写execute方法,也就是每次执行的业务逻辑,然后使用工具类的新增任务方法添加定时任务.

4.启动了注解EnableScheduling

集群参考https://www.cnblogs.com/wanghan1109/p/11195344.html

集群重复执行解决 shedlock


1.cron表达式(绝对时间)(受服务器影响)

2.fixedRate

(相对时间)



2020年1月22日星期三


导入使用ExceleimportUtel

导出ExcelexportUtel


2020年2月11日


Idea maven项目丢失项目结构

[if !supportLists]1.     [endif]右侧点击maven + xml

[if !supportLists]2.     [endif]




2020年4月8日


Springboot 异步


[if !supportLists]1.    [endif]异步方法

[if !supportLists]a)     [endif]方法上加@Async

[if !supportLists]b)     [endif]在启动类加@EnableAsync

[if !supportLists]c)     [endif]虚



2020年4月17日

[if !supportLists]1.    [endif]java调用shell脚本

[if !supportLists]a)     [endif]同一服务


StringbashCommand = "/home/go/script/restart_go.sh";  //①

    Runtime runtime = Runtime.getRuntime();

    Process pro =runtime.exec(bashCommand);  //②

    int status = pro.waitFor();  //③

    if (status != 0){  //④

        logger.error("restart go servererror");

        return;

    }

   logger.info("restart go server success");





10     public static void main(String[] args) {

11         String s;

12         StringBuilder sb = newStringBuilder();

13         InputStream fis = null;

14         try {

15             // Process process = Runtime.getRuntime().exec("pinglocalhost");

               Process process =Runtime.getRuntime().exec(new String[]{"sh", "-c", XXXX});

               //注意,我将原来的15行注释掉了,变成了下面的写法。声明,我调用的command是Lunix下的命令,如果你用的是windows的话,不需要这么写。

               //为什么要使用这样的写法,因为项目需要考虑到单引号双引号等,转换加/的原因。

16             fis = process.getInputStream();

17             BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(fis));

18            while((s=bufferedReader.readLine()) != null) {

19                 sb.append(s);

                   //sb.append(\n);

20             }

21             System.out.println(sb.toString());

22             process.waitFor();

23            System.out.println(process.exitValue());

24         } catch (InterruptedException e) {

25             e.printStackTrace();

26         } catch (IOException e) {

27             e.printStackTrace();

28         } finally {

29             try {

30                 fis.close();

31             } catch (IOException e) {

32                 e.printStackTrace();

33             }

34         }

35     }

36 }



[if !supportLists]b)     [endif]远程调用

.先登陆

publicBoolean login(){

        boolean flg=false;

        try {

        Connection   conn = new Connection(ip);

            conn.connect();//连接

           flg=conn.authenticateWithPassword(userName, userPwd);//认证

            if (flg){

                System.out.println("认证成功!");

            }

        } catch (IOException e) {

            e.printStackTrace();

        }

        return flg

}


执行  cmd为脚本的绝对路径  加权限 在前面凭借chomd 777

    public String executeSuccess(String cmd){

        String result="";

        try {

            if(login()){

                Session session=conn.openSession();//打开一个会话

                session.execCommand(cmd);//执行命令

               result=processStdout(session.getStdout(),DEFAULTCHART);

                conn.close();

                session.close();

            }

        } catch (IOException e) {

            e.printStackTrace();

        }

        returnresult;

}


获取输出信息

publicstatic String processStdout(InputStream in, String charset){

        InputStream    stdout = new StreamGobbler(in);

        StringBuffer buffer = newStringBuffer();;

        try {

            BufferedReader br = newBufferedReader(new InputStreamReader(stdout,charset));

            String line=null;

            while((line=br.readLine()) !=null){

               buffer.append(line+"\n");

            }

        } catch (UnsupportedEncodingExceptione) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

        return buffer.toString();

}


2020年4月17日

Jstack 调优

1.定位java进程id

       Ps–axu|grep tomcat  假如19992

[if !supportLists]2.    [endif]查看cpu占用情况

[if !supportLists]a)     [endif]Top

[if !supportLists]b)     [endif]Top Hp Pid(19992)

3. printf "%x\n" 21742 (占用cpu高的线程id)

4. jstack 19992| grep 54ee(第三步输出值)

2020年4月20日

修改mysql 密码

进入bin目录

mysql -uroot -p

输入密码

use mysql

update user set password=password('admin')where user = 'root';

flush privileges;刷新启用


windows查看安装目录

mysql -uroot -p

输入密码

show variables like "%char%";


Linux查看安装目录

1.whereis mysql

2.find

3.ps -aux|grep mysql

2020年4月26日

Spring事务

    1.PROPAGATION_REQUIRED: 

支持当前事务,没有则新建


2.PROPAGATION_REQUIRESNEW: 启动一个新的, 不依赖于环境的 "内部"事务. 这个事务将被完全 commited 或 rolled back 而不依赖于外部事务, 它拥有自己的隔离范围, 自己的锁, 等等.

              当内部事务开始执行时, 外部事务将被挂起, 内务事务结束时,外部事务将继续执行.

                    (适合于在一个事务中,新开一个事务,且2个事务互不干预)


3.PROPAGATION_SUPPORTS:支持当前事务,如果当前没有事务,就以非事务方式执行


4.PROPAGATION_MANDATORY:支持当前事务,如果当前没有事务,就抛出异常


5.PROPAGATION_NOT_SUPPORTED:以非事务方式执行,如果当前存在事务,就把当前事务挂起。也就是说业务方法不需要事务


6.PROPAGATION_NEVER:以非事务方式执行,如果当前存在事务,则抛出异常。也就是说业务方法绝对不能在事务范围内执行


7.PROPAGATION_NESTED:开始一个 "嵌套的" 事务,  它是已经存在事务的一个真正的子事务. 潜套事务开始执行时,  它将取得一个 savepoint. 如果这个嵌套事务失败,

       我们将回滚到此 savepoint. 潜套事务是外部事务的一部分, 只有外部事务结束后它才会被提交.

              (外部的事务的提交和回滚,会带动嵌套事务,嵌套事务异常回滚,会回到savepoint. 不影响之前改变)



手动提交/回滚事务

[if !supportLists]1.     [endif]//1.获取事务定义

       DefaultTransactionDefinition def = new DefaultTransactionDefinition();

       //2.设置事务隔离级别,开启新事务

       def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

       //3.获得事务状态,相当于开启事物

       TransactionStatus transactionStatus =transactionManager.getTransaction(def);

4//没有问题  手动提交事务  保证新开的线程在数据能查询到数据

        transactionManager.commit(transactionStatus);

2.TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();


2020年4月27日

1java后台简单操作数据库


 Db类型  query方法  Db.use().excute(sql) /.tx会自动提交事务自动关闭连接

 DbUtil

Db use = Db.use();

use.tx(db -> {


for(String

sql:entry.getValue()){


use.execute(sql);


}

})

;



Connection conn =Db.use().getConnection();

PreparedStatement createIndex = conn.prepareStatement(createIndexSql.toString());

SqlExecutor.executeUpdate(createIndex);

conn.commit();


1.使用线程池(局部的线程池方法结束关闭,全局的看业务)

 场景简单直接private ExecutorService executorServiceToCreateMarkTask =Executors.newFixedThreadPool(50);

       可能导致oom,blockQuene的大小没设置

       手动设置参数 ExecutorService executorService = new ThreadPoolExecutor(1,1,10,

TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)); (超过100会抛出异常)

 复杂场景  自己申明一个线程池对象



等待子线程结束在执行主线程

CountDownLatch

在子线程中CountDownLatch.countDown()

主线程CountDownLatch.wait(),CountDownLatch为0则不在阻塞

https://www.jianshu.com/p/edd7cb4eafa0 线程池经典案例

2020年5月6日

多线程 异步api   CompletableFuture

https://www.jianshu.com/p/cacb8162f409


2020年5月13日

服务器卡死内存溢出定位具体代码

[if !supportLists]1.    [endif]Top 找出高占用率进程pid

[if !supportLists]2.    [endif]pwdx pid(可省略步骤)

[if !supportLists]3.    [endif]top oder by with Pid:1040 // 首先按进程负载排序找到  maxLoad(pid)

[if !supportLists]4.    [endif]top -Hp 进程Pid:1073   //找到相关负载 线程PID

[if !supportLists]5.    [endif]printf “0x%x\n”线程PID:0x431 //将线程PID转换为 16进制,为后面查找 jstack 日志做准备

[if !supportLists]6.    [endif]jstack  进程PID | vim +/十六进制线程PID -        //例如:jstack 1040|vim +/0x431 -

[if !supportLists]7.    [endif] 



2020年6月16日

手动引入第三方jar

[if !supportLists]1.    [endif]resources下创建lib文件夹考入jar包

[if !supportLists]2.    [endif]配置pom依赖


         org.opencv

         org.opencv

         system

         ${project.basedir}/src/main/resources/lib/opencv-347.jar


        maven-compiler-plugin


               1.8

               1.8

               UTF-8


                      ${project.basedir}/src/main/resources/lib




2020年7月2日入参

[if !supportLists]1.    [endif]get请求 不能用RequestBody,List《String》@RequestParam注解 不加consume json

[if !supportLists]2.    [endif]post请求 不用RequestParam,用RequestBody,List不加consume json,list





2020年7月13日

Jsonobject put的值 顺序和放入不一致,原因底层默认是hashmap存的方式,可以修改为linkedhashmap

JsonObjcect jo = new JsonObject(newLinkedHashMap())


2020年7月22日

Springboot后台返给前端的参数修改:

@restcontroller 或者@responceBody

定义配置类实现WebMvcConfigurer或者继承WebMvcConfigurerAdapter

返回一个HttpMessageConverter。


2020年7月24日

Idea2017使用junit4测试


org.springframework.boot


spring-boot-starter-test


test




org.junit.vintage


junit-vintage-engine




org.junit.jupiter


junit-jupiter-api




junit


junit


4.12

2020年8月10日

1、I/O流加强

java.io.InputStream 中增加了新的方法来读取和复制 InputStream 中包含的数据:

readAllBytes:读取InputStream 中的所有剩余字节

readNBytes: 从InputStream 中读取指定数量的字节到数组中

transferTo:读取InputStream 中的全部字节并写入到指定的 OutputStream 中


java.util.Formatter:

定义一个单例的formatter, formatter.format(regex, obj … args);

%d int %s String

Comparator 接口


String response =HttpRequest.post(requestUrl).header(Header.CONTENT_TYPE, "application/json;charset=UTF-8")

        .body(JSONUtil.parse(modelBackInfo).toString()).timeout(

20000).execute().body();


2020年8月13日

1、I/O流加强

java.io.InputStream 中增加了新的方法来读取和复制 InputStream 中包含的数据:

readAllBytes:读取InputStream 中的所有剩余字节

readNBytes: 从InputStream 中读取指定数量的字节到数组中

transferTo:读取InputStream 中的全部字节并写入到指定的 OutputStream 中


java.util.Formatter:

定义一个单例的formatter, formatter.format(regex, obj … args);

%d int %s String

Comparator 接口


2020年9月7日

[if !supportLists]1.    [endif]禁止使用float 和double类型,使用bigdecimal,避免精度丢失

BigDecal b = new BigDecimal(Double.toString(0.1d))

BigDecal b = new BigDecimal().valueOf(0.1D)

[if !supportLists]2.    [endif]tinyint一个字节   smallint  两个字节   MEDIUMINT三个字节  int 4个字节  BIGINT 8个字节。

tinyint(1)  和 tinyint(3) 没什么区别,占用字节都是一位,存储范围都是一样的

tinyint(3) zerofill ,当插入的数据少于3位的时候,左边自动补零,这才是限制显示长度

tinyint数据库,后台用boolean和integer都行

[if !supportLists]3.    [endif]聚集索引和普通索引

聚集:主键索引,或者非null的唯一索引列

普通索引:复用索引,唯一索引等…

覆盖索引:不需要再次回表查询的索引,如主键索引,复核索引等,


2020年9月9日

1.try with resource (实现了autocloseable接口的类 自动关闭try,后声明先关闭)

 try(InputStream in = new FileInputStream(src);

        OutputStream out = new FileOutputStream(dst)) {

       byte[] buff = new byte[1024];

       int n;

       while ((n = in.read(buff)) >= 0) {

           out.write(buff, 0, n);

       }

    }catch (IOException e) {

       e.printStackTrace();

}


2020年9月11日

https://pkgs.org/search/?q=pcre-devel 插件依赖库

解压安装的镜像(完备的)然后取package找到拷贝到服务器,执行rpm -Uvh ./*.rpm --nodeps –force




2020年9月27日

本地idea 联调服务器代码

[if !supportLists]1.    [endif]本地添加remote 启动


[if !supportLists]2.    [endif]服务器代码启动 指定上述配置


nohup-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=3005 java -jar ai-survery-1.0.0.jar &

[if !supportLists]3.    [endif]idea启动即可


2020年9月29日星期二

是不小心同时按到了Windows键+ctrl键+C 所以才会变黑白


2020年10月9日星期五

Mapstruct 替换beanutiles。Copy

https://blog.csdn.net/qq_34530405/article/details/83586512


2020年10月10日

双重排序空值问题


2020年10月27日

备份本地yum源

 mv/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

1

2.获取阿里yum源配置文件


 wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo

1

3.更新cache


 yummakecache

1

4.安装


 yum-y update


2020年12月30日星期三

@Accessors(chain = true) 支持set方法返回对象

@SuperBuilder 支持.build链式变成

@Range 验证前端的数字参数大小

2021年4月29日

springboot 外部依赖打包

1.file-projectstructure - libraries -> + 依赖

2.打包包括

            opencv

            opencv

            347

            system

            ${project.basedir}/src/main/resources/opencv-347.jar

       

       

           

                org.springframework.boot

                spring-boot-maven-plugin

               

                    true

                    true

               

           

       

   


2021年4月29日

nginx 导入文件 413 404;

1.排查原请求走网关,现在走nginx,所以限制上传文件的大小,没配置默认1M;

2.看nginx的错误日志

3.注意nginx是那个角色启动,导致文件夹的下载上传文件,被nginx的权限过来拦截

新增:

http节点下

client_body_buffer_size 650M;

    client_max_body_size 650M;

你可能感兴趣的:(项目总结)