哪位高手给一个spring MVC的例子看看

哪位高手给一个springMVC的例子看看,不盛感激!!!!!... 哪位高手给一个spring MVC的例子看看,不盛感激!!!!! 展开
 我来答
wyd2002
推荐于2016-06-05 · TA获得超过1353个赞
知道小有建树答主
回答量:236
采纳率:100%
帮助的人:72.6万
展开全部
需要的JAR包有:
spring2.jar
cglib-nodep.jar
commons-logging.jar
log4j.jar

1,web.xml 中添加 DispatcherServlet 配置:
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring-MVC.xml</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.jwml</url-pattern>
</servlet-mapping>

2,spring-MVC.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings">
<props>
<prop key="/bulletinList.jwml">bulletinListAction</prop>
</props>
</property>
</bean>

<bean id="bulletinListAction" class="com.eoms.wap.web.controller.BulletinListAction">
<property name="pageSize"><value>3</value></property>
<property name="listJsp"><value>/bulletin/list/list.jsp</value></property>
<property name="errorJsp"><value>/error.jsp</value></property>
</bean>

</beans>

3,ACTION 的编写。

BulletinListAction.java
package com.eoms.wap.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.eoms.wap.entity.BulletinInfo;
import com.eoms.wap.factory.SpringFactory;
import com.eoms.wap.mgr.BulletinMgr;

/**
* 公告列表页Action
* @author wangyudong
*
*/
public class BulletinListAction implements Controller{

private int pageSize = 10 ;

private String listJsp = null ;

private String errorJsp = null ;

private BulletinMgr bulletinMgr = (BulletinMgr)SpringFactory.getBean("bulletinMgr");

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

int pageInt = 1 ;
String page = request.getParameter("page");

if(page!=null){
try{
pageInt=Integer.parseInt(page);
}catch(Exception ex){
pageInt=1;
}
}

int start = (pageInt-1)*pageSize;
int max = pageSize ;
List<BulletinInfo> list = bulletinMgr.findBulletinInfoListByStatus(BulletinInfo.STATUS_HAS_AUDIT, start, max);
int total = bulletinMgr.findTotalCountByStatus(BulletinInfo.STATUS_HAS_AUDIT);

if(list==null || list.size()==0){
request.setAttribute("error", "没有找到可展示公告");
return new ModelAndView(errorJsp);
}
boolean hasPrev = false;
boolean hasNext = false;

if(pageInt>1){
hasPrev = true ;
}
if( pageInt*pageSize < total ){
hasNext = true ;
}

request.setAttribute("list", list );
request.setAttribute("page", new Integer(pageInt));
request.setAttribute("total", new Integer(total));
request.setAttribute("hasPrev", new Boolean(hasPrev) );
request.setAttribute("hasNext", new Boolean(hasNext) );

return new ModelAndView(listJsp);
}

// getter and setter //
public String getListJsp() {
return listJsp;
}

public void setListJsp(String listJsp) {
this.listJsp = listJsp;
}

public String getErrorJsp() {
return errorJsp;
}

public void setErrorJsp(String errorJsp) {
this.errorJsp = errorJsp;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

}
wiwj307
2009-07-28 · 超过15用户采纳过TA的回答
知道答主
回答量:62
采纳率:0%
帮助的人:41万
展开全部
自己网上找吧,公司的项目不能拿出来的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式