Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在spring boot中将数据填充到表onclick按钮中?_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

如何在spring boot中将数据填充到表onclick按钮中?

如何在spring boot中将数据填充到表onclick按钮中?,spring,spring-mvc,spring-boot,Spring,Spring Mvc,Spring Boot,我想在spring boot中单击一个按钮后将数据填充到表中。这意味着我想从视图页面的按钮调用中从控制器获取数据。我尝试了,但当我单击按钮时,不会调用我的请求映射方法 这是我遵循的代码 JSP页面按钮 <button type="button" class="btn btn-info"> <i class="fas fa-search fa-2x"></i> </button> 我的桌子 <table class="table

我想在spring boot中单击一个按钮后将数据填充到表中。这意味着我想从视图页面的按钮调用中从控制器获取数据。我尝试了,但当我单击按钮时,不会调用我的请求映射方法

这是我遵循的代码

  • JSP页面按钮

    <button type="button" class="btn btn-info">
        <i class="fas fa-search fa-2x"></i>
    </button>
    
    
    
  • 我的桌子

     <table class="table">
        <thead>
            <tr>
               <th>LastName</th>
                <th>FirstName</th>
            </tr>
        </thead>
    
           <tbody>
            <c:forEach items="${userInfoSelectedList}" var="user">
                    <tr>
                        <td>${user.firstname}</td>
                        <td>${user.lastname}</td>
    
                    </tr>
            </c:forEach>
        </tbody>
    </table>
    
    
    姓氏
    名字
    ${user.firstname}
    ${user.lastname}
    
  • 我的控制器代码

    @Controller
    public class UserRightsController {
       @RequestMapping(value="/user002222", method = RequestMethod.GET)
       public String getid(Model model) {      
          List<UserInfoModel> userInfoSelectedList = dao.getUserInfos();
         model.addAttribute("userInfoSelectedList", userInfoSelectedList);
         return "userrights";
        }   
    }
    
    @控制器
    公共类UserRightsController{
    @RequestMapping(value=“/user002222”,method=RequestMethod.GET)
    公共字符串getid(模型){
    List userInfoSelectedList=dao.getUserInfos();
    model.addAttribute(“userInfoSelectedList”,userInfoSelectedList);
    返回“用户权限”;
    }   
    }
    
  • 问题是如何从jsp页面调用onclick按钮这个方法。
    请帮助我?

    您可以在页面中使用JavaScript代码编写对web服务的调用:

    <button type="button" class="btn btn-info" onclick="callWebService()">
    
    
    
    在javascript代码中调用Web服务:

    <script language="JavaScript">
        function callWebService() {
            ....
        }
    </script>
    
    
    函数callWebService(){
    ....
    }
    
    您可以调用GET endpoint in按钮,如下所示:

    <button onclick="location.href='/user002222'">