我快崩溃了 搞个springMvc 求大神来帮帮忙 指导一下我这个新手
从配置开始吧
/src/main/webapp/WEB-INF/web.xml
/src/main/webapp/WEB-INF/mvc-config.xml
/src\main/java/resources/spring.xml
[/code]
dao
service
service.impl
/src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>spring-mvc-study</display-name>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 拦截所有请求 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
/src/main/webapp/WEB-INF/mvc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 本配置文件是工名为mvc-dispatcher的DispatcherServlet使用, 提供其相关的Spring MVC配置 -->
<!-- 启用Spring基于annotation的DI, 使用户可以在Spring MVC中使用Spring的强大功能。 激活 @Required
@Autowired,JSR 250's @PostConstruct, @PreDestroy and @Resource 等标注 -->
<context:annotation-config/>
<!-- DispatcherServlet上下文, 只管理@Controller类型的bean, 忽略其他型的bean, 如@Service -->
<context:component-scan base-package="com.imooc.mvcdemo">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 静态资源处理, css, js, imgs -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- HandlerMapping, 无需配置, Spring MVC可以默认启动。 DefaultAnnotationHandlerMapping
annotation-driven HandlerMapping -->
<!-- 扩充了注解驱动,可以将请求参数绑定到控制器参数 -->
<mvc:annotation-driven />
<!-- 配置ViewResolver。 可以用多个ViewResolver。 使用order属性排序。 InternalResourceViewResolver放在最后。 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
/src\main/java/resources/spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Uncomment and add your base-package here:
<context:component-scan
base-package="org.springframework.samples.service"/> -->
<!--启用Spring基于annotation的DI管理 -->
<context:annotation-config />
<!-- exclude-filter告诉Spring 不需要管理Controller -->
<context:component-scan base-package="com.imooc.mvcdemo">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
controller
[code=java]
package com.imooc.mvcdemo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.imooc.mvcdemo.model.HelloMvc;
import com.imooc.mvcdemo.service.HelloMvcService;
@Controller
@RequestMapping("/hello")
public class HelloController {
private static Logger log=LoggerFactory.getLogger(HelloController.class);
private HelloMvcService helloMvcService;
@Autowired
public void setHelloMvcService(HelloMvcService helloMvcService) {
this.helloMvcService = helloMvcService;
}
@RequestMapping("/mvc")
public String helloMVC(Model model){
HelloMvc helloMvc=helloMvcService.getHelloMvc();
model.addAttribute(helloMvc);
return "showMessage";
}
}
[/code]
dao
package com.imooc.mvcdemo.dao;
import org.springframework.stereotype.Repository;
@Repository
public interface HelloDao {
}
service
package com.imooc.mvcdemo.service;
import org.springframework.stereotype.Service;
import com.imooc.mvcdemo.model.HelloMvc;
public interface HelloMvcService {
HelloMvc getHelloMvc();
}
service.impl
package com.imooc.mvcdemo.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.imooc.mvcdemo.dao.HelloDao;
import com.imooc.mvcdemo.model.HelloMvc;
import com.imooc.mvcdemo.service.HelloMvcService;
public class HelloMvcServiceImpl implements HelloMvcService {
private HelloDao helloDao;
public HelloDao getHelloDao() {
return helloDao;
}
@Autowired
public void setHelloDao(HelloDao helloDao) {
this.helloDao = helloDao;
}
public HelloMvc getHelloMvc() {
// TODO Auto-generated method stub
return new HelloMvc();
}
}
...全文
相关推荐
百度Ueditor整合springMVC+hibernate完整demo
百度ueditor(jsp)1.4.3最新版,完整的整合了springMVC和hibernate源码,借鉴了他人的源码,做成了一个完整可运行的demo,需自己根据实体类建立数据库。
springmvc+spring+mybatis+redis是实现秒杀
这是慕课上老师的springmvc+spring+mybatis+redis实现秒杀的完整项目
SpringMVC+mysql框架
SpringMVC+mysql框架,每步的部署和配置信息。以及对应的demo类中css js 的标准框架
springmvc_mybatis3.01.zip_SpringMVC事务_漏洞
spring3.X集成mybatis例子包涵事务管理,非常有用的例子
DUBBO与ZOOKEEPER、SPRINGMVC整合和使用
Dubbo是一个分布式服务框架,解决了上面的所面对的问题,Dubbo的架构如图所示: 主要核心部件: Remoting: 网络通信框架,实现了 sync-over-async 和 request-response 消息机制. RPC: 一个远程过程调用的抽象,支持负载均衡、容灾和集群功能 Registry: 服务目录框架用于服务的注册和服务事件发布和订阅


Web 开发
