qq_人不犯er枉少年_03735473
2018-04-04 17:35
package liang.test.aspect;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Aspect
@Component
public aspect HttpCliet {
private final static Logger logger= LoggerFactory.getLogger(HttpCliet.class);
@Pointcut("execution(public * liang.test.controller.GirlController.*(..))")
public void log(){
}
@Before("log()")
public void logb(){
logger.info("befor");
}
@After("log()")
public void log1(){
logger.info("After");
}
}
package liang.test.controller;
import liang.test.properties.Girl;
import liang.test.repository.GirlsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@RequestMapping("/girl")
public class GirlController {
@Autowired
private Girl girl;
@Autowired
private GirlsRepository girlsRepository;
@PostMapping("/insert")
public Girl insert(@Valid Girl girl, BindingResult bindingResult){
if (bindingResult.hasErrors()){
System.out.println(bindingResult.getFieldError().getDefaultMessage());
return null;
}
girl.setAge(girl.getAge());
girl.setName(girl.getName());
return girlsRepository.save(girl);
}
}
@Aspect @Component public aspect HttpCliet {
问题在这里: 类的定义
解决: public class HttpClient{...}
望采纳
com.example.demo.aspectorg.slf4j.Loggerorg.slf4j.LoggerFactoryGirlAspect { Logger =LoggerFactory.(GirlAspect.)() (){ } (= ) (){ .info()} (= ) (){ .info()} }
Spring Boot进阶之Web进阶
104039 学习 · 393 问题
相似问题