贫民窟里的程序高手

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

ViewController:

package com.keafmd.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * Keafmd
 *
 * @ClassName: ViewController
 * @Description:
 * @author: 牛哄哄的柯南
 * @Date: 2021-04-02 14:47
 * @Blog: https://keafmd.blog.csdn.net/
 */
@Controller
public class ViewController {

    @GetMapping("getname")
    public String getName(Model model){
        model.addAttribute("name","keafmd");
        return "name";
    }
    @GetMapping("getage")
    public String getAge(Model model){
        model.addAttribute("age",18);
        return "age";
    }
}

在webapp下创建name.jsp和age.jsp

name.jsp:

<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/4/2
  Time: 14:31
  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>
<h1>name</h1>
${name}

</body>
</html>

age.jsp:

<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/4/2
  Time: 15:29
  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>
<h1>age</h1>
${age}

</body>
</html>

 

posted on 2022-11-23 20:07  贫民窟里的程序高手  阅读(167)  评论(0编辑  收藏  举报