HttpMessageConverter<T>
是 Spring3.0新添加的一个接 口,负责将请求信息转换为一个对象(类型为 T),将对象( 类型为 T)输出为响应信息 @RequestMapping("/testResponseEntity")
public ResponseEntity<byte[]> testResponseEntity(HttpSession session) throws IOException{
byte [] body = null;
ServletContext servletContext = session.getServletContext();
InputStream in = servletContext.getResourceAsStream("/files/abc.txt");
body = new byte[in.available()];
in.read(body);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=abc.txt");
HttpStatus statusCode = HttpStatus.OK;
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(body, headers, statusCode);
return response;
}
常用注解:
aop的全部通知顺序是什么?spring boot或者spring boot2对aop的执行顺序影响是什么?
新建一个切面
@Aspect
@Component
public class MyAspect
{
@Before("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void beforeNotify()
{
System.out.println("******** @Before我是前置通知MyAspect");
}
@After("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterNotify()
{
System.out.println("******** @After我是后置通知");
}
@AfterReturning("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterReturningNotify()
{
System.out.println("********@AfterReturning我是返回后通知");
}
@AfterThrowing("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterThrowingNotify()
{
System.out.println("********@AfterThrowing我是异常通知");
}
@Around("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable
{
Object retValue = null;
System.out.println("我是环绕通知之前AAA");
retValue = proceedingJoinPoint.proceed();
System.out.println("我是环绕通知之后BBB");
return retValue;
}
}
spring4+springboot1.5.9
@SpringBootTest
@RunWith(SpringRunner.class) //1.5.9
public class T1
{
@Autowired
private CalcService service;
System.out.println("spring版本:"+ SpringVersion.getVersion()+"\t"+"SpringBoot版本:"+ SpringBootVersion.getVersion());
System.out.println();
calcService.div(10,2);
}