package com.kb.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController
{
@RequestMapping("/controller1")
public String controllerFunc1(Model m)
{
m.addAttribute("msg","hello controller 1");
return "test";
}
@RequestMapping("/controller2")
public String controllerFunc2(Model m)
{
m.addAttribute("msg","hello controller 2");
return "test";
}
@RequestMapping("/controller3")
public String controllerFunc3(Model m)
{
m.addAttribute("msg","hello controller 3");
return "test";
}
}这里使用注解的方式,有三个方法可以被前端调用,分别为controllerFunc1;controllerFunc2;controllerFunc3;URL分别为http://localhost:8080/controller1;http://localhost:8080/controller2;http://localhost:8080/controller3。由于springmvc-servlet.xml里配置了web访问的路径前缀包括jsp,因此在WEB-INFO路径下添加jsp文件夹,并创建test.jsp文件。
<%--
Created by IntelliJ IDEA.
User: KingBoy
Date: 2021/11/14
Time: 19:03
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${msg}
</body>
</html>原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。