当前位置:   article > 正文

利用 gradle 创建springmvc 工程_gradle搭建soringmvc

gradle搭建soringmvc

File-New-Project

输入项目名,唯一识别

finish,生成项目

手动创建必要文件

springmvc.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:mvc="http://www.springframework.org/schema/mvc"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/mvc
  14. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  15. ">
  16. <!--组件扫描-->
  17. <context:component-scan base-package="com.ln.controller"/>
  18. <!--<context-->
  19. <!--处理器映射,处理解析器-->
  20. <mvc:annotation-driven/>
  21. <!--试图解析器-->
  22. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  23. <property name="prefix" value="/WEB-INF/psges/"/>
  24. <property name="suffix" value=".jsp"/>
  25. </bean>
  26. <!--释放静态资源-->
  27. <mvc:default-servlet-handler/>
  28. <!--<bean id="accountDao" class="com.ln.dao.impl.AccountDaoImpl"/>-->
  29. </beans>

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  5. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  6. id="WebApp_ID" version="3.0">
  7. <!--配置springmvc核心servlet-->
  8. <servlet>
  9. <servlet-name>springmvc</servlet-name>
  10. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  11. <init-param>
  12. <param-name>contextConfigLocation</param-name>
  13. <param-value>classpath:springmvc.xml</param-value>
  14. </init-param>
  15. </servlet>
  16. <servlet-mapping>
  17. <servlet-name>springmvc</servlet-name>
  18. <url-pattern>/</url-pattern>
  19. </servlet-mapping>
  20. </web-app>

index.jsp

  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: Administrator
  4. Date: 2018/9/20
  5. Time: 9:22
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <html>
  10. <head>
  11. <title>Title</title>
  12. </head>
  13. <body>
  14. <jsp:forward page="/hello/list"/>
  15. <%--qishie--%>
  16. </body>
  17. </html>

list.jsp

  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: Administrator
  4. Date: 2018/9/20
  5. Time: 9:21
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <html>
  10. <head>
  11. <title>Title</title>
  12. </head>
  13. <body>
  14. 成功跳转到list页面
  15. </body>
  16. </html>

helloController.java

  1. package com.ln.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.ResponseBody;
  5. @Controller
  6. @RequestMapping("/hello")
  7. public class helloController {
  8. @RequestMapping("/list")
  9. // @ResponseBody
  10. public String toList(){
  11. return "list";
  12. }
  13. }

添加tomcat

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/305880?site
推荐阅读
相关标签
  

闽ICP备14008679号