1.springbootapplication注解,组成?
解释一下,@SpringBootApplication其实就是以下三个注解的总和
@Configuration: 用于定义一个配置类
@EnableAutoConfiguration :Spring Boot会自动根据你jar包的依赖来自动配置项目。
@ComponentScan: 告诉Spring 哪个packages 的用注解标识的类 会被spring自动扫描并且装入bean容器。
2.autowired和resource注解的区别
作为controller层的service注入,
@Autowired
@Autowired为Spring提供的注解,需要导入包org.springframework.beans.factory.annotation.Autowired。
@Autowired采取的策略为按照类型注入。
public class UserService { @Autowired private UserDao userDao; }
如上代码所示,这样装配回去spring容器中找到类型为UserDao的类,然后将其注入进来。这样会产生一个问题,当一个类型有多个bean值的时候,会造成无法选择具体注入哪一个的情况,这个时候我们需要配合着@Qualifier使用。
@Qualifier告诉spring具体去装配哪个对象。
public class UserService { @Autowired @Qualifier(name="userDao1") private UserDao userDao; }
这个时候我们就可以通过类型和名称定位到我们想注入的对象。
@Resource
@Resource注解由J2EE提供,需要导入包javax.annotation.Resource。
@Resource默认按照ByName自动注入。
public class UserService { @Resource private UserDao userDao; @Resource(name="studentDao") private StudentDao studentDao; @Resource(type="TeacherDao") private TeacherDao teacherDao; @Resource(name="manDao",type="ManDao") private ManDao manDao; }
①如果同时指定了name和type,则从Spring上下文中找到唯一匹配的bean进行装配,找不到则抛出异常。
②如果指定了name,则从上下文中查找名称(id)匹配的bean进行装配,找不到则抛出异常。
③如果指定了type,则从上下文中找到类似匹配的唯一bean进行装配,找不到或是找到多个,都会抛出异常。
④如果既没有指定name,又没有指定type,则自动按照byName方式进行装配;如果没有匹配,则回退为一个原始类型进行匹配,如果匹配则自动装配。
3.spring aop ioc 的含义以及项目运用
4.注入方式
5.restcontroller和controller注解区别
开发RESTful API 时,一般都会在Controller上加上@Controller注解,但是有时候加上@RestController,当同事问为什么的时候,我也一脸懵逼,默默的看了资料,现在就说说他们的区别。
@RestController注解等价于@ResponseBody + @Controller。@RestController和@Controller的共同点是都用来表示Spring某个类是否可以接收HTTP请求,二者区别: @RestController无法返回指定页面,而@Controller可以;前者可以直接返回数据,后者需要@ResponseBody辅助。下面详细分析。
① 是否可以返回页面
答:@RestController无法返回指定页面,而@Controller可以。
解析:对于Controller, 如果只是使用@RestController注解,则其方法无法返回指定页面,此时配置的视图解析器 InternalResourceViewResolver不起作用,返回的内容就是 return 里的内容。 如果需要返回到指定页面,则需要用 @Controller配合视图解析器InternalResourceViewResolver才行。
② 返回内容
如果需要返回JSON,XML或自定义mediaType内容到页面,@RestController自己就可以搞定,这个注解对于返回数据比较方便,因为它会自动将对象实体转换为JSON格式。而@Controller需要在对应的方法加上@ResponseBody注解。
6.resultMap 和resultype 的区别
基本映射 :(resultType)使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功。(数据库,实体,查询字段,,这些全部都得一一对应)
高级映射 :(resultMap) 如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间作一个映射关系。(高级映射,字段名称可以不一致,通过映射来实现)
7.mysql 取出最大的一个值,去除第二个最大值
select top 1 id,name,age from 表 order by age desc
按照年龄倒序排序,然后取第一条。
考虑可能有多人年龄相同,如果都需取出,可以这样写:
select id,name,age from 表 where age=(select max(age) from 表)
select max(age) as '第二大年龄' from Students where age<(select max(age) from Students ;
8 springcloud 微服务的组件有哪些,分别是做什么的?
- 服务发现——Netflix Eureka
- 客服端负载均衡——Netflix Ribbon
- 断路器——Netflix Hystrix
- 服务网关——Netflix Zuul
- 分布式配置——Spring Cloud Config
资料参考:https://www.cnblogs.com/lingboweifu/p/11807465.html
9.redis的数据类型常见的有哪些?分别是怎么应用的
-
string
-
hash
-
list
-
set
-
sorted set
资料参考:https://blog.csdn.net/GV7lZB0y87u7C/article/details/93986796