Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
library_demo
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
xuyang
library_demo
Commits
798cc988
提交
798cc988
authored
4月 13, 2020
作者:
xuyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first commit
上级
46ae20e5
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
135 行增加
和
21 行删除
+135
-21
BooksController.java
...java/com/springboot/demo1/controller/BooksController.java
+35
-5
BorrowInfoController.java
...com/springboot/demo1/controller/BorrowInfoController.java
+4
-8
UserController.java
.../java/com/springboot/demo1/controller/UserController.java
+34
-7
BooksRepository.java
src/main/java/com/springboot/demo1/dao/BooksRepository.java
+2
-0
UserRepository.java
src/main/java/com/springboot/demo1/dao/UserRepository.java
+4
-0
Books.java
src/main/java/com/springboot/demo1/entity/Books.java
+3
-0
BorrowInfo.java
src/main/java/com/springboot/demo1/entity/BorrowInfo.java
+4
-0
BooksService.java
src/main/java/com/springboot/demo1/service/BooksService.java
+24
-1
UserService.java
src/main/java/com/springboot/demo1/service/UserService.java
+17
-0
BooksServiceImpl.java
...a/com/springboot/demo1/service/impl/BooksServiceImpl.java
+6
-0
UserServiceImpl.java
...va/com/springboot/demo1/service/impl/UserServiceImpl.java
+2
-0
没有找到文件。
src/main/java/com/springboot/demo1/controller/BooksController.java
浏览文件 @
798cc988
...
...
@@ -3,24 +3,54 @@ package com.springboot.demo1.controller;
import
com.springboot.demo1.entity.Books
;
import
com.springboot.demo1.service.BooksService
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Controller
@
Rest
Controller
@RequestMapping
(
value
=
"/books"
)
public
class
BooksController
{
@Resource
private
BooksService
booksService
;
//获取图书列表
@PostMapping
(
value
=
"/get"
)
@ResponseBody
public
List
<
Books
>
getBooksList
(){
return
booksService
.
getBooksList
();
}
//根据书本ID查找书籍
@PostMapping
(
value
=
"/get/{bookId}"
)
public
Books
getBookById
(
@PathVariable
Integer
bookId
){
return
booksService
.
getBookById
(
bookId
);
}
//添加书籍
@PostMapping
(
value
=
"/add/{bookName}"
)
public
String
addBook
(
@PathVariable
String
bookName
)
{
if
(
bookName
==
null
||
bookName
.
length
()
<
1
)
{
return
"书名信息有误"
;
}
else
{
String
res
=
booksService
.
addBook
(
bookName
);
if
(
res
!=
null
)
{
return
res
;
}
else
{
return
"内部错误"
;
}
}
}
//根据书本ID删除书籍
@PostMapping
(
value
=
"/delete/{bookId}"
)
public
String
deleteBook
(
@PathVariable
Integer
bookId
)
{
String
res
=
booksService
.
deleteBook
(
bookId
);
if
(
res
!=
null
)
{
return
res
;
}
else
{
return
"内部错误"
;
}
}
}
src/main/java/com/springboot/demo1/controller/BorrowInfoController.java
浏览文件 @
798cc988
...
...
@@ -3,29 +3,26 @@ package com.springboot.demo1.controller;
import
com.springboot.demo1.entity.BorrowInfo
;
import
com.springboot.demo1.service.BorrowInfoService
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Controller
@
Rest
Controller
@RequestMapping
(
value
=
"/borrowInfo"
)
public
class
BorrowInfoController
{
@Resource
private
BorrowInfoService
borrowInfoService
;
//获取借阅信息列表
@PostMapping
(
value
=
"/get"
)
@ResponseBody
public
List
<
BorrowInfo
>
getBorrowInfoList
()
{
return
borrowInfoService
.
getBorrowInfoList
();
}
//借书还书
@PostMapping
(
value
=
"/update/{userId}/{bookId}/{type}"
)
@ResponseBody
public
String
updateBorrowInfo
(
@PathVariable
Integer
userId
,
@PathVariable
Integer
bookId
,
@PathVariable
Integer
type
)
{
if
(
userId
==
null
||
bookId
==
null
||
type
==
null
)
{
return
"error 504"
;
...
...
@@ -40,7 +37,6 @@ public class BorrowInfoController {
}
else
{
return
"内部错误"
;
}
}
}
...
...
src/main/java/com/springboot/demo1/controller/UserController.java
浏览文件 @
798cc988
...
...
@@ -2,26 +2,53 @@ package com.springboot.demo1.controller;
import
com.springboot.demo1.entity.User
;
import
com.springboot.demo1.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Controller
@
Rest
Controller
@RequestMapping
(
value
=
"/user"
)
public
class
UserController
{
@Resource
private
UserService
userService
;
//获取用户列表
@PostMapping
(
value
=
"/get"
)
@ResponseBody
public
List
<
User
>
getUserList
(){
return
userService
.
getUserList
();
}
//根据用户ID获取用户
@PostMapping
(
value
=
"/get/{userId}"
)
public
User
getUserById
(
@PathVariable
Integer
userId
){
return
userService
.
getUserByUserId
(
userId
);
}
//添加用户
/*@PostMapping(value = "/add/{userName}/{passWord}/{email}/{nickName}")
public String addUser(@PathVariable String userName,@PathVariable String passWord,@PathVariable String email,
@PathVariable String nickName){*/
@PostMapping
(
value
=
"/add"
)
public
String
addUser
(
String
userName
,
String
passWord
,
String
email
,
String
nickName
){
if
(
passWord
==
null
||
passWord
.
length
()
<
6
)
{
return
"密码格式有误"
;
}
else
if
(
email
==
null
||
email
.
length
()
<
6
)
{
return
"邮箱格式有误"
;
}
else
{
User
user
=
new
User
();
user
.
setUserName
(
userName
);
user
.
setPassWord
(
passWord
);
user
.
setEmail
(
email
);
user
.
setNickName
(
nickName
);
String
res
=
userService
.
addUser
(
user
);
if
(
res
!=
null
)
{
return
res
;
}
else
{
return
"内部错误"
;
}
}
}
}
src/main/java/com/springboot/demo1/dao/BooksRepository.java
浏览文件 @
798cc988
...
...
@@ -7,4 +7,6 @@ public interface BooksRepository extends JpaRepository<Books, Integer> {
Books
findBooksByBookId
(
Integer
bookId
);
Integer
countBooksByBookName
(
String
bookName
);
}
src/main/java/com/springboot/demo1/dao/UserRepository.java
浏览文件 @
798cc988
...
...
@@ -11,4 +11,8 @@ public interface UserRepository extends JpaRepository<User,Integer> {
User
getUserByUserId
(
Integer
userId
);
Integer
countUserByEmail
(
String
email
);
Integer
countUserByUserName
(
String
userName
);
}
src/main/java/com/springboot/demo1/entity/Books.java
浏览文件 @
798cc988
...
...
@@ -9,13 +9,16 @@ import javax.persistence.*;
@Data
public
class
Books
{
//书籍ID
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Integer
bookId
;
//书名
@Column
(
nullable
=
false
,
unique
=
true
)
private
String
bookName
;
//借阅状态 ==0表示书籍未被借阅 ==1表示书籍已被借阅
@Column
(
nullable
=
false
)
private
Integer
bookState
;
...
...
src/main/java/com/springboot/demo1/entity/BorrowInfo.java
浏览文件 @
798cc988
...
...
@@ -8,16 +8,20 @@ import javax.persistence.*;
@Data
public
class
BorrowInfo
{
//借阅信息ID
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Integer
borrowId
;
//用户ID
@Column
(
nullable
=
false
)
private
Integer
userId
;
//书籍ID
@Column
(
nullable
=
false
)
private
Integer
bookId
;
//借阅状态 ==1表示借书 ==0表示还书
@Column
(
nullable
=
false
)
private
Integer
type
;
...
...
src/main/java/com/springboot/demo1/service/BooksService.java
浏览文件 @
798cc988
...
...
@@ -14,8 +14,31 @@ public class BooksService implements BooksServiceImpl {
@Autowired
private
BooksRepository
booksRepository
;
public
List
<
Books
>
getBooksList
(){
public
List
<
Books
>
getBooksList
()
{
return
booksRepository
.
findAll
();
}
public
Books
getBookById
(
Integer
bookId
)
{
return
booksRepository
.
findBooksByBookId
(
bookId
);
}
public
String
addBook
(
String
bookName
)
{
Integer
numByBookName
=
booksRepository
.
countBooksByBookName
(
bookName
);
if
(
numByBookName
>
0
)
{
return
"该书籍已经存在"
;
}
else
{
Books
books
=
new
Books
();
books
.
setBookName
(
bookName
);
books
.
setBookState
(
0
);
//bookState为0表示书籍未被借出
booksRepository
.
save
(
books
);
return
"书籍上传成功"
;
}
}
public
String
deleteBook
(
Integer
bookId
)
{
booksRepository
.
deleteById
(
bookId
);
return
"书籍删除成功"
;
}
}
src/main/java/com/springboot/demo1/service/UserService.java
浏览文件 @
798cc988
...
...
@@ -18,5 +18,22 @@ public class UserService implements UserServiceImpl {
return
userRepository
.
findAll
();
}
public
User
getUserByUserId
(
Integer
userId
)
{
return
userRepository
.
getUserByUserId
(
userId
);
}
public
String
addUser
(
User
user
)
{
Integer
numByEmail
=
userRepository
.
countUserByEmail
(
user
.
getEmail
());
Integer
numByUserName
=
userRepository
.
countUserByUserName
(
user
.
getUserName
());
if
(
numByEmail
>
0
)
{
return
"该邮箱已被使用"
;
}
else
if
(
numByUserName
>
0
)
{
return
"该用户名已被使用"
;
}
else
{
userRepository
.
save
(
user
);
}
return
"新建用户成功"
;
}
}
src/main/java/com/springboot/demo1/service/impl/BooksServiceImpl.java
浏览文件 @
798cc988
...
...
@@ -8,4 +8,10 @@ public interface BooksServiceImpl {
public
List
<
Books
>
getBooksList
();
public
Books
getBookById
(
Integer
bookId
);
public
String
addBook
(
String
bookName
);
public
String
deleteBook
(
Integer
bookId
);
}
src/main/java/com/springboot/demo1/service/impl/UserServiceImpl.java
浏览文件 @
798cc988
...
...
@@ -8,5 +8,7 @@ public interface UserServiceImpl {
public
List
<
User
>
getUserList
();
public
User
getUserByUserId
(
Integer
userId
);
public
String
addUser
(
User
user
);
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论