加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Spring boot + thymeleaf 后端直接给onclick函数赋值的实现代码

发布时间:2020-12-14 19:49:21 所属栏目:Java 来源:网络整理
导读:这里是控制器里返回的 /** * @param pageUtil 分页工具类 * @param cliCorpQuery 查询类 * @param model model * @return String */ @RequestMapping(value = {"/list"},method = RequestMethod.GET) public String list(PageUtilCliCorp pageUtil,CliCorpQu

 这里是控制器里返回的 

  /** 
   * @param pageUtil   分页工具类 
   * @param cliCorpQuery 查询类 
   * @param model    model 
   * @return String 
   */ 
  @RequestMapping(value = {"/list"},method = RequestMethod.GET) 
  public String list(PageUtil<CliCorp> pageUtil,CliCorpQuery cliCorpQuery,Model model) { 
    PageUtil<CliCorp> corps; 
    try { 
      corps = corpClientService.queryByPage(pageUtil,cliCorpQuery); 
    } catch (Exception e) { 
      logger.error("queryByPage error:" + e.getMessage()); 
      return "queryByPage error"; 
    } 
    model.addAttribute("corps",corps); 
    return VIEW_PATH + "list"; 
  } 

页面

<tr th:each="corp:${corps.contents}"> 
                    <td><span th:text="${corp.name}"></span></td> 
                    <td><span th:text="${corp.creditCode}"></span></td> 
                    <td><span th:text="${corp.taxNo}"></span></td> 
                    <td><span th:text="${corp.showName}"></span></td> 
                    <td><span th:text="${corp.bank}"></span></td> 
                    <td><span th:text="${corp.bankAccount}"></span></td> 
                    <td><span th:text="${corp.agent}"></span></td> 
                    <td><span th:text="${corp.address}"></span></td> 
                    <td><span th:text="${corp.status}"></span></td> 
                    <td><span th:text="${corp.creator}"></span></td> 
                    <td> 
                      <button type="button" th:onclick="'javascript:check('+${corp.id}+',2)'">审核 
                      </button> 
                      <button type="button" th:onclick="'javascript:check('+${corp.id}+',3)'">拒绝 
                      </button> 
                    </td> 
                  </tr> 

JS

function check(id,status) { 
   $.ajax({ 
     type: "POST",data: {id: id,status: status},url: "/admin/corp/check",success: function (data) { 
       if (data == "认证成功") { 
         window.location.href = ("/admin/corp/list"); 
       } else { 
         alert("认证失败"); 
       } 
     },error: function (data) { 
       alert("认证失败"); 
     } 
   }); 
 } 

以上所述是小编给大家介绍的Spring boot + thymeleaf 后端直接给onclick函数赋值的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

您可能感兴趣的文章:

  • Springboot访问html页面的教程详解
  • 详解SpringBoot+Thymeleaf 基于HTML5的现代模板引擎
  • spring boot请求异常处理并返回对应的html页面
  • springboot用thymeleaf模板的paginate分页完整代码
  • spring boot使用thymeleaf模板的方法详解
  • SpringBoot中的Thymeleaf用法
  • springboot中thymeleaf模板使用详解
  • springboot如何使用thymeleaf模板访问html页面

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读