Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux集群 > Architecture > » 正文

Spring3.0MVC和Hibernate基于annotation注解的整合(2)

来源: 未知 分享至:



usercontroller
Java代码
package org.xlaohe1.web;  
  
import java.util.List;  
  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
  
import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.stereotype.Controller;  
import org.springframework.ui.ModelMap;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.servlet.ModelAndView;  
import org.xlaohe1.model.User;  
import org.xlaohe1.service.IUserService;  
  
@Controller  
public class UserController {  
    @Autowired  
    IUserService userService;  
  
    public UserController() {  
    }  
  
    @RequestMapping(value = \"/show\")  
    public ModelAndView myMethod(HttpServletRequest request,  
            HttpServletResponse response, ModelMap modelMap) throws Exception {  
        List<User> ulst = userService.findAllUsers();  
        modelMap.put(\"users\", ulst);  
        return new ModelAndView(\"showUser\", modelMap);  
  
    }  
      
    @RequestMapping(value = \"/t\")  
    public ModelAndView t() {  
        return new ModelAndView(\"t\");  
    }  
  
} 




<context:annotation-config />这个配置告诉springmvc,springmvc相关的bean中使用注解来进行表示

<context:component-scan base-package=\"com.jlh2.study.web.module\"/>这个配置告诉springmvc对com.jlh2.study.web.module进行扫描,并创建其中的javaBe an并注入到spring容器中。

<bean class=\"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping\" /> 启动springmvc的注解映射功能

<bean class=\"org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping\" /> 自动将访问url映射到同名的Controller上面

<bean class=\"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter\"/> 启动springmvc的注解功能

Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史