第一:以前的XML的MVC ActionForm和Action 是要分开的,现在用annotation方式,是不用分开的,用不同的注解参数就可以区别开。
如:
/**
* 查看访问策略列表
*
* @param type
* o:查看总的访问策略;1:查看session访问策略
* @param model
* @return
* @since maguangze@Jun 24, 2010
*/
@RequestMapping(params = "action=list")
public String visitorPolicyList(@RequestParam("type")
int type, ModelMap model) {
if (logger.isDebugEnabled()) {
logger.debug("进入查看访问策略列表页面");
}
if (type == 0) {
if (logger.isDebugEnabled()) {
logger.debug("查看总的访问策略列表,type=" + type);
}
model.addAttribute("policy", this.visitorProxyManager
.getVisitorPolicies("policy"));
} else {
if (logger.isDebugEnabled()) {
logger.debug("查看session的访问策略列表 type=" + type);
}
model.addAttribute("policy", this.visitorProxyManager
.getVisitorPolicies("sessionPolicy"));
}
model.addAttribute("type", type);
return "console/visitorPolicyList";
}
/**
* 添加或修改访问策略
*
* @param url
* 目标URL
* @param model
* @return
* @since maguangze@Jun 24, 2010
*/
@RequestMapping(params = "action=addOrUpdate", method = RequestMethod.GET)
public String addOrUpdateVisitorPolicy(@RequestParam("url")
String url, ModelMap model) {
Map policyMap = this.visitorProxyManager.getVisitorPolicies("policy");
if (!"".equals(url)) {
if (logger.isDebugEnabled()) {
logger.debug("修改访问策略");
}
model.addAttribute("policy", policyMap.get(url));
} else {
if (logger.isDebugEnabled()) {
logger.debug("新增访问策略");
}
model.addAttribute("policy", new VisitorPolicy());
}
return "console/visitorPolicyForm";
}
/**
* 保存访问策略
*
* @param policy
* @return
* @since maguangze@Jun 24, 2010
*/
@RequestMapping(method = RequestMethod.POST)
public String saveVisitorPolicy(@ModelAttribute("policy")
VisitorPolicy policy) {
if (logger.isDebugEnabled()) {
logger.debug("保存访问策略");
}
this.visitorProxyManager.addConfigPolicies(policy.getUrl().trim(),
policy.getAllowNum(), policy.getAllowIp().trim());
return "console/operateSuccess";
}
以上实现了可以查看列表,可以增加,修改策略。
容易出错点:
一:@RequestParam("url")String url 的使用,jsp页面的URL中必须带有url参数,否则报错
二:在新建对象的时候.model.addAttribute("policy", new VisitorPolicy());
new VisitorPolicy():这里必须是new 一个新对象,否则,JSP页面会报错
第三:在新建或者修改页面form标签要有<form:form modelAttribute="policy">modeAttribute属性。
在查看列表页面也要添加<form:form modelAttribute="policy">modeAttribute,否则没有数据
分享到:
相关推荐
八、spring mvc 请求如何映射到具体的Action中的方法? 九、spring mvc 中的拦截器: 十、spring mvc 如何使用拦截器? 十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? ...
这里提供了Spring3 MVC中较为常见的使用方法,主要是利用Spring3官方文档建议使用的Annotation进行开发的一般步骤,包含了常见的集中Annotation的使用方法。
Spring4 MVC Hibernate4集成,使用Annotation,封装dao层和service层。 环境: spring 4.0.3.RELEASE hibernate 4.3.5.Final mysql 5.1.29
八、spring mvc 请求如何映射到具体的Action中的方法? 九、spring mvc 中的拦截器: 十、spring mvc 如何使用拦截器? 十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? ...
Spring MVC internationalization annotation example 这个是annotation 方式的国际化 访问http://localhost:8080/login.htm
Table of Contents Introduction Chapter 1: The Spring Framework Chapter 2: Model 2 and the MVC Pattern Chapter 3: Introduction to Spring MVC Chapter 4: Annotation-Based Controllers Chapter 5: Data ...
八、spring mvc 请求如何映射到具体的Action中的方法? 九、spring mvc 中的拦截器: 十、spring mvc 如何使用拦截器? 十一、spring mvc 如何实现全局的异常处理? 十二、spring mvc 如何把全局异常记录到日志中? ...
基于注解的Spring MVC,环境搭建,示例代码
博文链接:https://pesome.iteye.com/blog/236273
Spring MVC 整合Hibernate的一个小小的用例,适合初学Spring MVC 的学者。
弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,...
spring mvc annotation interceptor
一个简单的spring mvc登录案例,采用的是annotation方式。
Ajax With Spring 3. Eclipse 工程,包含Web所需要的 所有jar包。 1> ajax 请求。 2> spring 3注解使用 3> mvc:annotation
web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: ...
Spring mvc Aop+annotation实现系统日志记录功能实现的jar包asm-3.3.jar ,aspectjrt.jar , aspectjweaver.jar , cglib-nodep-2.1_3.jar , spring-aop.jar
NULL 博文链接:https://starscream.iteye.com/blog/1066712
NULL 博文链接:https://yihuawuye1.iteye.com/blog/2105063
With the power of annotation-based configuration, Spring MVC makes web application development easy for developers. This book is a great companion for beginners who want to learn Spring MVC. With ...
在spring3.0mvc中最大的特点就是采用了rest,它利用annotation来完全替代配置文件,直接用注释将请求映射到具体的model进行处理,然后返回结果给jsp页面,操作很简单。