package com.example.zxweb.controller;

import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.service.IZxCelueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description
 * @Author ZhouWenTao
 * @Date 2023/9/13 11:39
 */
@Controller
public class ThymeleafController {
    @Autowired
    IZxCelueService zxCelueService;
    @RequestMapping("/")
    public String index(HttpServletRequest request){
        return "index.html";
    }

    @RequestMapping("/celue/add")
    public String celueAdd(HttpServletRequest request,Model model){
        model.addAttribute("type","add");
        model.addAttribute("detail",new ZxCelueDTO());
        return "add.html";
    }

    @RequestMapping("/celue/{id}")
    public String celueDetail(@PathVariable("id")String id, Model model){
        ZxCelueDTO detail = zxCelueService.getDetail(id);
        model.addAttribute("detail",detail);
        model.addAttribute("type","detail");
        return "add.html";
    }
}
