首页 > 解决方案 > 从数据库中搜索并使用spring boot + html将其显示在网页中

问题描述

大家好,我是 Spring Boot 的新手,想创建一个功能,在我的搜索框中输入一个数字,并在网页上显示与数据相关的表格。

我将在搜索框中输入数字

然后信息应该是可见的。认为我是 Spring Boot 中的菜鸟,并且想要做这个功能请帮助我使用 html css for fromt end。请为我使用控制器类提供一个合适的示例,这是我的控制器类

package com.complaintportal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.complaintportal.entities.tbl_voicechat;
import com.complaintportal.serv.tbl_voicechatservice;

@org.springframework.stereotype.Controller
public class Controller {

    /*
     * @Autowired
     * 
     * private tbl_voicechatservice voiceservice;
     */

    @RequestMapping("/home")
    public String home(Model model) {
        model.addAttribute("title", "Welcome to Complaint Portal");
        return "home";
    }

    @RequestMapping("/complaint")
    public String complaint(Model model) {
        model.addAttribute("title", "Complaint lodge");
        return "complaint";
    }

    @RequestMapping("/minutes")
    public String minutes(Model model) {
        model.addAttribute("title", "Minutes not updated");
        return "minutes";
    }

    @RequestMapping("/unvoicht")
    public String unablevoicechat(Model model) {
        model.addAttribute("title", "Complaint lodge");
        return "unvoicht";
    }

    @GetMapping("/login")
    public String login() {
        return "/login";
    }
    
    /*
     * @RequestMapping(value = "/user/{ani}", method = RequestMethod.GET) public
     * tbl_voicechat getDataByANI(@PathVariable("ani") String ani) { return
     * voiceservice.getDataByANI(ani); }
     */

}

请帮助并提供合适的例子

标签: htmlspring-bootsts

解决方案


@RequestMapping(value = "/user", method = RequestMethod.GET) public tbl_voicechat getDataByANI(@RequestParam(name = "ani") String ani) {

returnvoiceservice.getDataByANI(ani);

}

您的代码应该可以工作,但请尝试使用它。

如果它不起作用,也分享您的 HTML。


推荐阅读