博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java综合(二)springmvc与spring整合
阅读量:3530 次
发布时间:2019-05-20

本文共 2149 字,大约阅读时间需要 7 分钟。

学习整合struts2与spring后,再学习springmvc与spring整合就比较简单了.

1.web.xml配置

springMVC
com.skymr.smvcs.EncodingDispatcherServlet
contextConfigLocation
classpath*:/config/spring_annotation-servlet.xml
encoding
UTF-8
1
springMVC
/
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
WEB-INF/classes/config/applicationContext.xml
spring配置文件与springmvc配置文件都放到src/config/下
2.springmvc配置文件

3.Service ,serviceBean与controller类 

package com.skymr.smvcs.hello.service;public interface HelloWorldService {	public void say();}

package com.skymr.smvcs.hello.service.impl;import com.skymr.smvcs.hello.service.HelloWorldService;public class HelloWorldServiceBean implements HelloWorldService{	public void say() {		System.out.println("springmvc-spring第一个实例:Hello World!!!");	}}

package com.skymr.smvcs.hello.ctrl;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.skymr.smvcs.hello.service.HelloWorldService;@Controller@RequestMapping("/hello")public class HelloWorldController{	//spring注解注入	@Resource	private HelloWorldService helloWorldService;		@RequestMapping("/helloWorld")	public String toHelloWorld(){		System.out.println("执行HelloWorldController toHelloWorld方法");		helloWorldService.say();		return "index";	}	}
4.spring配置文件

5部署测试

http://localhost:8080/springmvc_spring/hello/helloWorld显示index.jsp页面成功.

后台打印

执行HelloWorldController toHelloWorld方法

springmvc-spring第一个实例:Hello World!!!

转载地址:http://hjihj.baihongyu.com/

你可能感兴趣的文章
BFC(Block Formatting Context)
查看>>
什么是作用域,什么是闭包,什么是作用域链
查看>>
惰性求值,面向对象
查看>>
lodash源码分析之baseSlice()函数
查看>>
数据结构之列表
查看>>
发布/订阅模式 vs 观察者模式
查看>>
es5中的arguments对象
查看>>
git本地仓库和远程仓库关联,分支重命名
查看>>
js对象的深拷贝,你真的觉得很简单吗?
查看>>
你真的了解map方法吗?手动实现数组map方法。
查看>>
带你手动实现call方法,让你收获满满
查看>>
前端知识体系
查看>>
查找入职员工时间排名倒数第三的员工所有信息
查看>>
使用join查询方式找出没有分类的电影id以及名称
查看>>
Qt教程(2) : Qt元对象系统
查看>>
驱动开发误用指针错误:Unable to handle kernel NULL pointer dereference at virtual address
查看>>
Linux部署DocSystem知识/文件管理系统
查看>>
Centos7开机自启动脚本无法使用备用方案
查看>>
jvm虚拟机内存详解
查看>>
线程的创建方式
查看>>