我创建了HelloController
类,如下所示:
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/welcome")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring MVC Hello World");
return "hello";
}
}
然后我使用LoggingAspect
建议创建了@Before
,效果很好,我的hello.jsp
页面会在浏览器中打开http://localhost:8989/SpringApplication/welcome
时显示。
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class LoggingAspect {
@Before("execution(* com.controller.HelloController.printWelcome(..))")
public void logBefore(JoinPoint joinPoint) {
System.out.println("logBefore() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
然后,我删除了@Before
并添加了@Around
的代码,如下所示:
import java.util.Arrays;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class LoggingAspect {
@Around("execution(* com.controller.HelloController.printWelcome(..))")
public void logAround(ProceedingJoinPoint pointroceedingJoinPoint)
throws Throwable {
System.out.println("logAround() is running!");
System.out.println("hijacked method : "
+ pointroceedingJoinPoint.getSignature().getName());
System.out.println("hijacked arguments : "
+ Arrays.toString(pointroceedingJoinPoint.getArgs()));
System.out.println("Around before is running!");
pointroceedingJoinPoint.proceed();
System.out.println("Around after is running!");
System.out.println("******");
}
}
现在,在浏览器中打开http://localhost:8989/SpringApplication/welcome
时,
它告诉我:
HTTP状态404 - /SpringApplication/pages/welcome.jsp
此外,我可以在控制台上看到@Around
打印的语句如下:
logAround() is running!
hijacked method : printWelcome
hijacked arguments : [{}]
Around before is running!
Around after is running!
******
现在,我的问题是,当我返回时welcome.jsp
正在搜索hello
,hello.jsp
应该解析为UIImage
。
你能帮我解决这个问题吗?