how2j.cn

下载区
文件名 文件大小
请先登录 418k
增值内容 418k
418k
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 界面效果   
步骤 4 : login.html   
步骤 5 : UserDAO   
步骤 6 : UserService   
步骤 7 : loginPage.html   
步骤 8 : ForeRESTController.login()   

步骤 1 :

先运行,看到效果,再学习

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
界面效果
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
login.html
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head th:include="include/fore/header::html" ></head> <body> <div id="workingArea"> <div th:replace="include/fore/loginPage::html" ></div> <div th:replace="include/fore/footer::html" ></div> </div> </body> </html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include/fore/header::html" ></head>
<body>
<div id="workingArea">
    <div th:replace="include/fore/loginPage::html" ></div>
    <div th:replace="include/fore/footer::html" ></div>
</div>
</body>
</html>
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.dao; import org.springframework.data.jpa.repository.JpaRepository; import com.how2java.tmall.pojo.User; public interface UserDAO extends JpaRepository<User,Integer>{ User findByName(String name); User getByNameAndPassword(String name, String password); }
package com.how2java.tmall.dao;

import org.springframework.data.jpa.repository.JpaRepository;

import com.how2java.tmall.pojo.User;

public interface UserDAO extends JpaRepository<User,Integer>{

    User findByName(String name);

    User getByNameAndPassword(String name, String password);

}
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import com.how2java.tmall.dao.UserDAO; import com.how2java.tmall.pojo.User; import com.how2java.tmall.util.Page4Navigator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; @Service public class UserService { @Autowired UserDAO userDAO; public boolean isExist(String name) { User user = getByName(name); return null!=user; } public User getByName(String name) { return userDAO.findByName(name); } public User get(String name, String password) { return userDAO.getByNameAndPassword(name,password); } public Page4Navigator<User> list(int start, int size, int navigatePages) { Sort sort = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(start, size,sort); Page pageFromJPA =userDAO.findAll(pageable); return new Page4Navigator<>(pageFromJPA,navigatePages); } public void add(User user) { userDAO.save(user); } }
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
loginPage.html
<div th:fragment="html"> <script> $(function(){ var data4Vue = { uri:'forelogin', result: [], user:{name:'', password:''} }; //ViewModel var vue = new Vue({ el: '#workingArea', data: data4Vue, mounted:function(){ linkDefaultActions(); }, methods: { login:function(){ var url = this.uri; if(0==this.user.name.length){ $("span.errorMessage").html("请输入用户名"); $("div.loginErrorMessageDiv").css("visibility","visible"); return; } if(0==this.user.password.length){ $("span.errorMessage").html("请输入密码"); $("div.loginErrorMessageDiv").css("visibility","visible"); return; } axios.post(url,this.user).then(function(response) { var result = response.data; if(result.code==0){ location.href="home"; } else{ $("span.errorMessage").html(result.message); $("div.loginErrorMessageDiv").css("visibility","visible"); } }); } } }); var left = window.innerWidth/2+162; $("div.loginSmallDiv").css("left",left); }) </script> <div id="loginDiv" style="position: relative"> <div class="simpleLogo"> <a th:href="${application.contextPath}"><img src="img/site/simpleLogo.png"></a> </div> <img id="loginBackgroundImg" class="loginBackgroundImg" src="img/site/loginBackground.png"> <div id="loginSmallDiv" class="loginSmallDiv"> <div class="loginErrorMessageDiv"> <div class="alert alert-danger" > <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button> <span class="errorMessage">22</span> </div> </div> <div class="login_acount_text">账户登录</div> <div class="loginInput " > <span class="loginInputIcon "> <span class=" glyphicon glyphicon-user"></span> </span> <input v-model="user.name" placeholder="手机/会员名/邮箱" type="text"> </div> <div class="loginInput " > <span class="loginInputIcon "> <span class=" glyphicon glyphicon-lock"></span> </span> <input v-model="user.password" type="password" placeholder="密码"> </div> <span class="text-danger">不要输入真实的天猫账号密码</span><br><br> <div> <a class="notImplementLink" href="#nowhere">忘记登录密码</a> <a href="register" class="pull-right">免费注册</a> </div> <div style="margin-top:20px"> <button class="btn btn-block redButton" type="button" @click="login">登录</button> </div> </div> </div> </div>
步骤 8 :

ForeRESTController.login()

edit
增值内容,请先登录
完整的 Springboot 模仿天猫项目,使用 Springboot 、Vue.js、shiro、redis、elasticsearch 等一整套技术栈, 从无到有涵盖全部129个知识点,565个开发步骤, 充实 Springboot 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@PostMapping("/forelogin") public Object login(@RequestBody User userParam, HttpSession session) { String name = userParam.getName(); name = HtmlUtils.htmlEscape(name); User user =userService.get(name,userParam.getPassword()); if(null==user){ String message ="账号密码错误"; return Result.fail(message); } else{ session.setAttribute("user", user); return Result.success(); } }
package com.how2java.tmall.web; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.pojo.User; import com.how2java.tmall.service.CategoryService; import com.how2java.tmall.service.ProductService; import com.how2java.tmall.service.UserService; import com.how2java.tmall.util.Result; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.crypto.SecureRandomNumberGenerator; import org.apache.shiro.crypto.hash.SimpleHash; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.util.HtmlUtils; import javax.servlet.http.HttpSession; import java.util.List; @RestController public class ForeRESTController { @Autowired CategoryService categoryService; @Autowired ProductService productService; @Autowired UserService userService; @GetMapping("/forehome") public Object home() { List<Category> cs= categoryService.list(); productService.fill(cs); productService.fillByRow(cs); categoryService.removeCategoryFromProduct(cs); return cs; } @PostMapping("/foreregister") public Object register(@RequestBody User user) { String name = user.getName(); String password = user.getPassword(); name = HtmlUtils.htmlEscape(name); user.setName(name); boolean exist = userService.isExist(name); if(exist){ String message ="用户名已经被使用,不能使用"; return Result.fail(message); } user.setPassword(password); userService.add(user); return Result.success(); } @PostMapping("/forelogin") public Object login(@RequestBody User userParam, HttpSession session) { String name = userParam.getName(); name = HtmlUtils.htmlEscape(name); User user =userService.get(name,userParam.getPassword()); if(null==user){ String message ="账号密码错误"; return Result.fail(message); } else{ session.setAttribute("user", user); return Result.success(); } } }


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2021-11-18 JpaRepository 和 JpaSpecificationExecutor
你好啊007

这年头Springboot配JPA怪怪的,我还特地去翻了翻文档




1 个答案

how2j
答案时间:2021-12-02
spingboot配jpa 不是标配嘛



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2021-03-29 关于提示框
努力必进大厂

站长能解读下这个的意思嘛: data-dismiss="alert" aria-label="Close" 前端知识不扎实




1 个答案

how2j
答案时间:2021-04-03
data-dismiss 这个是 bootstrap 自定义的,可以不去管他。 aria-label 这个是给盲人用的,在特殊设备上会被读出来。



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2020-11-27 login的方法
2020-10-02 关于用户登录的请求方式问题
2020-09-20 关于@requestbody 与@responsebody


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 17 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站Springboot-登录 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图