没任何日志的出现
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);
}
}