杂货货

杂货货二维数组遍历 定义一个整型数组 3 行 4 列 inta newint 3 4 获取行数 3 行 intlenY a length 获取列数 4 列 intlenX a 0 length a lengt

大家好,欢迎来到IT知识分享网。

jquery引入

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

二维数组遍历

//定义一个整型数组:3行4列 int a[][] = new int[3][4]; //获取行数---3行 int lenY = a.length; //获取列数---4列 int lenX = a[0].length; 

a.length是二维数组的行数,每一行是一个一维数组。

 //方法1 public static void printArr1(int[][] arr) { for(int x=0; x<arr.length; x++) { for(int y=0; y<arr[x].length; y++) { System.out.print(arr[x][y]+" "); } System.out.println(); } } 
//方法2 public static void printArr2(int[][] arr) { //遍历二维数组中每一个一维数组 for(int[] cells : arr) { //遍历一维数组中每一个元素 for(int cell : cells) { System.out.print(cell+" "); } System.out.println(); } 

输出数据对齐问题

System.out.printf("%-6s",a); S代表字符串
System.out.printf("%-6d",b); D代表数字
把中间-去掉,表示右对齐

mybatis动态SQL模糊查询
第一种可能有sql注入问题。

<if test="sname !=null and sname!=''"> and sname like '%${sname}%' and sname like concat(concat('%',#{ 
   sname}),'%') </if> 

动态和静态区别

静态页面的return默认是跳转到/static/index.html,当在pom.xml中引入了thymeleaf组件动态跳转会覆盖默认的静态跳转
默认就会跳转到/templates/index.html,注意看两者return代码也有区别,动态没有html后缀。
在引入thymeleaf后, 如果仍需要访问~/static/index.html, 则可以使用重定向

springboot实现定时器
在这里插入图片描述
把springboot项目打成jar包

  • 复制项目到任一新建文件夹
  • 打开cmd,进入项目文件夹,输入mvn package
  • 进入项目的target文件夹,会生成一个jar包
  • 再cmd进入target,然后java -jar C:\code\honeybadger\target\honeybadger-0.0.1-SNAPSHOT.jar(把jar包拖入即可)

双击package,自动生成jar包到本项目的target目录下
在这里插入图片描述
在这里插入图片描述

SHA256加密加盐

如果被保护数据仅仅用作比较验证,在以后不需要还原成明文形式,则使用哈希;如果被保护数据在以后需要被还原成明文,则需要使用加密。

例如,你正在做一个系统,你打算当用户忘记自己的登录口令时,重置此用户口令为一个随机口令,而后将此随机口令发给用户,让用户下次使用此口令登录,则适合使用哈希。实际上很多网站都是这么做的,想想你以前登录过的很多网站,是不是当你忘记口令的时候,网站并不是将你忘记的口令发送给你,而是发送给你一个新的、随机的口令,然后让你用这个新口令登录。这是因为你在注册时输入的口令被哈希后存储在数据库里,而哈希算法不可逆,所以即使是网站管理员也不可能通过哈希结果复原你的口令,而只能重置口令。 相反,如果你做的系统要求在用户忘记口令的时候必须将原口令发送给用户,而不是重置其口令,则必须选择加密而不是哈希。

public class SHA256Encrypt { 
    // private static String SALT = UUID.randomUUID().toString(); public static String sha256(String str) { 
    try { 
    MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] data = str.getBytes("UTF-8"); md.update(data); byte[] bytes = md.digest(); StringBuffer stringBuffer = new StringBuffer(); String temp = null; for (int i = 0; i < bytes.length; i++) { 
    temp = Integer.toHexString(bytes[i] & 0xFF); if (temp.length() == 1) { 
    stringBuffer.append("0"); } stringBuffer.append(temp); } return stringBuffer.toString(); } catch (Exception e) { 
    e.printStackTrace(); return "失败!!!"; } } 

设置java实现定时器

设定2000毫秒后执行

public static void timer1(){ 
    Timer nTimer = new Timer(); nTimer.schedule(new TimerTask() { 
    @Override public void run() { 
    System.out.println("----设定要指定任务-----"); } },2000); } 

延迟5000毫秒,每1000毫秒执行一次

 public static void timer2() { 
    Timer timer = new Timer(); timer.schedule(new TimerTask() { 
    public void run() { 
    System.out.println("-------延迟5000毫秒,每1000毫秒执行一次--------"); } }, 5000, 1000); } 

延迟5000毫秒,每1000毫秒执行一次

 public static void timer3() { 
    Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { 
    public void run() { 
    System.err.println("-------延迟5000毫秒,每1000毫秒执行一次--------"); } }, 5000, 1000); } 
BindingResult

SpringBoot 结合 JSR303 对前端数据进行校验
在这里插入图片描述
List errorList = bindingResult.getAllErrors(); 获取多个error信息
在这里插入图片描述

@notnull @notempty @notblank 区别

@notnull @notempty @notblank 的区别

@notempty 用在集合类上
@notblank 用在string上,包括””和null
@notnull用在包装类上 包括null

@before和@beforeclass区别

重定向时,用map传到前端页面不好使,但会在地址栏显示
map.put(“member”,member);
${param.member}可以获取地址栏里member值

当参数不是必须的时,@requsetparam(required=false,defaultvalue=1)

B树逻辑实现

https://www.bilibili.com/video/av?p=1

在这里插入图片描述

java URL获取页面内容
public class HttpTry { 
    public static void main(String[] args) throws Exception { 
    URL url = new URL("http://localhost:8080/login"); InputStream is = url.openStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String len = null; StringBuilder sb = new StringBuilder(); while ((len = br.readLine()) != null) { 
    sb.append(len).append("\n"); } System.out.println(sb.toString()); } } 

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/141906.html

(0)
上一篇 2025-05-13 22:33
下一篇 2025-05-13 22:45

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信