前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >简单的Spring MVC 程序 原

简单的Spring MVC 程序 原

作者头像
南郭先生
发布2018-08-14 15:29:25
3900
发布2018-08-14 15:29:25
举报
文章被收录于专栏:Google Dart
代码语言:javascript
复制
package group.esperanto.action;

import java.io.IOException;

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

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
// 定义该Action的映射路径
// 该路径绝对不能重复
@RequestMapping("/pages/emp/*")
public class EmpAction {	
	private	Logger log = Logger.getLogger(EmpAction.class);
	
	@RequestMapping("echo")  //映射方法名
   public void echo(String msg){
	   Logger.getLogger(EmpAction.class).info(msg);
   }
	@RequestMapping("list")
   public ModelAndView list(    // 设置参数亲求名和 默认值
			   @RequestParam(value="cp",defaultValue="1") int currentPage,
			   @RequestParam(value="lc",defaultValue="10") int lineSize,
			   @RequestParam(value="col",defaultValue="title") String column,
			   @RequestParam(value="kw",defaultValue="") String keyWord){
		     log.info("--- currentPage : "+currentPage+" ---");
		     log.info("--- lineSize : "+lineSize+" ---");
		     log.info("--- column : "+column+" ---");
		     log.info("--- keyWord : "+keyWord+" ---");		
		     return null;
	 }
	@RequestMapping("get")    // 接收Servlet内置对象 request,response
   public ModelAndView get(int id,HttpServletRequest request,HttpServletResponse response){
	   HttpSession session = request.getSession();
	   ServletContext application = request.getServletContext();
	   log.info("--- contextPath :" + request.getServletPath());
	   log.info("--- sessionId :" + session.getId());
	   log.info("--- realPath :" + application.getRealPath("/"));
	   try {
		    response.getWriter().println("Hello Spring MVC");
	    } catch (IOException e) {
		    e.printStackTrace();
	    }
	   return null;
   }	
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017/08/13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档