PageController.java 1.52 KB
package com.xly.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 页面跳转控制器
 * 修复路径映射、视图名称、重定向路径问题
 */
@Controller
@RequestMapping("/chat") // 类级别路径前缀:/xlyAi/chat(结合context-path)
public class PageController {
//"C:\Users\Administrator\AppData\Local\Programs\Python\Python314\Scripts\tts_cli.py" -t "多层测试" -e cute -o "outputs\2024\01\15\test.mp3"
    /**
     * 聊天页面
     * 访问地址:http://localhost:8099/xlyAi/chat
     */
    @GetMapping // 方法级别无需加路径,继承类的@RequestMapping
    public String chatPage() {
        // 视图名称只需写 "chat",Spring会自动拼接:prefix + "chat" + suffix
        // 最终路径:classpath:/templates/chat.html
        return "chat";
    }

    @GetMapping ("/tts")// 方法级别无需加路径,继承类的@RequestMapping
    public String tts() {
        // 视图名称只需写 "chat",Spring会自动拼接:prefix + "chat" + suffix
        // 最终路径:classpath:/templates/chat.html
        return "tts";
    }

    /**
     * 首页重定向
     * 访问地址:http://localhost:8099/xlyAi/
     */
    @GetMapping("/../") // 匹配根路径 /xlyAi/(规避@RequestMapping("/chat")的影响)
    public String index() {
        // context-path已包含/xlyAi,重定向只需写相对路径/chat
        return "redirect:/chat";
    }
}