idea mysql做登录界面_IDEA下创建SpringBoot+MyBatis+MySql项目实现动态登录与注册功能...
一、搭建SpringBoot项目
1.1、file ——> new ——> project——> Spring Initializr——> next——> next——> next——> finish
注意选择包依赖关系
Web下的Spring Web。
Template Engines下的Thymeleaf。
SQL下的JDBC API、Spring Data JDBC、MySQL Driver。
二、springboot整合mybatis.mysql
2.1、整体结构
2.2、设置所需要的依赖
即pom.xml文件
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.4.2
springboot-web04
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-data-jdbc
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.3
mysql
mysql-connector-java
org.projectlombok
lombok
1.18.12
provided
com.alibaba
druid
1.2.1
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
org.xmlunit
xmlunit-core
org.mybatis
mybatis
3.4.6
org.springframework.boot
spring-boot-maven-plugin
2.3、设置application.yml文件与pplication.properties文件
在resources目录下新建yml文件,用于存放数据库连接需要的一些数据
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=GMT%2B8&useSSL=true
username: root #数据库
password: sm1208 #密码
在application.properties文件中加入
#端口号
server.port=8080
#druid数据库连接池
type=com.alibaba.druid.pool.DruidDataSource
#清除缓存
spring.thymeleaf.cache=false
#配置mapper
mybatis.mapper-locations=classpath:mapper/*.xml
2.4、在pojo下的新建类UserLogin
package springbootweb04.demo.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserLogin {
private String username;
private String password;
public String getUsername() {
return username;
}
}
2.5、新建数据库,名为mybatis,创建用户表,名为userLogin,创建username、password字段
2.5.1、数据库名可以随意,不过要与application.yml文件中的一致
2.5.2、IDEA中连接数据库
Database——> +——> Data Source——> Mysql
2.6、mapper层
新建UserLoginMapper接口
package springbootweb04.demo.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import springbootweb04.demo.pojo.UserLogin;
import java.util.List;
@Mapper
@Repository
public interface UserLoginMapper {
//查询 public List queryAll();
//添加数据 public int add(UserLogin userLogin);
//根据用户名查询数据 public UserLogin queryByName(String username);
}
2.7、resources目录下的mapper目录
在resources目录下新建mapper目录,并在这个目录下新建UserLoginMapper.xml文件
/p>
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select * from userLogin
insert into userLogin values (#{username},#{password})
select * from userLogin where username = #{username}
2.8、测试
在test.Java.springbootweb04.demo类中,测试是否能联通数据库,没有报错说明成功。
package springbootweb04.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import springbootweb04.demo.mapper.UserLoginMapper;
import springbootweb04.demo.pojo.UserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
@SpringBootTest
class DemoApplicationTests {
@Autowired
DataSource dataSource;
@Test
void contextLoads() throws SQLException {
System.out.println(dataSource.getClass());
Connection connection = dataSource.getConnection();
System.out.println(connection);
//template模板,拿来即用 connection.close();
}
@Autowired
UserLoginMapper userLoginMapper;
@Test
public void toTest(){
List userLogins = userLoginMapper.queryAll();
userLogins.forEach(e-> System.out.println(e));
}
}
2.9、services层
在services下新建接口UserLoginServicesI和类UserLoginServicesImpl
UserLoginServicesI接口:
package springbootweb04.demo.services;
import springbootweb04.demo.pojo.UserLogin;
import java.util.List;
public interface UserLoginServicesI {
//查询 public List queryAll();
//添加数据 public int add(UserLogin userLogin);
//根据用户名查询数据 public UserLogin queryByName(String username);
}
UserLoginServicesImpl类
package springbootweb04.demo.services;
import springbootweb04.demo.mapper.UserLoginMapper;
import springbootweb04.demo.pojo.UserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserLoginServicesImpl implements UserLoginServicesI {
@Autowired
UserLoginMapper userLoginMapper;
@Override
public List queryAll() {
return userLoginMapper.queryAll();
}
@Override
public int add(UserLogin userLogin) {
return userLoginMapper.add(userLogin);
}
@Override
public UserLogin queryByName(String username) {
return userLoginMapper.queryByName(username);
}
}
2.A、controller层
编写MyController类
package springbootweb04.demo.controller;
import springbootweb04.demo.pojo.UserLogin;
import springbootweb04.demo.services.UserLoginServicesImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
@Autowired
UserLoginServicesImpl userLoginServicesImpl;
@RequestMapping("/toLogin")
public String toLogin(){
return "login";
}
@RequestMapping("/LoginSuccess")
public String LoginSuccess(Model model, UserLogin userLogin){
//先查询看该用户名是否存在 UserLogin userLogin1 = userLoginServicesImpl.queryByName(userLogin.getUsername());
if(userLogin1 != null){ // 如果查询的用户不为空 System.out.println(userLogin1.toString());
return "success";
}
else{
//返回到登录页面 model.addAttribute("data","该用户不存在,请先注册");
return "login";
}
}
//登录界面 @RequestMapping("/toRegister")
public String toRegister(){
return "register";
}
@RequestMapping("/RegisterSuccess")
public String toRegisterSuccess(Model model,UserLogin userLogin){
//将账号密码加入到数据库中 int add = userLoginServicesImpl.add(userLogin);
System.out.println("数据插入成功!");
model.addAttribute("data","注册成功,请登录!");
return "login";
}
}
三、编写前端页面
将以下三个页面放在templates下面
login.html:登录页面
Title
登录界面
用户名:
密码:
register.html:注册页面
Title
注册界面
用户名:
密码:
确认密码:
success.html:成功界面
Title
四、运行测试知乎视频www.zhihu.com
PS:如果觉得我的分享不错,欢迎大家随手点赞。
idea mysql做登录界面_IDEA下创建SpringBoot+MyBatis+MySql项目实现动态登录与注册功能...相关推荐
- 创建springboot+mybatis+mysql项目
创建springboot+mybatis+mysql项目的源码https://download.csdn.net/download/qq_34297287/85245127可以点击上方下载创建spri ...
- mybatis mysql 配置文件路径_从零搭建SpringBoot+MyBatis+MySQL工程
目录 小白上路,寸草不生 若文章内容有误,欢迎留言指出~~~ 创建工程 使用依赖:web(前后端交互).mybatis(持久层).mysql(数据库驱动) 了解MVC模型 模型(model或serve ...
- 微信小程序后端mysql数据库_微信小程序后台springboot+mybatis+mysql“采坑”集锦
"采坑"错误集锦 1.service层 错误描述:2019-04-14 22:09:52.027 ERROR 8416 --- [nio-8082-exec-5] o.a.c.c. ...
- 微信小程序+SpringBoot+mybatis+MySQL实现简单的登录
微信小程序+SpringBoot+mybatis+MySQL实现简单的登录 当下微信小程序和springboot都是比较火的.今天我们来用springboot和微信小程序来实现简单的登录. 1.首先来 ...
- python制作qq登录界面_Python制作一个仿QQ办公版的图形登录界面
最近,QQ的办公版本--TIM进行了一次更新升级.本次更新升级大幅修改了界面的样式,看起来更加的清爽.简洁和高效了. 这种界面州的先生还是比较喜欢的,没有QQ那么花里胡哨,也比微信那些残缺的功能更加丰 ...
- 基于springboot+mybatis+mysql+layui员工工资管理系统
基于springboot+mybatis+mysql+layui员工工资管理系统 一.目的 二.需求 功能划分 系统结构设计 软件界面截图 三.系统开发配置 四.获取源码 一.目的 运用JavaE ...
- SpringBoot+MyBatis+Redis实现SSO单点登录系统(一)
SpringBoot+MyBatis+Redis实现SSO单点登录系统(一) 一.SSO系统概述 SSO英文全称Single Sign On,单点登录.SSO是在多个应用系统中,用户只需要登录一次就可 ...
- 基于javaweb的商品进销存系统(java+vue+springboot+mybatis+mysql)
基于javaweb的商品进销存系统(java+vue+springboot+mybatis+mysql) 运行环境 Java≥8.MySQL≥5.7.Node.js≥10 开发工具 后端:eclips ...
- ShardingSphere分库分表(SpringBoot+mybatis+mysql)配置
一.什么是ShardingSphere 定位为轻量级 Java 框架,在 Java 的 JDBC 层提供的额外服务. 它使用客户端直连数据库,以 jar 包形式提供服务,无需额外部署和依赖,可理解为增 ...
- Java+Springboot+Mybatis+Mysql+Bootstrap+Maven实现网上商城系统
网上商城系统 一.系统介绍 1.软件环境 2.功能模块图 3.系统功能 4.数据库表 5.SQL语句 6.工程截图 二.系统展示 1.用户-浏览商品 2.用户-注册 3.用户-登录 4.用户-购物车管 ...
最新文章
- 蓝桥杯:入门训练 圆的面积
- Silverlight C# 游戏开发:Flyer01开发一个有趣的游戏
- WARNING: cell0 mapping not found - not syncing cell0
- join orcl的left_oracle中left join与where
- ASP.Net Core Razor 部署AdminLTE框架
- js_!和!!的使用
- DOM相关(主要是var和let的区别用法)
- JS基础02之流程控制语句
- 全球最顶级的电脑配置_全球最顶级外汇交易员,非这10位莫属
- mybatis实体类类型别名
- OCJP认证该不该考?
- word文档计算机基础考试,计算机基础考试题库(含答案)48924
- 百度地图如何拾取经纬度
- 《软技能—代码之外的生存指南》读书笔记之二:自我营销
- HBuilderXHBuilder连接雷电模拟器“未检测到手机或模拟器” ---- 问题解决
- 免费网络硬盘、FTP、大容量邮箱、电子相册合集
- html调用一言api,纯 JavaScript 实现网站一言功能
- 避难所Android闪退,iOS/安卓版《辐射:避难所》Fallout Shelter攻略:闪退进不去解决办法...
- 转自stormzhang的一些博文
- 2018年07月17日(1~10)