日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

springMVC——注解配置方式实现Helloworld

發布時間:2024/2/28 c/c++ 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springMVC——注解配置方式实现Helloworld 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基于注解helloworld

只需根據基于xml的項目文件進行改變。

改變1: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:p="http://www.springframework.org/schema/p"
???????xmlns:aop="http://www.springframework.org/schema/aop"
???????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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
????<!--啟用classpath掃描-->
????<context:component-scan base-package="com.henu.controller"></context:component-scan>
????<!--映射處理器 -->
????<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
????<!--處理器適配器 -->
????<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>
????<!--視圖解析器-->
????<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
????????<!--指定跳轉位置?/success.jsp-->
????????<property name="prefix" value="/"/>
????????<property name="suffix" value=".jsp"/>
????</bean>
</beans>

改變2:UserController

package com.henu.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
?* @author George
?* @description
?**/
@Controller
public class UserController{

????/**
?????* 處理器方法
?????*
?????* @return
?????* @throws Exception
?????*/
????@RequestMapping("/login")
????public ModelAndView login() throws Exception {

????????//創建模型視圖對象
????????ModelAndView mav = new ModelAndView();
????????//把數據綁定到模型對象
????????mav.addObject("name","admin");
????????//設置跳轉的試圖對象
????????mav.setViewName("success");
????????return mav;
????}
}

然后啟動tomcat

不過路徑如果你是使用插件啟動的。需要看控制臺打出的路徑。

插件啟動位置:

?

控制臺打出的路徑:

?

因此:http://localhost:9091/mvc/login

?

總結

以上是生活随笔為你收集整理的springMVC——注解配置方式实现Helloworld的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。