博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
零碎知识总结[一]
阅读量:162 次
发布时间:2019-02-28

本文共 2963 字,大约阅读时间需要 9 分钟。

1>. spring配置注解context:annotation-config和context:component-scan区别

1.context:annotation-config

  • < context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean上面的注解,也就是显示的向Spring注册

  • 一般来说,像@ Resource 、@ PostConstruct、@Antowired这些注解在自动注入还是比较常用,所以如果总是需要按照传统的方式一条一条配置显得有些繁琐和没有必要,于是spring给我们提供< context:annotation-config/>的简化配置方式,自动帮你完成声明

2. context:component-scan

  • Spring 给我提供了context:component-scan配置,如下:
    在这里插入图片描述

3. 总结:

  • ①. < context:annotation-config />:仅能够在已经在已经注册过的bean上面起作用。对于没有在spring容器中注册的bean,它并不能执行任何操作

  • ②. < context:component-scan base-package=“XX.XX”/> :除了具有上面的功能之外,还具有自动将带有@component,@service,@Repository等注解的对象注册到spring容器中的功能

  • ③.在springMvc中如果使用了< mvc:annotation-driven >,会自动开启spring注解,可以不需要使用< context:annotation-config >来开启Spring注解

在这里插入图片描述

4. 自我见解:

  • ①. 在spring中,如果使用了context:component-scan 或 <dubbo:annotation package=" "> 可以不用开启context:annotation-config,而其他引入的配置文件如Spring-redis.xml等在监听器中加载这些配置文件
    在这里插入图片描述
  • ②. 在springMvc中如果使用了< mvc:annotation-driven >,会自动开启spring注解,可以不需要使用< context:annotation-config >来开启Spring注解。在SpringMvc中要在spring-mvc.xml中加上import resource=""
    在这里插入图片描述
  • ③. 如果不是在Spring或SpringMvc环境下,要加上 context:annotation-config开启注解,才能使用@Autowired
    在这里插入图片描述

2>. setInterval(doLoop(),1000) 和setInterval(doLoop,1000)的区别

  • ①. setInterval(doLoop()):定时器只会执行一次

  • ②. setInterval(doLoop):方法的引用,会被调用多次

3>. 使用两个工具类判断是否为空

  • ①. CollectionUtils.isNotEmpty(): List Names= new ArrayList<>();
1.当从数据库中查出的数据为NULL时,可以用CollectionUtils.isNotEmpty()来判断Names是否有值,值是否可用。2.CollectionUtils.isNotEmpty() 包含null,size=0等多种情况,太好用了。
  • ②. StringUtils.equals(validateCodeInRedis,validateCode)
// 比较两个字符串是否相等,如果两个均为null,则也认为相等  StringUtils.equals("", "");   //结果是true  StringUtils.equals(null, null);  //结果是true  StringUtils.equals(null, "");  //结果是false  StringUtils.equals("",null);  //结果是false  StringUtils.equals(null,"");  //结果是false  StringUtils.equalsIgnoreCase("ss", "Ss");  //不区分大小写--结果是true

4>. 认证和授权

  • 认证:只需要用户表就可以了,在用户登录时可以查询用户表t_user进行校验,判断 用户输入的用户名和密码是否正确

  • 授权过程:用户必须完成认证之后才可以进行授权,首先可以根据用户查询其角色,再 根据角色查询对应的菜单,这样就确定了用户能够看到哪些菜单。然后再根据用户的角 色查询对应的权限,这样就确定了用户拥有哪些权限

在这里插入图片描述

5>. 在mysql数据库中带条件查询不区分大小写

  • ①.问题的引出现在数据库存在name=abc,不存在name=ABC的;但是直接查询是都能查到abc数据的
select * from user where name='abc' select * from user where name='ABC'
  • ②. 解决方案
1.select * from user where binary name='abc' [使用binary关键字]2.在建表时时候加以标识:create table user(name char(20) binary)原理:	对于CHAR、VARCHAR和TEXT类型,BINARY属性可以为列分配该列字符集的 校对规则。	BINARY属性是指定列字符集的二元 校对规则的简写。	排序和比较基于数值字符值。因此也就自然区分了大小写。

6>. mybatis中不能使用>或<等

在这里插入图片描述
7>. 数据库中关于date类型查询数据库问题

在这里插入图片描述

8>. 根据前台传入的值写出后台接收方式

  • ①. Map和对象的json数据类型是 { }

  • ②. List集合的json数据类型是[ ]

在这里插入图片描述

9>. 经典sql语句

  • ①. 查询套餐的名字和数量
select  s.name,count(o.id) as value from t_order o inner join t_setmeal s on o.setmeal_id=s.id group by s.name#group by o.setmeal_id

在这里插入图片描述

  • ②. 热门套餐,查询前4条
select s.name, count(o.id) setmeal_count ,     count(o.id)/(select count(id) from t_order) proportion     from t_order o inner join t_setmeal s on s.id = o.setmeal_id     group by o.setmeal_id     order by setmeal_count desc limit 0,4

10>. lombok中的@Slf4j

  • ①. 等级由低到高:debug<info<warn<Error<Fatal;

  • ②.区别

    在这里插入图片描述

  • ③. 使用

    在这里插入图片描述

11>. 忽略test等打包方式

在这里插入图片描述

转载地址:http://ymdj.baihongyu.com/

你可能感兴趣的文章