JAVA利用properties实现的一个小功能

这次说的小功能呢,其实是跟项目中用到的知识有关,虽然对别人可能会起不到什么作用,但博客是我记录知识的好地方,所以便总结在此

目标功能:准备好N个账户,名字的命名形式为:用户名+编号,每次登陆使用一个不同用户,当然这个账户不能重复,

程序实现原理:首先呢准备好一个List将用户个数的集合放入进去:这个LIST支持的得是Long类型而不是int,为什么这么做呢,因为后面要用到System.currentTimeMillis();然后呢遍历找出list集合中最小的数字,将索引记住,设置list集合中这个索引的值为System.currentTimeMillis();这样的话list集合中的数字就有个最大的了,一次类推以后每遍历出来一个最小的就给他赋值为System.currentTimeMillis();,这样这N个用户总会轮流的来使用

好了,说的可能不是太清晰,看看代码就OK了,直接运行看不出效果得在服务器上跑出来

user.properties

user.prefixname=user
user.count=20

处理程序

package com.cn.util.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class PropertiesRead {
	public static InputStream inStream = Thread.currentThread()
			.getContextClassLoader().getResourceAsStream("user.properties");
	public static Properties properties = new Properties();
	public static List<Long> caches=new ArrayList<Long>();
	public static String accname;
	public static int count;
	static {
		try {
			properties.load(inStream);
			accname = (String) properties.get("user.prefixname");
			count = Integer.valueOf(properties.getProperty("user.count"));
			for (int i = 1; i <= count; i++) {
				caches.add(Long.valueOf(i));
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		
		raedProperties();
		// int random=(int)(Math.random()*10)+1;
		// System.out.println(random);
		// System.out.println(System.currentTimeMillis());
	}

	public static String raedProperties() {
		int size=caches==null?0:caches.size();
		Long flag=Long.MAX_VALUE;
		int  index=0;
		for(int i=0;i<size;i++){
			if(flag>caches.get(i)){
				flag=caches.get(i);
				index=i;
			}
		}
		caches.set(index, System.currentTimeMillis());
		System.out.println(index+"==="+flag+"==="+caches.get(index));
		String loginName=accname+(index+1);
		System.out.println(caches);
		System.out.println("登录名称"+loginName);
      return loginName;
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现一个富文本编辑器可以使用第三方库,比如CKEditor、TinyMCE等。这些库都提供了一些基础的富文本编辑功能,比如加粗、斜体、下划线、字体大小、字体颜色等,也支持插入图片、视频等多媒体内容。 下面介绍如何在Spring Boot中使用CKEditor实现富文本编辑器。 1. 引入CKEditor的相关依赖 在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>com.github.alex-leonhardt</groupId> <artifactId>ckeditor</artifactId> <version>4.15.1</version> </dependency> ``` 2. 配置CKEditor 在application.properties中添加以下配置: ```properties spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ ckeditor.basePath=/js/ckeditor/ ``` 这里将CKEditor的静态资源文件放在了src/main/resources/static/js/ckeditor目录下。 3. 创建一个富文本编辑器页面 在src/main/resources/templates目录下创建一个editor.html页面,代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>富文本编辑器</title> <script src="/js/ckeditor/ckeditor.js"></script> </head> <body> <textarea name="content" id="editor"></textarea> <script> CKEDITOR.replace('editor'); </script> </body> </html> ``` 这里引入了CKEditor的js文件,并在页面中创建了一个textarea元素,然后使用CKEDITOR.replace()方法将textarea转换成一个富文本编辑器。 4. 创建一个Controller 在src/main/java目录下创建一个EditorController类,代码如下: ```java @Controller public class EditorController { @GetMapping("/editor") public String editor() { return "editor"; } } ``` 这里使用@GetMapping注解将editor()方法映射到/editor路径,返回editor.html页面。 5. 运行程序 运行程序,在浏览器中访问http://localhost:8080/editor,即可看到一个富文本编辑器界面。可以在编辑器中输入文本、插入图片等,然后保存到数据库或者其他地方。 以上就是使用Spring Boot和CKEditor实现富文本编辑器的步骤。需要注意的是,CKEditor的配置和使用方法可能会随着版本的更新而发生变化,具体可以参考CKEditor的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值