毕设-离不开的登录页
来源:互联网 发布:知乎精华故事 编辑:程序博客网 时间:2024/06/05 23:52
计划:登录页使用js验证;配置数据库;使用Mybatis从数据库查数据;使用Shiro验证登录
1、登录页
去除@ResponseBody(返回Json字符串),当返回值为String类型,SpringBoot会使用DispatcherServlet(自动配置)找到要返回的页面,我使用Thymeleaf模板,它提供了一套Spring的集成
Thymeleaf offers a set of Spring integrations that allow you to use it as a full-featured substitute for JSP in Spring MVC applications.
These integrations will allow you to:
- Make the mapped methods in your Spring MVC
@Controller
objects forward to templates managed by Thymeleaf, exactly like you do with JSPs. - Use Spring Expression Language (Spring EL) instead of OGNL in your templates.
- Create forms in your templates that are completely integrated with your form-backing beans and result bindings, including the use of property editors, conversion services and validation error handling.
- Display internationalization messages from messages files managed by Spring (through the usual
MessageSource
objects).
但是。写一个LoginController控制器处理 http://localhost:8080/login/login 请求
/** * @Author yinyunqi * @date 2017年12月20日 * @Content 登录控制 */package com.yongqi.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controller@RequestMapping("/login")public class LoginController { @RequestMapping("/login") public String doLogin() {return "login"; }}
然后添加模板依赖
<!-- Thymeleaf模板 --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>泪奔,如果你出现任何问题,无法显示页面,报一些看不懂的错,比如
Could not resolve view with name 'login' in servlet with name 'dispatcherServlet' 等等
只有一种出路。关掉,重启(或许clean一下项目),正常,耸肩,我想这是热启动没有将Thymeleaf加载进去,需要注意的是模板默认使用的配置是
页面放在templates下,静态文件在static下,如果需要自定义,就在application.properties中配置
#MVC配置spring.mvc.view.prefix=classpath:/XX/spring.mvc.view.suffix=.htmllogin.html如下
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>后台登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><img src="/img/design02.png" alt="" /> <form action="" method="post"> <p>账号:<input type="text" name="username" /></p> <p>密码:<input type="text" name="password" /></p> <p><input type="submit" value="登录"/></p></form> </body></html>页面
这样html页面和静态资源都可以用了
接着写验证,写完该吃饭了,啧
//处理登录验证http://localhost:8080/login/verify @RequestMapping("/verify") public String doVerify(HttpServletRequest request) {System.out.println(request.getParameter("username"));if (request.getParameter("username").equals("1")) { return "success";}else { return "fail";} }要注意的是要在templates中创建两个返回的页面,不然报错,也可能位置错误,细心,耐心,不行clean 重新编译
前台添加了请求地址
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>后台登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><form action="/login/verify" method="post"> <p>账号:<input type="text" name="username" /></p> <p>密码:<input type="text" name="password" /></p> <p><input type="submit" value="登录"/></p></form> </body></html>现在情况是:username输入1进success.html,否则fail.html
此时项目结构图
不过还是乱,为了可持续发展,晚上回去整理,然后将页面画好看点
- 毕设-离不开的登录页
- 毕设简单的登录界面
- 离不开的微信
- 毕设由登录模块所想
- 头疼的毕设
- 社会的进步离不开网络
- 上一次设的密码又登录不上了
- 在内网架设一个可供外网登录的ftp服务器
- 我们的毕设-苏醒
- [毕设]wamp的配置
- 品牌的成长离不开服务质量的提高
- 健康的身体离不开平日的养生
- 大学生成长离不开的十二个老师
- Web设计离不开的4项基本原则
- IT员工离不开的12项技术
- IT员工离不开的12项技术
- 放眼望去,始终离不开眼前的五彩斑斓
- CRM系统离不开好的业务流程
- 加快app的启动速度
- leetcode 9 Palindrome Number
- 朴素贝叶斯
- JavaScript 基本类型和引用类型
- 使用AMP的优点和缺点
- 毕设-离不开的登录页
- 异步处理springmvc的请求,关键字:@Async,CyclicBarrier,CountDownLatch
- Round-robin 轮询调度详解
- Vue基础(表单输入绑定)
- SSM框架整合 quartz 定时任务调度
- wcf获取客户端ip
- 关于jqGrid的demo路径
- git的使用介绍
- STL 标准模板库