当前位置: 首页 > news >正文

网站app免费制作软件网站开发 项目职责

网站app免费制作软件,网站开发 项目职责,seo外包公司哪家专业,矿泉水网站模板16.1 修改index.html中表单跳转的地址 将action的地址改为user/login&#xff0c;意思是点击提交按钮后&#xff0c;就会跳转到user/login地址&#xff0c;然后只要用Controller类的RequsetMapping去接这个地址就行了。 <body class"text-center"><form cl…

16.1 修改index.html中表单跳转的地址

        将action的地址改为user/login,意思是点击提交按钮后,就会跳转到user/login地址,然后只要用Controller类的@RequsetMapping去接这个地址就行了。

<body class="text-center"><form class="form-signin" th:action="@{user/login}"><img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" alt="" width="72" height="72"><h1 class="h3 mb-3 font-weight-normal">Please sign in</h1><label class="sr-only">Username</label><input type="text" class="form-control" placeholder="Username" required="" autofocus=""><label class="sr-only">Password</label><input type="password" class="form-control" placeholder="Password" required=""><div class="checkbox mb-3"><label><input type="checkbox" value="remember-me"> Remember me</label></div><button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button><p class="mt-5 mb-3 text-muted">© 2017-2018</p><a class="btn btn-sm">中文</a><a class="btn btn-sm">English</a></form></body>

16.2 controller类

        当访问localhost:8080/user/login时,会返回在页面返回一字符串(本例是hello),@ResponseBody是作用在方法上的,@ResponseBody 表示该方法的返回结果直接写入 HTTP response body 中。

package jiang.com.springbootstudy.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
public class LoginController {@RequestMapping("/user/login")@ResponseBodypublic String login(){return "hello";}
}

        以上代码只是简单实现了点击按钮后,访问请求,最后响应了一个字符串的过程。该项目中不需要使用ResponseBody注解,实现请求后的数据转发合页面跳转即可。注意,之前的表单中,input没有name属性,只有placeholder属性,改为name属性即可,然后相应的属性值改下,因为后面需要使用@RequestParm注解来接受表单数据,最终代码如下:

package jiang.com.springbootstudy.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;@Controller
public class LoginController {@RequestMapping("/user/login")public String login(@RequestParam("username") String username,@RequestParam("password") String password,Model model){if (!StringUtils.isEmpty(username)&&"123456".equals(password)){return "redirect:/main.html";}else {model.addAttribute("msg","用户名或密码错误!");return "index";}}
}

        这里使用了重定向(redirect), return "redirect:/main.html"会使访问localhost:8080/user.login地址后,网页被转移到localhost:8080/main.html地址,注意!这个是main.html是虚拟的地址,并不是转发到main.html页面的意思,因此需要使用mvc的配置类对请求就行转发,转发到实际地址中。最终,如果访问localhost:8080/main.html地址,就会打开一个dashboard.html页面。mvc配置类代码如下:

package jiang.com.springbootstudy.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class MyMvcConfig implements WebMvcConfigurer {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("index");  //setViewName后面不用加htmlregistry.addViewController("/index.html").setViewName("index");registry.addViewController("/main.html").setViewName("dashboard"); // 前面的main.html是假的,只是一种请求,后面才是真的,输入请求后会跳转的地方是后面的html}
}

16.3 修改index页面

        根据Controller类的处理逻辑,如果用户名和密码错误,就会返回indem.html页面,并转发msg数据。转发后,需要在相应位置上把msg数据显示出来。需要在相应位置上加一行html代码,并且对p标签的样式进行了更改,需要增加的html代码如下:

<link th:href="@{/css/mystyle.css}" type="text/css" rel="stylesheet">
<p  class="p-msg" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>

        css样式的代码如下:

p.p-msg{color: red;
}

        输入错误后转发到index.html的结果:

 16.4 

http://www.yayakq.cn/news/720474/

相关文章:

  • 做网站外包需要提供什么适合在家做的电商
  • 网站索引量突然下降给公司做网站销售怎样啦
  • 学校网站总务建设北京企业网站开发费用
  • 李沧网站建设公司懒设计app
  • 网上购物的网站开发背景无锡专业网站制作的公司
  • php网站开发工资安防 光速东莞网站建设
  • 下列关于网站开发中网站上传动画设计培训学校排名
  • 申请网站多少钱网站建设管理实训报告
  • 网站编辑怎么做的杭州专业做网站的公司有哪些
  • 技术网站有哪些做亚马逊常用的网站
  • 建网站需要几程序员重庆网站建设企业
  • 网赌网站怎么做找人设计网页多少钱
  • 做门户网站开发的技术广州百度网站建设公司
  • 本地建站教程装饰网站建设的背景
  • 麻涌企业网站建设网站怎样备案
  • 网站续费申请如何做网站浏览pdf
  • 网站百度不收录开发一个app软件的开发费用
  • 朔州网站建设价格建立企业网站的缺点
  • 鲨鱼座 网站建设免费域名注册网站怎么登录
  • 网站推广岗位的要求如何查询网站是否备案
  • 单位做员工招退工在什么网站备案查询化妆品
  • 上海市建设工程备案查询网站建站教程wp
  • 重庆哪家做网站好深紫色网站
  • 安徽平台网站建设外贸行业要死光了2022
  • 湛江购房网官方网站宁波网站排名优化报价
  • 强大的技术团队网站建设新平台推广
  • 郑州好的网站建设公司哪家好简单网站首页怎么做
  • 上海做网站运维的公司上海专业做网站较好的公司
  • 建设与管理局网站网站后台不能编辑
  • 学校网站建设整改报告找人帮你做ppt的网站吗