使用注解开发 | 学习笔记

简介: 快速学习使用注解开发。

开发者学堂课程【SpringMVC 框架入门:使用注解开发】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/22/detail/452


使用注解开发

 

内容介绍:

1.   导入jar

2.   Web.xml

3.   Controller

4.   Spring mvc的配置

 

l  导入jar

commons-logging-1.1.1.jar

spring-aop-4.1.6.RELEASE.jar

spring-beans-4.1.6.RELEASE.jar

spring-context-4.1.6.RELEASE.jar

spring-context-support-4.1.6.RELEASE.jar spring-core-4.1.6.RELEASE.jar

spring-expression-4.1.6.RELEASE.jar          

spring-web-4.1.6.RELEASE.jar

spring-webmvc-4.1.6.RELEASE.jar

 

l  Web.xml

<servlet>

<servlet-name>springmvc</servlet-name>

 

<servlet-class>org.springframework.web.servlet.Dispatcher Servlet</servlet-class>

 

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:mvc.xml</param-value>

</init-param>

 

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

注意:红色配置指明mvc的配置文件位置(src/mvc.xml)

 

l  Controller

@Controller

public class HelloController {

@RequestMapping("/hello")

public ModelAndView hello(HttpServletRequest reg, HttpServletResponse resp){

ModelAndView mv= new ModelAndView();

//封装要显示到视图中的数据

mv. addObject ("msg"," hello annotation");

//视图名

my. setViewName ("hello");// web-inf/ isp/ hello. isp

return mv;

}

}

 

l  Spring mvc的配置

<?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:p="http://ww.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd">

<!--配置渲染器 视图解析器-->

<bean id="jspViewResolver"

class="org.springframework.web.servlet.view.InternaLResource ViewResolver">

<property name="viewClass"

value="org.springframework.web.servlet.view.Jstlview"/>

<!--结果视图的前缀-->

<property name="prefix" value="/WEB-INF/isp/"/>

<!--结果视图的后缀-->

<property name="suffix" value=".jsp"/>

</bean>

<一扫描该包下的注解-->

< context: component- scan

base-package="cn.sxt.controller"/>

</ beans >

相关文章
|
5月前
|
Java 关系型数据库 数据库连接
【JavaEE进阶】 MyBatis使用注解实现增删改查
【JavaEE进阶】 MyBatis使用注解实现增删改查
|
5月前
|
Java 数据库连接 数据库
JAVAEE框架技术之10-myBatis注解式开发
JAVAEE框架技术之10-myBatis注解式开发
72 0
JAVAEE框架技术之10-myBatis注解式开发
|
XML 设计模式 Java
Spring进阶-AOP注解开发
Spring进阶-AOP注解开发
145 0
|
XML Java 数据库连接
《springboot实战》 第十章 整合Mybatis(注解)
《springboot实战》 第十章 整合Mybatis(注解)
63 0
|
XML 前端开发 Java
使用注解开发 | 学习笔记
快速学习使用注解开发。
|
SQL Java 关系型数据库
SpringBoot 整合 Mybatis(注解方式)|学习笔记
快速学习 SpringBoot 整合 Mybatis(注解方式)
421 0
SpringBoot 整合 Mybatis(注解方式)|学习笔记
|
SQL XML Java
mybatis @SelectProvider 注解, 打赌你没有用过
mybatis @SelectProvider 注解, 打赌你没有用过
461 0
mybatis @SelectProvider 注解, 打赌你没有用过
|
Java 数据库连接 开发者
使用注解开发| 学习笔记
快速学习使用注解开发。
|
Java Spring 容器
SpringMVC注解开发入门案例
SpringMVC注解开发入门案例
SpringMVC注解开发入门案例
|
Java 数据库连接 mybatis
MyBatis(十一) 注解详解
MyBatis常用注解详解介绍