Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
八重嘤
springboot-login
提交
0652ad3d
S
springboot-login
项目概览
八重嘤
/
springboot-login
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
springboot-login
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0652ad3d
编写于
4月 22, 2019
作者:
laoyog
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial commit
上级
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
341 addition
and
0 deletion
+341
-0
pom.xml
pom.xml
+52
-0
src/main/java/com/alibaba/Application.java
src/main/java/com/alibaba/Application.java
+19
-0
src/main/java/com/alibaba/bean/Result.java
src/main/java/com/alibaba/bean/Result.java
+46
-0
src/main/java/com/alibaba/bean/User.java
src/main/java/com/alibaba/bean/User.java
+34
-0
src/main/java/com/alibaba/controller/UserController.java
src/main/java/com/alibaba/controller/UserController.java
+40
-0
src/main/java/com/alibaba/mapper/UserMapper.java
src/main/java/com/alibaba/mapper/UserMapper.java
+44
-0
src/main/java/com/alibaba/service/UserService.java
src/main/java/com/alibaba/service/UserService.java
+69
-0
src/main/resources/application.yml
src/main/resources/application.yml
+11
-0
src/main/resources/templates/login.html
src/main/resources/templates/login.html
+13
-0
src/main/resources/templates/regist.html
src/main/resources/templates/regist.html
+13
-0
未找到文件。
pom.xml
0 → 100644
浏览文件 @
0652ad3d
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.alibaba
</groupId>
<artifactId>
springboot-login
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<java.version>
1.8
</java.version>
</properties>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.5.10.RELEASE
</version>
</parent>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<!--可以进行热部署 如不需要,可以不配置 idea默认运行期间不自动编译 需要提前配置一下-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<artifactId>
mybatis-spring-boot-starter
</artifactId>
<version>
1.3.1
</version>
</dependency>
<!--整合mysql-->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
<!--json @responseBody/@requestBody-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.54
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/com/alibaba/Application.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @SpringBootApplication相当于3个注解
* 1. @Configuration 定义一个配置类
* 2. @EnableAutoConfiguration spring boot自动根据jar包的依赖来自动配置项目
* 3. @ComponentScan spring自动扫描类上的注解, 并注入spring容器
*/
@SpringBootApplication
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Application
.
class
,
args
);
}
}
src/main/java/com/alibaba/bean/Result.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba.bean
;
/**
* 向前端返回信息封装
* @param <T> 可变类型
*/
public
class
Result
<
T
>
{
/**
* 返回信息
*/
private
String
msg
;
/**
* 数据是否正常请求
*/
private
boolean
success
;
/**
* 具体返回的数据
*/
private
T
detail
;
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
boolean
isSuccess
()
{
return
success
;
}
public
void
setSuccess
(
boolean
success
)
{
this
.
success
=
success
;
}
public
T
getDetail
()
{
return
detail
;
}
public
void
setDetail
(
T
detail
)
{
this
.
detail
=
detail
;
}
}
src/main/java/com/alibaba/bean/User.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba.bean
;
/**
* 用户信息
*/
public
class
User
{
private
Long
id
;
private
String
username
;
private
String
password
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
src/main/java/com/alibaba/controller/UserController.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba.controller
;
import
com.alibaba.bean.Result
;
import
com.alibaba.bean.User
;
import
com.alibaba.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/user"
)
public
class
UserController
{
@Autowired
private
UserService
userService
;
/**
* 注册
* @param user 参数封装
* @return Result
*/
@PostMapping
(
value
=
"/regist"
)
public
Result
regist
(
User
user
){
return
userService
.
regist
(
user
);
}
/**
* 登录
* @param user 参数封装
* @return Result
*/
@PostMapping
(
value
=
"/login"
)
public
Result
login
(
User
user
){
return
userService
.
login
(
user
);
}
}
src/main/java/com/alibaba/mapper/UserMapper.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba.mapper
;
import
com.alibaba.bean.User
;
import
org.apache.ibatis.annotations.*
;
import
org.springframework.stereotype.Repository
;
/**
* mapper的具体表达式
*/
@Mapper
//标记mapper文件位置,否则在Application.class启动类上配置mapper包扫描
@Repository
public
interface
UserMapper
{
/**
* 查询用户名是否存在,若存在,不允许注册
* 注解@Param(value) 若value与可变参数相同,注解可省略
* 注解@Results 列名和字段名相同,注解可省略
* @param username
* @return
*/
@Select
(
value
=
"select u.username,u.password from user u where u.username=#{username}"
)
@Results
({
@Result
(
property
=
"username"
,
column
=
"username"
),
@Result
(
property
=
"password"
,
column
=
"password"
)})
User
findUserByName
(
@Param
(
"username"
)
String
username
);
/**
* 注册 插入一条user记录
* @param user
* @return
*/
@Insert
(
"insert into user values(#{id},#{username},#{password})"
)
//加入该注解可以保存对象后,查看对象插入id
@Options
(
useGeneratedKeys
=
true
,
keyProperty
=
"id"
,
keyColumn
=
"id"
)
void
regist
(
User
user
);
/**
* 登录
* @param user
* @return
*/
@Select
(
"select u.id from user u where u.username = #{username} and password = #{password}"
)
Long
login
(
User
user
);
}
src/main/java/com/alibaba/service/UserService.java
0 → 100644
浏览文件 @
0652ad3d
package
com.alibaba.service
;
import
com.alibaba.bean.Result
;
import
com.alibaba.bean.User
;
import
com.alibaba.mapper.UserMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
class
UserService
{
@Autowired
private
UserMapper
userMapper
;
/**
* 注册
* @param user 参数封装
* @return Result
*/
public
Result
regist
(
User
user
)
{
Result
result
=
new
Result
();
result
.
setSuccess
(
false
);
result
.
setDetail
(
null
);
try
{
User
existUser
=
userMapper
.
findUserByName
(
user
.
getUsername
());
if
(
existUser
!=
null
){
//如果用户名已存在
result
.
setMsg
(
"用户名已存在"
);
}
else
{
userMapper
.
regist
(
user
);
//System.out.println(user.getId());
result
.
setMsg
(
"注册成功"
);
result
.
setSuccess
(
true
);
result
.
setDetail
(
user
);
}
}
catch
(
Exception
e
)
{
result
.
setMsg
(
e
.
getMessage
());
e
.
printStackTrace
();
}
return
result
;
}
/**
* 登录
* @param user 用户名和密码
* @return Result
*/
public
Result
login
(
User
user
)
{
Result
result
=
new
Result
();
result
.
setSuccess
(
false
);
result
.
setDetail
(
null
);
try
{
Long
userId
=
userMapper
.
login
(
user
);
if
(
userId
==
null
){
result
.
setMsg
(
"用户名或密码错误"
);
}
else
{
result
.
setMsg
(
"登录成功"
);
result
.
setSuccess
(
true
);
user
.
setId
(
userId
);
result
.
setDetail
(
user
);
}
}
catch
(
Exception
e
)
{
result
.
setMsg
(
e
.
getMessage
());
e
.
printStackTrace
();
}
return
result
;
}
}
src/main/resources/application.yml
0 → 100644
浏览文件 @
0652ad3d
server
:
port
:
9090
spring
:
datasource
:
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=utf-8&useSSL=false
username
:
root
password
:
123456
resources
:
static-locations
:
classpath:/templates
#访问静态页面
\ No newline at end of file
src/main/resources/templates/login.html
0 → 100644
浏览文件 @
0652ad3d
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
用户登录
</title>
</head>
<body>
<form
action=
"/user/login"
method=
"post"
>
用户名:
<input
name=
"username"
type=
"text"
/><br>
密码:
<input
name=
"password"
type=
"password"
>
<br>
<input
type=
"submit"
value=
"登录"
>
</form>
</body>
src/main/resources/templates/regist.html
0 → 100644
浏览文件 @
0652ad3d
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
用户注册
</title>
</head>
<body>
<form
action=
"/user/regist"
method=
"post"
>
用户名:
<input
name=
"username"
type=
"text"
/><br>
密码:
<input
name=
"password"
type=
"password"
>
<br>
<input
type=
"submit"
value=
"注册"
>
</form>
</body>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录