Mybatis:
@Insert: 编写新增SQL语句
@Update: 编写修改SQL语句
@Delete: 编写删除SQL语句
@Select: 编写查询SQL语句
@Param : 参数名称 与 SQL语句中的#{key}的对应关系
@Select("select * from tb_user where username = #{ab} and password= #{ba}")
public User findByNameAndPwd(@Param("ab")String a,@Param("ba")String b)
@ResultMap:指定Mapper映射文件的 <resultMap>
@Results: 等同于<resultMap>标签,进行字段映射
Spring:
<bean id="" class="" scope="" init-method="" destroy-method="">
@Component: 写在类上,将类声明成Spring的bean对象
@Controller:写在类上,表现层的类
@Service:写在类上,业务层的类
@Repository:写在类上,持久层的类
@Configuration:写在类上,将当前类声明成一个配置类
@Bean:写在方法上,将方法的返回值制作成spring的bean对象,用来管理第三方bean
@ComponentScan:指定Spring扫描的包路径,会将指定的包及其子包中的所有类上的注解进行扫描
<bean ...>
<property name="" value=""|ref=""/>
</bean>
@Value: 注入的是简单数据类型
@Autowired: 注入的是引用数据类型,默认是按照类型注入
@Qualifier:指定名称,配合@Autowired使用,实现按照名称注入
<context:property-placeholder location=""/>
@PropertySource("classpath:jdbc.properties")
@Import:在当前的配置类中引入其他的配置类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
@EnableTransactionManagement:开启Spring的声明式事务管理注解支持
@Transactional:事务注解,写在类上、类的方法上、接口上、接口的方法上
SpringMVC:
@RequestMapping:请求映射,可以写在类上和方法上,如果类上和方法上都有,前端请求路径=类+方法
@GetMapping :请求映射,要求发送的是GET 查询
@PostMapping:请求映射,要求发送的是POST 新增
@PutMapping:请求映射,要求发送的是PUT 修改
@DeleteMapping:请求映射,要求发送的是DELETE 删除
@RequestParam: 请求url地址上的参数名和方法的参数名的对应关系
http://localhost/find?username=tom&age=18
@RequestMapping("/find")
public List<User> find(@RequestParam("username")String name,String age){
}
@PathVariable
http://localhost/find/tom/18
@RequestMapping("/find/{username}/{age}")
public List<User> find(@PathVariable("username") String name,@PathVariable String age){
}
@EnableWebMvc:开启SpringMVC注解驱动
@RequestBody: 将前端发送的json数据转换成java对象
@ResponseBody:如果方法的返回值是非对象,原样返回,如果返回的是对象,会将对象自动转成json进行返回
@RestController = @Controller+@ReponseBody
@ControllerAdvice(annotations = {RestController.class,Controller.class}) 写在类上,标识该类是一个全局异常处理器类
@RestControllerAdvice = @ControllerAdvice + @ResponseBody
@ExceptionHandler(IOException.class) : 写在方法上,指定该方法处理的异常类型,例句为处理IO异常
SpringBoot:
@SpringBootApplication:SpringBoot引导类上的注解
@ConfigurationProperties(prefix=""):读取springboot配置文件中的数据到指定的对象中
@SpringBootTest(classes=引导类.class):SpringBoot中写在测试类上的注解
@Mapper / @MapperScan:在Mapper类上添加或者在引导类/入口类上进行MapperScan包扫描
不常用注解
Lombok:
@Data:(@Setter...@Getter...@ToString)
@NoArgsContructor:无参构造
@AllArgsContructor:全参构造
MybatisPlus
@TableName:默认操作:将类名首字母小写作为表名 配置文件里配置table-prefix
@TableField:默认操作:会自动将属性名与列名进行匹配
@TableId:主键映射 配置文件里配置id-type: auto
@TableLogic:逻辑删除
Spring的IOC
@Scope("singleton|prototype") 作用域
@PostConstruct:初始化方法,在构造函数执行之后执行
@PreDestroy:销毁方法,在对象销毁之前执行
Spring的AOP
@EnableAspectJAutoProxy:开启Spring的AOP注解支持
@Aspect:切面,写在通知类上
@Pointcut:切入点表达式,写在方法上,@Pointcut("execution([修饰符] 返回值 包名.类名.方法名(参数))")
@Before,@After,@AfterReturning,@AfterThrowing,@Around:前置、后置、返回后、抛出异常、环绕
其他
@WebFilter(FilterName = "Xxx" )过滤器
@ServletCompentScan:该注解的作用是再Spring环境中扫描Servlet组件(Servlet,Filter,Listener)
SpringCloud
RabbitMQ:
@RabbitListener(bindings = @QueueBinding(
value = @Queue( name = "queueName", durable = "true")
exchange = @Exchange( name = "exchangeName", durable = "true")
key={ "routingKey1" , "routingKey2"}
)