复习第二点-2.基于注解的helloworld
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!--配置前端控制器-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
springmvc.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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"
xmlns:mvc="http://www.springframework.org/schema/mvc"
>
<!--
这个标签仅是@Controller @RequestMapping 基本功能的注解可以使用
-->
<context:component-scan base-package="controller"/>
<!--
增加了这个标签后,提供了扩展功能
它的处理类 AnnotationDrivenBeanDefinitionParser 会注册很多基于注解开发时所用到的
Bean 对 象 到 容 器 中 。 其 中 包 含 RequestMappingHandlerMapping 、
RequestMappingHandlerAdapter 与 ExceptionHandlerExceptionResolver 三个 bean。
-->
<mvc:annotation-driven/>
</beans>
AnnoController.java
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
//http://localhost:8888/springmvc_war_exploded/suibian/ann
// @RequestMapping 用于将一个 URI 绑定到类上或类的方法中。
@RequestMapping("/suibian")
public class AnnoController {
//http://localhost:8888/springmvc_war_exploded/ann
@RequestMapping("/ann")
public ModelAndView annDemo(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/index.jsp");
modelAndView.addObject("msg","Hello Oldlu");
return modelAndView;
}
}
展示效果

复习第二点-2.基于注解的helloworld的更多相关文章
- (spring-第4回【IoC基础篇】)spring基于注解的配置
基于XML的bean属性配置:bean的定义信息与bean的实现类是分离的. 基于注解的配置:bean的定义信息是通过在bean实现类上标注注解实现. 也就是说,加了注解,相当于在XML中配置了,一样 ...
- 基于注解的Spring AOP的配置和使用
摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...
- SpringMVC4 + Spring + MyBatis3 基于注解的最简配置
本文使用最新版本(4.1.5)的springmvc+spring+mybatis,采用最间的配置方式来进行搭建. 1. web.xml 我们知道springmvc是基于Servlet: Dispatc ...
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- 基于注解风格的Spring-MVC的拦截器
基于注解风格的Spring-MVC的拦截器 Spring-MVC如何使用拦截器,官方文档只给出了非注解风格的例子.那么基于注解风格如何使用拦截器呢? 基于注解基本上有2个可使用的定义类,分别是Defa ...
- Spring MVC中基于注解的 Controller
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...
- SpringMVC + ehcache( ehcache-spring-annotations)基于注解的服务器端数据缓存
背景 声明,如果你不关心java缓存解决方案的全貌,只是急着解决问题,请略过背景部分. 在互联网应用中,由于并发量比传统的企业级应用会高出很多,所以处理大并发的问题就显得尤为重要.在硬件资源一定的情况 ...
- SpringMVC详解(三)------基于注解的入门实例
前两篇博客我们讲解了基于XML 的入门实例,以及SpringMVC运行的详细流程.但是我们发现基于 XML 的配置还是比较麻烦的,而且,每个 Handler 类只能有一个方法,在实际开发中肯定是不可能 ...
- spring基于注解进行注入(个人记录)
spring的Bean基于注解进行配置,再结合自动装配属性,也就DI,其实说白了就相当于初始化的时候给对象赋初值. 配置文件的过程有些麻烦,记录一下. 基于注解进行配置: 1.在application ...
- 转载 SpringMVC详解(三)------基于注解的入门实例
目录 1.在 web.xml 文件中配置前端处理器 2.在 springmvc.xml 文件中配置处理器映射器,处理器适配器,视图解析器 3.编写 Handler 4.编写 视图 index.jsp ...
随机推荐
- 迁移学习(JDDA) 《Joint domain alignment and discriminative feature learning for unsupervised deep domain adaptation》
论文信息 论文标题:Joint domain alignment and discriminative feature learning for unsupervised deep domain ad ...
- NG-ZORRO + Angular11增加自定义全局样式,不影响其他页面全局样式,仅作用于当前页面
实现只需要两步 ts import { ViewEncapsulation } from '@angular/core';// 关键代码 @Component({ selector: 'app-tes ...
- AR Engine毫秒级平面检测,带来更准确的呈现效果
近年来,AR版块成为时下大热,这是一种将现实环境中不存在的虚拟物体融合到真实环境里的技术,用户借助显示设备可以拥有真实的感官体验.AR的应用场景十分广泛,涉及娱乐.社交.广告.购物.教育等领域:AR可 ...
- 报错One record is expected, but the query result is multiple records
总结:出现这种情况,显而易见,就是查询的数据在数据库中不止一条,而我调用的selectOne方法,返回值是一个User对象,导致报错 点击查看错误代码 LambdaQueryWrapper<Us ...
- drf-day3——drf整体流程、APIView执行流程及源码分析、Request对象源码分析、序列化器介绍和使用、反序列化的使用、反序列化的校验
目录 一.drf 整体内容 二.APIView执行流程--源码分析(难,了解) 2.1 基于APIView+JsonResponse编写接口 2.2 基于APIView+Response 写接口 2. ...
- Rust Rand生成随机数
# in project file cargo add rand extern crate rand; use rand::Rng; fn main() { let mut rng = rand::t ...
- spring-in-action_day01
前景说明:SpringInAction主要致力于SpringBoot为基础的讲解,尽可能多的使用SpringBoot,可以减少显行的配置,如xml配置,可以更加的专注于功能的实现. 第一章:主要讲了如 ...
- 远程控制 todesk
最近发现的一个好用的远程连接软件 便是近些年推出来的 todesk 虽然qq的远程 和 向日葵的 远程连接也都可以达到我要实现的效果 但是体验起来的话 我个人还是觉得 todesk更好用一些 下载地址 ...
- Dao包 对数据库的操作
//添加 public static int add(Bean1 bean){ String sql = "insert into classtable(classname,teacher, ...
- 交叉熵损失CrossEntropyLoss
在各种深度学习框架中,我们最常用的损失函数就是交叉熵,熵是用来描述一个系统的混乱程度,通过交叉熵我们就能够确定预测数据与真实数据的相近程度.交叉熵越小,表示数据越接近真实样本. 1 分类任务的损失计算 ...