Creating a project 10 idea in springmvc

1, environmental constraints

win10 64-bit operating system

idea2018.1.5

jdk-8u162-windows-x64

2, software download

Baidu network disk:

Link: https: //pan.baidu.com/s/1gfnI8NqUYgYK1g0ULGIV2w

Extraction code: q9pl

3, the premise of restraint

Operating system installed jdk, and have completed the configuration

4. Create a project

(1) Open idea

(2) by the operation shown in FIG enter the following page:

(3) Do not click "Next", press the view of the operation:

(3) by the operation shown in FIG enter the following page:

(4) Press the operation shown in FIG, enter the following interface, then clicks "Finish", download jar package, waiting to enter the following interface:

(5) As shown in FIG. Press, click "New Window", wait for a while, enter the following interface:

5, modify the code

(1) Create a folder in the src springmvc.xml, the specific operation as shown below:

(2) create a folder in the src package, this package was added in springmvc.xml scanning, the specific operation as shown below:

springmvx.xml specific configuration is as follows:

<?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"

      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">

     <context:component-scan base-package="net.wanho.controller"></context:component-scan>

</beans>

(3) create a package in which UserController.java class, as follows:

package net.wanho.controller;

import org.springframework.stereotype.Controller;

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

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

@Controller

public class UserController {

@RequestMapping("/testresp")

@ResponseBody

public String testResp()

  {

    return "hello wanhe";

  }

}

(4) modify web.xml [Note: This document any original servlet and servlet-mapping tags can be deleted], the final configuration is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

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

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

        version="4.0">

<servlet>

    <servlet-name>dispatcher</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>

      <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

    <servlet-name>dispatcher</servlet-name>

    <url-pattern>/</url-pattern>

</servlet-mapping>

</web-app>

[Note]: web / WEB-INF / under applicationContext.xml and dispatcher-servlet.xml is generated automatically delete files.

(5) to move lib folder web / WEB-INF / them, and add environmental variables, the specific operation as shown below:

6, the test

(1) is pressed to start the operation of FIG items:

(2) Open your browser, type http: // localhost: 8080 / testresp, verification can be. Specific operation is as follows:

So far, we have completed the creation of the idea among a springmvc project, and completed the test.



Guess you like

Origin www.cnblogs.com/alichengxuyuan/p/12581834.html