3分钟搭建ssm配置

创建maven普通项目

导入maven

<packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.6.RELEASE</version>
        </dependency>
    </dependencies>

创建目录
在这里插入图片描述
在目录上按一下f6
ok,然后改变目录为域名那里
在这里插入图片描述

配置webapp

在项目上按f4,点击web
在这里插入图片描述
在这里插入图片描述
点击这里
在这里插入图片描述
修改目录,点击确定
在这里插入图片描述

配置xml

在这里插入图片描述
(1)创建applicationContext.xml配置spring

<context:component-scan base-package="top.chenyp" use-default-filters="true">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

(2)创建springmvc.xml配置springmvc

<context:component-scan base-package="top.chenyp" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    
    <mvc:annotation-driven/>

(3)配置web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <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>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

测试配置

编写controller

@Controller
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping("/hello")
    public @ResponseBody
     String testHello(){
        return testService.testHello();
    }
}

编写service

@Service
public class TestService {

    public String testHello(){
        return "hello";
    }
}

配置tomcat(略)

运行

在这里插入图片描述

发布了33 篇原创文章 · 获赞 19 · 访问量 3551

猜你喜欢

转载自blog.csdn.net/qq_42794826/article/details/103532367