一、springmvc注解方式

  注解方式使用的更多,更加灵活。在上一篇的博客的基础上修改springmvc-servlet.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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- <bean name="/hello" class="springmvc.HelloController"></bean> -->
<!-- 要使注解生效,需要配置这几个属性,它会扫描controller中的注解 -->
<context:component-scan base-package="Controller" />
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/JSP/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

二、在controller下新建一个类

package Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; @Controller
public class UserController { @RequestMapping(value="/index")
public ModelAndView index()
{
System.out.println("index");
ModelAndView mv=new ModelAndView();
mv.setViewName("hello");
return mv; }
}

三、访问/index即可

Java 系列之spring学习--springmvc注解方式(五)的更多相关文章

  1. Java 系列之spring学习--springmvc注解参数传递(六)

    一.绑定参数注解如下 @RequestParam     绑定单个请求数据,既可以是URL中的参数,也可以是表单提交的参数或上传的文件. 它有三个属性:  value    用于设置参数名. defa ...

  2. Java 系列之spring学习--springmvc搭建(四)

    一.建立java web 项目 二.添加jar包 spring jar包下载地址http://repo.spring.io/release/org/springframework/spring/ 2. ...

  3. Spring、SpringMVC注解方式整合

    1 原理 Web容器在启动的时候,会扫描每个jar包下的META-INF/services/javax.servlet.ServletContainerInitializer文件. 加载META-IN ...

  4. Java 系列之spring学习--注解(三)

    一.注解 使用注解之前要开启自动扫描功能 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...

  5. Java 系列之spring学习--spring搭建(一)

    一.新建maven项目 二.引入spring jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...

  6. Java 系列之spring学习--依赖注入(二)

    一.依赖注入的三种方式 接口注入,set注入,构造函数注入 二.构造函数注入 2.1.测试类 package test; public class test01 { public String msg ...

  7. 跟着刚哥学习Spring框架--通过注解方式配置Bean(四)

    组件扫描:Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件. 特定组件包括: 1.@Component:基本注解,识别一个受Spring管理的组件 2.@Resposit ...

  8. springMVC注解方式+easyUI+MYSQL配置实例

    刚接触springMVC,使用的注解方式,也在学习阶段,所以把自己学习到的记下来.本文利用springMVC从数据库读取用户信息为例,分享一下. 1.准备相关架包及资源.因为使用springMVC+e ...

  9. 2.学习SpringMVC注解入门篇

    一.SpringMVC执行流程 . 二.创建项目学习SpringMVC注解 按照我之前的SpringMVC创建项目,首先创建一个项目springmvc01,配置好pom.xml,web.xml,spr ...

随机推荐

  1. android黑科技系列——微信抢红包插件原理解析和开发实现

    一.前言 自从几年前微信添加抢红包的功能,微信的电商之旅算是正式开始正式火爆起来.但是作为Android开发者来说,我们在抢红包的同时意识到了很多问题,就是手动去抢红包的速度慢了,当然这些有很多原因导 ...

  2. poj3083 Children of the Candy Corn 深搜+广搜

    这道题有深搜和广搜.深搜还有要求,靠左或靠右.下面以靠左为例,可以把简单分为上北,下南,左西,右东四个方向.向东就是横坐标i不变,纵坐标j加1(i与j其实就是下标).其他方向也可以这样确定.通过上一步 ...

  3. Centos7下git服务器及gogs部署

    1.安装git # yum install -y git 2.创建git用户及组 # groupadd git # adduser git -g git # mkdir /home/git # mkd ...

  4. 【leecode】独特的电子邮件地址

    每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...

  5. 【leecode】宝石与石头

    给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...

  6. php笔记之:文章中图片处理的使用

    array_diff($arr1,$arr2)php数组函数之一,用来计算数组的差集.正则匹配html图片标签用sinaeditor添加的图片删除操作用法之一,今天晚上在用新浪编辑器发表文章的过程中. ...

  7. Blender软件导出的obj数据格式文件内容解读

    [cube.obj] # Blender v2.78 (sub 0) OBJ File: '' # www.blender.org mtllib cube.mtl #这里是引用了一个外部材质文件cub ...

  8. tx:advice标签简介

    http://book.51cto.com/art/200909/149437.htm

  9. N - 畅通工程再续

    N - 畅通工程再续 思路:zz #include<cmath> #include<cstdio> #include<cstring> #include<io ...

  10. Quartz.Net 使用心得(一)

    最近工作内容与定时任务相关,在实际使用Quartz过程中,有两个小问题较为困扰. 一.多个Trigger如何触发一个Job. 比如上下班打卡时推送消息,上班时间为9:30,打卡提醒时间为9:20较好. ...