• idea 创建springmvc项目


    新建springmvc 项目

    填入名称

    项目结构,会自动下载jar包

    配置Tomcat

    然后启动。。。

    会报错。。。。。。

    是因为相关jar没有导入

    out目录下没有lib

    将jar导入后重新启动服务器,out中已经有lib了,此时已经可以访问首页了

    修改web.xml ,使得springmvc 可以监听所有请求

    修改applicationContext.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"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           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">
    
        <!-- 注解扫描包 -->
        <context:component-scan base-package="com.ahao"/>
    
        <!-- 启用spring mvc 注解 -->
        <context:annotation-config/>
    
        <!-- 开启注解 -->
        <mvc:annotation-driven/>
    </beans>

    第一个hello

    @RestController
    public class Hello {
        @RequestMapping("/hello")
        public String hello() {
            System.out.println("hello");
            return "hello spring";
        }
    }

    前后端都可以看到输出,说明配置成功

  • 相关阅读:
    Linux文件与目录管理(一)
    Linux文件基本属性
    软工实践总结
    微软必应词典的调查与研究
    调研安卓开发环境的发展演变
    软件工程的预定目标
    学习进度第5周
    机械学习----KNN算法
    MyBatis:简介、第一个程序01(纯小白非常实用)
    解决数据库连接时区的问题
  • 原文地址:https://www.cnblogs.com/appium/p/13181520.html
Copyright © 2020-2023  润新知