public class PerformancethreshodInterceptor implements MethodInterceptor{ private final long thresholdInMillis ; … public Object invoke(MehtodInvocation mi){ long t = System.currentTimeMillis(); Object o = mi.proceed(); t = System.currenttimeMillis – t ; if(t > thresholdInMillis ){ …… . } return o ; } }
class xxx extends AbstractController{ ModelAndView hanleRequest(){ Set courses = courseService.getAllCourses(); return new ModelAndView(“courseList”,”courses”,courses); } } 参数一:控制器输出表单视图组件的逻辑名。 参数二:传递给视图组件的数据对象名。 参数三:传递给视图组件的数据对象。 ----------------------------------------- <bean id=“coursesCtroller” class=“xxx.CourseController”> <property name=“courseService”> <ref bean=“” /> </property> </bean>
第八章 建立 web 层
8.3 用控制器处理请求
8.3.2 处理命令
对于 web 请求需要若干个参数来帮助确定返回结果。 public calss xxxController extends AbstractCommandController(){ public xxxController(){ setCommandClass(xxxCommand.class); } public ModelAndView handle(request,response,command,errors){ xxxComand xxxcommand = (XxxCommand)command ; return new ModelAndView(“”,””,); } } 标准 javabean: class XxxCommand(){ int I ; int name ; … }
第八章 建立 web 层
8.3 用控制器处理请求
8.3.2 处理表单提交
public calss xxxController extends SimpleFormController (){ public xxxController(){ setCommandClass(xxxCommand.class); } public void doSubmitAction(){ … } } doSubmitAction() 方法没有返回任何东西,用户将看到什么页面也不是很清楚, Simple FormController 类被设计成尽量将视图详细信息放在控制器代码之外。不是将 ModelAnd View 对象硬编码进来,而是像下面这样在上下文配置文件中配置控制器。
0 comments
Post a comment