springframework

RestTemplate

RestTemplate restTemplate = new RestTemplate();

//请求头设置参数格式
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);

//http实体
HttpEntity<String> httpEntity = new HttpEntity<>(String jsonStr,httpHeaders);

//发送请求
restTemplate.put("url",httpEntity);

lua

*.lua

//赋值
local var1 = redis.call('[order]',KEYS[1],ARGV[1],ARGV[2]);
//载入脚本
DefaultRedisScript<Object> objectDefaultRedisScript = new DefaultRedisScript<Object>();
objectDefaultRedisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("*.lua")));

Object 0 = redisTemplate.execute(objectDefaultRedisScript, [List<> key],ARGV[1],ARGV[2]);

Amqp

pom.xml

		<!--自动导的不是这个,不能自动注入amqpTemplate-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>

application.yml

spring:
  rabbitmq:
      host: $[host}
      port:${port}
      username: ${username}
      password: $[pasword}
      virtual-host:${virtualHosts}

component

@Autowired
AmqpTemplate amqpTemplate;

/**
	发送消息
	var1: 交换机名称,使用默认交换机设置""
	var2:路由key,不是DIRECT模式时绑定队列,没有写"",可以多段*.*.*(*匹配一个,#匹配多个)
	var3:消息内容
*/
void function(){
        amqpTemplate.convertAndSend(String var1, String var2, Object var3);
 }

//接收消息
//不用交换机
@RabbitListener(queuesToDeclare = @Queue("RSA"))
//用交换机
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "queueName",durable = "true"),
    exchange = @Exchange(value = "exchangeName"),
    key = {"routingKey"}))
public void function(String msg){}

config

//转换成json传输
@Configuration 
public class RabbitConfig { 
	@Bean 
	public Jackson2JsonMessageConverter messageConverter(){ 
		return new Jackson2JsonMessageConverter();
	} 
}

BCryptPasswordEncoder

component

@Component
public class encodeConfig {
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder(){
    	//随机安全码, yml配置${random.uuid}也可以生成String
        SecureRandom secureRandom = new SecureRandom(UUID.randomUUID().toString().getBytes());
        return new BCryptPasswordEncoder(10/*加密次数*/,secureRandom);
    }
}

server

	@Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;
   
    public void fuction(){
    	//加密
        bCryptPasswordEncoder.encode(""));
    }

scheduling

Application

@SpringBootApplication
//开启定时任务
@EnableScheduling
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

Schedule

@Component
public class Schedule {
	/**
		    秒 分 时 日 月 周 年
            ,时点 /间隔 -范围 *所有
            L 日和周后表示最后一个
            W 日后加表示工作日
            日 和 周 其中一个要是 ?
            [起始时间]/[间隔时间],之前的时间要设为0
      */
    @Scheduled(cron = "")
    //单位毫秒
    //上一次任务完成后开始计时
    @Scheduled(fixedDelay = 1000L)
    //上一次任务开始后开始计时
    @Scheduled(fixedRate = 1000L)
    public void schedule(){}
}

application.yml

#可以防止任务执行时间太长阻塞任务执行
spring:
  task:
    scheduling:
      pool:
        size: 2

BeanUtils

复制相同的filed

BeanUtils.copyProperties(Object source, Object target);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值