首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,087 阅读
2
类的加载
742 阅读
3
Spring Cloud OAuth2.0
726 阅读
4
SpringBoot自动装配原理
691 阅读
5
集合不安全问题
589 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
FastApi
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
390
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
FastApi
页面
统计
关于
搜索到
390
篇与
的结果
2020-11-20
IP
ip地址:InetAddress唯一定位一台网络上的计算机127.0.0.1:本机localhostip地址的分类ipv4/ipv6IPV4:4个字节组成,0~255,约42亿个IPV6:128位,8个无符号整数,例如240e:1234:abcd:0010:2b58:9900:add2:b156公网(互联网)--私网(局域网)ABCD段package com.network.lesson01; import java.net.InetAddress; import java.net.UnknownHostException; /** * @Author suaxi * @Date 2020/11/20 16:54 */ public class TestInetAddress { public static void main(String[] args) { try { //查询本机地址 InetAddress host1 = InetAddress.getByName("localhost"); System.out.println(host1); //查询网站ip地址 InetAddress host2 = InetAddress.getByName("www.baidu.com"); System.out.println(host2); //常用方法 System.out.println(host2.getAddress()); System.out.println(host2.getCanonicalHostName()); //规范的名字 System.out.println(host2.getHostAddress()); //ip System.out.println(host2.getHostName()); //域名或自己电脑的名字 } catch (UnknownHostException e) { e.printStackTrace(); } } }
2020年11月20日
76 阅读
0 评论
0 点赞
2020-11-20
面向对象小结
1、类与对象类是一个模板:抽象 对象是一个具体的实例2、方法定义 调用3、对应的引用引用类型:基本类型(8种)对象是通过引用来操作的:栈------>堆4、属性:字段Field 成员变量默认初始化: 数字: 0 0.0 char: u0000 boolean: false 引用: null修饰符 属性类型 属性名 = 属性值private String name = null;5、对象的创建和使用必须使用new关键字创建对象,构造器:Person person = new Person();对象的属性 person.name;对象的方法 person.sleep();6、类静态的属性 属性动态的行为 方法封装、继承、多态1、封装高内聚、低耦合高内聚:类的内部数据操作细节自己完成,不允许外部干涉低耦合:仅暴露少量的方法给外部使用封装(数据的隐藏)通常,应该禁止直接访问一个对象中数据的直接表示,而应通过操作接口来访问,这称为信息的隐藏1、提高程序的安全性2、隐藏代码的实现细节3、统一接口4、系统可维护性2、继承继承的本质是对某一批类的抽象,从而实现对现实世界更好的建模JAVA类中只有单继承,没有多继承继承是类和类之间的一种关系,除此之外,还有依赖、组合、聚合等在继承关系中,一个为子类(派生类),一个为父类(基类),子类继承父类,使用关键字extends来表示子类和父类之间,从严格意义上来说应该具有 “is a” 的关系super注意点:1、super调用父类得构造方法,必须在构造方法的第一个2、super只能出现在子类的方法或构造方法中3、super和this不能同时调用构造方法与 this 的区别代表的对象不同this:本身调用者这个对象super:代表父类对象的引用前提this:没有继承也可以使用super:只能在继承条件下使用构造方法this():本类的构造super():父类的构造重写重写:需要有继承关系,子类重写父类的方法方法名必须相同参数列表必须相同修饰符:范围可以扩大,但不能缩小 public>protected>default>private抛出的异常:范围,可以被缩小,但不能扩大 ClassNotFoundException --> Exception(大)重写,子类的方法和父类必须要一致,方法体不同为什么需要重写?父类的功能,子类不一定需要,或者不一定满足3、多态同一方法可以根据发送对象的不同而采用多种不同的行为方式一个对象的实际类型是确定的,但可以指向对象的引用的类型有很多(父类,有关系的类)多态注意事项:1、多态是方法的多态,和属性没有关系2、父类和子类有联系 类型转换异常 ClassCastException3、存在条件:继承关系,方法需要重写,父类引用指向子类 Father f = new Son();以下情况不能被重写static方法,属于类,不属于任何一个方法final 终类(不能被继承)private 方法(私有的)类型转换:1、父类引用指向子类2、子类 > 父类(向上转换)3、父类 > 子类(向下转换)需要强转4、方便方法的调用,减少重复的代码抽象类abstract可以用来修饰方法,也可以用来修饰类,如果修饰方法,那么该方法就是抽象方法,修饰类时同理。抽象类中可以没有抽象方法,但是有抽象方法的类一定要声明为抽象类。抽象类不能使用new关键字来创建对象,它是用来让子类继承的。子类继承抽象类,那么就必须要实现抽象类没有实现的抽象方法,否则该子类也要声明为抽象类。//1、不能new这个抽象类,只能靠子类去实现它:约束 //2、抽象类中可以写普通方法 //3、抽象方法必须在抽象类中 //抽象的抽象:约束接口接口的本质就是规范,定义的是一组规则,体现了现实世界中“如果你是......则必须能......”的思想。作用:1、约束2、定义一些方法,让不同的人实现3、public abstract4、public static final5、接口不能被实例化,接口中没有构造方法
2020年11月20日
167 阅读
0 评论
0 点赞
2020-11-19
Exception与Error
异常什么是异常(Exception)?指程序运行过程中出现的不期而至的各种状况,例如:找不到文件,网络连接失败,非法参数等1、检查性异常,用户错误或问题引起的异常2、运行时异常,与检查性异常相反,运行时异常可以在编译时被忽略3、错误(Error),错误不是异常,而是脱离程序员控制的问题在Exception分支中有一个重要的子类RuntimeException(运行时异常)ArrayIndexOutOfBoundsException 数组下标越界NullPointerException 空指针异常ArithException 算数异常MissingResourceException 丢失资源ClassNotFoundException 找不到类等异常,这些异常是不检查异常,程序中可以选择捕获处理,也可以不处理这些异常一般是由程序逻辑错误引起的,应尽量避免package com.exception; /** * @Author suaxi * @Date 2020/11/19 16:16 */ public class Test { public static void main(String[] args) { int a = 1; int b = 0; try { // 监控区域 System.out.println(a/b); }catch (Error e){ //catch(想要捕获的异常类型) System.out.println("Error"); e.printStackTrace(); //打印错误的栈信息 }catch (Exception e){ System.out.println("Exception"); }catch (Throwable t){ System.out.println("Throwable"); }finally { System.out.println("finally"); } } public void a(){ b(); } public void b(){ a(); } } package com.exception; /** * @Author suaxi * @Date 2020/11/19 16:36 */ public class Test01 { public static void main(String[] args) { try { new Test01().test(1,0); } catch (ArithmeticException e) { e.printStackTrace(); } } public void test(int a,int b) throws ArithmeticException{ if (b==0){ throw new ArithmeticException(); //主动抛出异常 } } } ErrorError类对象由JAVA虚拟机生成并抛出,大多数错误与代码编写者所执行的操作无关Java虚拟机运行错误(Virtual MachineError),当JVM不再有继续执行所需的内存资源时,将出现OutOfMemoryError,这些错误出现时,JVM一般会选则线程终止还有发生在虚拟机试图执行应用时,如类定义错误(NoClassDefFoundError)、链接错误(LinkageError)。这些错误是不可检查的,因为它们在应用程序的控制和处理能力之外,而且绝大多数是程序运行时不允许出现的状况。Exception与Error的区别:Error通常是灾难性的致命的错误,是程序无法控制和处理的,当出现这些异常时,JVM一般会选择终止线程;Exception通常情况下是可以被程序处理的,在程序中应尽可能的去处理这些异常。
2020年11月19日
98 阅读
0 评论
0 点赞
2020-11-16
稀疏数组
package com.example.demo.Array; /** * @Description 稀疏数组 * @Author suaxi * @Date 2021/8/17 14:43 */ public class SparseArrayDemo { public static void main(String[] args) { //1.创建一个二维数组 11*11 0:没有棋子 1:白棋 2:黑棋 int[][] a = new int[11][11]; a[1][2] = 1; a[2][3] = 2; //输出原始数组 System.out.println("原始数组:"); for (int[] ints : a) { for (int anInt : ints) { System.out.print(anInt + "\t"); } System.out.println(); } System.out.println("===========================分割线================================="); //2.转换为稀疏数组 //获取有效值的个数 int sum = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { if (a[i][j] != 0) { sum++; } } } System.out.println("有效值的个数:" + sum); System.out.println("===========================分割线================================="); //创建一个稀疏数组的数组 int[][] b = new int[sum + 1][3]; b[0][0] = a.length; b[0][1] = a.length; b[0][2] = sum; //遍历二维数组,将非零值存入稀疏数组 //记录行数 int count = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { if (a[i][j] != 0) { count++; //第几行的第一个数字存横坐标 b[count][0] = i; //第几行的第二个数字存纵坐标 b[count][1] = j; //第几行的第三个数字存具体的值 b[count][2] = a[i][j]; } } } System.out.println("稀疏数组:"); for (int i = 0; i < b.length; i++) { System.out.println(b[i][0] + "\t" + b[i][1] + "\t" + b[i][2] + "\t" ); } System.out.println("===========================分割线================================="); //还原稀疏数组 System.out.println("还原"); //1.读取稀疏数组 int[][] c = new int[b[0][0]][b[0][1]]; //2.将其中的元素还原为对应的值 for (int i = 1; i < b.length; i++) { c[b[i][0]][b[i][1]] = b[i][2]; } //3.打印 for (int[] ints : c) { for (int anInt : ints) { System.out.print(anInt + "\t"); } System.out.println(); } } }
2020年11月16日
74 阅读
0 评论
0 点赞
2020-11-16
冒泡排序
package array; import java.util.Arrays; /** * @Author suaxi * @Date 2020/11/16 16:16 * 冒泡排序 * 1、比较数组中,两个相邻的元素,如果第一个数比第二个数大,就交换它们的位置 * 2、每一次比较,都会产生出一个最大,或者最小的数字 * 3、下一轮则可以少一次排序 * 4、依次循环,直到结束 */ public class ArrayDemo07 { public static void main(String[] args) { int[] a = {1,15,67,349,394,80,347,5,2,35}; //int[] a ={1, 2, 5, 15, 35, 67, 80, 347, 349, 394}; int[] sort = sort(a); System.out.println(Arrays.toString(sort)); } public static int[] sort(int[] array){ int temp = 0; boolean flag = false; //外层循环,判断程序需要运行多少次 for (int i = 0; i < array.length; i++) { //内层循环,比较相邻的两个数,如果第一个数比第二个数大,则交换位置 for (int j = 0; j < array.length - 1 - i; j++) { if (array[j+1]<array[j]){ temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; flag = true; } } if (flag==false){ break; } } return array; } }
2020年11月16日
186 阅读
0 评论
0 点赞
2020-11-09
SQL注入
SQL注入sql存在漏洞,会被攻击导致数据泄露,SQL会被拼接 orimport com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/9 9:57 */ public class SQlzhuru { public static void main(String[] args) { //login("sunxiaochuan","12345");正常登录 login(" 'or '1=1"," 'or '1=1"); //技巧 } //登录 public static void login(String username,String passwd){ Connection conn = null; Statement st = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 //SELECT * FROM users WHERE `name`='sunxiaochuan' AND `passwd`='12345'; //SELECT * FROM users WHERE `name`='' or '1=1' AND `passwd`='' or '1=1'; String sql = "SELECT * FROM users WHERE `name`='"+username+"' AND `passwd`='"+passwd+"'"; rs = st.executeQuery(sql); //查询完毕会返回一个结果集 while (rs.next()){ System.out.println(rs.getString("name")); System.out.println(rs.getString("passwd")); System.out.println("================="); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } }
2020年11月09日
71 阅读
0 评论
0 点赞
2020-11-09
PreparedStatement对象
可以防止SQL注入,效率更好。1、新增package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.util.Date; import java.sql.PreparedStatement; import java.sql.SQLException; /** * @Author suaxi * @Date 2020/11/9 10:12 */ public class TestInsert { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "insert into users(id,name,passwd,email,birthday) values(?,?,?,?,?)"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setInt(1,5); pstm.setString(2,"liubo"); pstm.setString(3,"12345"); pstm.setString(4,"liubo@qq.com"); //注:sql.Date 数据库使用 java.sql.Date() // util.Date Java new Date().getTime() 获得当前时间戳 pstm.setDate(5,new java.sql.Date(new Date().getTime())); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("插入成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 2、删除package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; /** * @Author suaxi * @Date 2020/11/9 10:28 */ public class TestDelete { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "delete from users where id=?"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setInt(1,5); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 3、修改package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; /** * @Author suaxi * @Date 2020/11/9 10:28 */ public class TestUpdate { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; try { conn = JdbcUtils.getConnection(); //PreparedStatement与Statement的区别 //使用?占位符代替参数 String sql = "update users set `name`=? where id=?"; pstm = conn.prepareStatement(sql); //预编译SQl,先编译sql但不执行 //手动给参数赋值 pstm.setString(1,"孙笑川"); pstm.setInt(2,2); //执行 int i = pstm.executeUpdate(); if(i>0){ System.out.println("更新成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,null); } } } 4、查询package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * @Author suaxi * @Date 2020/11/9 10:34 */ public class TestSelect { public static void main(String[] args) { Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); String sql = "select * from users where id=?"; pstm = conn.prepareStatement(sql); //预编译 pstm.setInt(1,2); //传递参数 rs = pstm.executeQuery(); //执行 if (rs.next()){ System.out.println(rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,rs); } } } 5、防止SQL注入package com.sw.kuangshen.lesson03; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.*; /** * @Author suaxi * @Date 2020/11/9 9:57 */ public class SQlzhuru { public static void main(String[] args) { //login("dd","12345"); //正常登录 login("''or 1=1","12345"); } //登录 public static void login(String username,String passwd){ Connection conn = null; PreparedStatement pstm = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); //PreparedStatement防止SQL注入的本质,把传递进来的参数当作字符 //假设其中存在转义字符,例如 ' 会被直接转义 String sql = "select * from users where `name`=? and passwd=?"; pstm = conn.prepareStatement(sql); pstm.setString(1,username); pstm.setString(2,passwd); rs = pstm.executeQuery(); while (rs.next()){ System.out.println(rs.getString("name")); System.out.println(rs.getString("passwd")); System.out.println("================="); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,pstm,rs); } } }
2020年11月09日
103 阅读
0 评论
0 点赞
2020-11-08
statement对象
statement对象jdbc中的statement对象用于向数据库发送SQL语句,例如:想完成对数据库的增删查改,只需通过这个对象向数据库发送增删查改语句即可。Statement对象的executeUpdate方法,用于向数据库发送增、删、改的sql语句,executeUpdate执行完后,将会返回一个整数(即增删改语句导致了数据库几行数据发生了变化)。statement.executeQuery方法用于向数据库发送查询语句,executeQuery方法返回代表查询结果的resultSet对象。CRUD操作 --create使用executeUpdate(String sql)方法完成数据添加操作Statement st = conn.createStatement(); String sql = "insert into user(...) values(...)"; int num = st.executeUpdate(sql); if(num>0){ System.out.println("数据插入成功!"); }CRUD操作 --delete使用executeUpdate(String sql)方法完成数据删除操作Statement st = conn.createStatement(); String sql = "delete from user where id=1"; int num = st.executeUpdate(sql); if(num>0){ System.out.println("删除成功!"); }CRUD操作 --update使用executeUpdate(String sql)方法完成数据修改操作Statement st = conn.createStatement(); String sql = "update user set name='孙笑川' where id =1; int num = st.executeUpdate(sql); if(num>0){ System.out.println("修改成功!"); }CRUD操作 --read使用executeQuery(String sql)方法完成数据查询操作Statement st = conn.createStatement(); String sql = "select * from user; ResultSet rs = st.executeQuery(sql); while(re.next*()){ //根据获取列的数据类型,分别调用rs相应的方法映射到java对象中 }代码实现1、提取工具类package com.sw.kuangshen.utils; import java.io.InputStream; import java.sql.*; import java.util.Properties; /** * @Author suaxi * @Date 2020/11/8 21:06 */ public class JdbcUtils { private static String driver = null; private static String url = null; private static String username = null; private static String password = null; static{ try{ InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties"); Properties properties = new Properties(); properties.load(in); driver = properties.getProperty("driver"); url = properties.getProperty("url"); username = properties.getProperty("username"); password = properties.getProperty("password"); //1、驱动只用加载一次 Class.forName(driver); } catch (Exception e) { e.printStackTrace(); } } //获取连接 public static Connection getConnection() throws SQLException { return DriverManager.getConnection(url,username,password); } //释放资源 public static void release(Connection conn, Statement st, ResultSet rs){ if(rs!=null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(st!=null){ try { st.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn!=null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } 2、编写增删改的方法,都是用executeUpdate新增package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestInsert { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="INSERT INTO users(id,`name`,`passwd`,`email`,`birthday`)" + "VALUES(4,'dd','12345','dd@qq.com','1994-01-01')"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("插入成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 删除package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestDelete { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="DELETE FROM users WHERE id=1"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("删除成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 修改package com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:16 */ public class TestUpdate { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); //获取数据库连接 st = conn.createStatement(); //获得SQL的执行对象 String sql ="UPDATE users SET `name`='sunxiaochuan' WHERE id=2"; int i = st.executeUpdate(sql); if(i>0){ System.out.println("更新成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } } 3、查询 executeQuerypackage com.sw.kuangshen; import com.sw.kuangshen.utils.JdbcUtils; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * @Author suaxi * @Date 2020/11/8 21:45 */ public class TestSelect { public static void main(String[] args) { Connection conn = null; Statement st = null; ResultSet rs =null; try { conn = JdbcUtils.getConnection(); st = conn.createStatement(); String sql = "select * from users where id=2"; rs = st.executeQuery(sql); //查询完毕会返回一个结果集 while (rs.next()){ System.out.println(rs.getString("name")); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,rs); } } }
2020年11月08日
81 阅读
0 评论
0 点赞
1
...
43
44
45
...
49