首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,085 阅读
2
类的加载
742 阅读
3
Spring Cloud OAuth2.0
726 阅读
4
SpringBoot自动装配原理
691 阅读
5
集合不安全问题
586 阅读
笔记
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
蘇阿細
累计撰写
389
篇文章
累计收到
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
页面
统计
关于
搜索到
51
篇与
的结果
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-06-01
Java Web用户角色与权限的管理
以SSM框架为例后台管理系统——给用户添加角色流程分析与设计1.流程分析注:图片来源itheima的ssm课件2.UserController //给用户添加角色 @RequestMapping("/addRoleToUser.do") public String addRoleToUser(@RequestParam(name = "userId",required = true) Integer userId,@RequestParam(name = "ids",required = true) Integer[] roleIds){ //单个用户可以对应多个角色,所以采用数组存userService.findOtherRoles(id)查询出来的角色id userService.addRoleToUser(userId,roleIds); return "redirect:findAll.do"; } //查询用户以及用户可以添加的角色 @RequestMapping("/findUserByIdAndAllRole.do") public ModelAndView findUserByIdAndAllRole(@RequestParam(name = "id",required = true) Integer id){ ModelAndView mv = new ModelAndView(); //1.根据用户id查询用户 Userinfo userinfo = userService.findById(id); //2.根据用户id查询可以添加的角色 List<Role> roles = userService.findOtherRoles(id); mv.addObject("user",userinfo); mv.addObject("roleList",roles); mv.setViewName("user-role-add"); return mv; }3.UserService接口void addRoleToUser(Integer userId, Integer[] roleIds);4.UserServiceImpl //给用户添加角色 @Override public void addRoleToUser(Integer userId, Integer[] roleIds) { for (Integer roleId : roleIds) { //(单个用户可以对应多个角色)给用户添加角色时,从数组中遍历取出角色id userDao.addRoleToUser(userId,roleId); } } //根据用户id查询可以添加的角色 @Override public List<Role> findOtherRoles(Integer id) { return userDao.findOtherRoles(id); }5.UserDao//查询用户可以添加的角色@Select("select * from role where id not in(select roleId from users_role where userId=#{id})") List<Role> findOtherRoles(Integer id); @Insert("insert into users_role(userId,roleId) values(#{userId},#{roleId})") //当传入mybatis的参数有多个时,必须写@Param void addRoleToUser(@Param("userId") Integer userId,@Param("roleId") Integer roleId);注:添加权限与添加角色同理
2020年06月01日
90 阅读
0 评论
0 点赞
1
...
6
7