栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

maven+springmvc的小例子

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

maven+springmvc的小例子

1.7

1.7

在Java Resources,src/main/java中新建com.springdemo.controller.DemoController.java

代码如下:

package com.springdemo.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

@RequestMapping("/demo")

public class DemoController {

@RequestMapping("/index")

public String index(){

System.out.println(“nihao”);

return “demo”;

}

}

在src/main/java/webapp/WEB-INF下新建web.xml配置如下:

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd”>

spring

org.springframework.web.servlet.DispatcherServlet

spring

/

以上配置,默认它会找serlet-name-servlet.xml,即我们配置的spring-servlet.xml

所以我们在WEB-INF下新建spring-servlet.xml,这就是springmvc的配置文件,当然我们也可以修改web.xml中的配置来把它改为通用的spring-mvc.xml

这里我们不改,就用spring-servlet.xml,代码如下

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:context=“http://www.springframework.org/schema/context”

xmlns:tx=“http://www.springframework.org/schema/tx” xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocat

【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】

浏览器打开:qq.cn.hn/FTf 免费领取

ion="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/tx

http://www.springframework.org/schema/tx/spring-tx.xsd

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

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

class=“org.springframework.web.servlet.view.InternalResourceViewResolver”>

视图解析器中配置了,所以我们在WEB-INF中新建view文件夹,再建demo.jsp

<%@ page language=“java” contentType=“text/html; charset=UTF-8”

pageEncoding=“UTF-8”%>

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/356895.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号