Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
SpringBoot_book
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨雪
SpringBoot_book
Commits
0598f71d
提交
0598f71d
authored
4月 14, 2020
作者:
杨雪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改修改后的版本â
上级
3d0a6192
隐藏空白字符变更
内嵌
并排
正在显示
21 个修改的文件
包含
1004 行增加
和
49 行删除
+1004
-49
README.md
README.md
+14
-0
pom.xml
pom.xml
+7
-0
DateConvert.java
src/main/java/com/example/config/DateConvert.java
+82
-0
MybatisConfig.java
src/main/java/com/example/config/MybatisConfig.java
+87
-0
BookController.java
src/main/java/com/example/controller/BookController.java
+17
-29
RecordController.java
src/main/java/com/example/controller/RecordController.java
+45
-0
UserController.java
src/main/java/com/example/controller/UserController.java
+50
-0
DaoMapper.java
src/main/java/com/example/dao/DaoMapper.java
+27
-5
RecordMapper.java
src/main/java/com/example/dao/RecordMapper.java
+41
-0
UserMapper.java
src/main/java/com/example/dao/UserMapper.java
+35
-0
Book.java
src/main/java/com/example/entity/Book.java
+15
-7
Record.java
src/main/java/com/example/entity/Record.java
+41
-0
User.java
src/main/java/com/example/entity/User.java
+30
-0
BookService.java
src/main/java/com/example/service/BookService.java
+3
-6
BookServiceImpl.java
src/main/java/com/example/service/BookServiceImpl.java
+39
-1
RecordService.java
src/main/java/com/example/service/RecordService.java
+24
-0
RecordServiceImpl.java
src/main/java/com/example/service/RecordServiceImpl.java
+120
-0
UserService.java
src/main/java/com/example/service/UserService.java
+23
-0
UserServiceImpl.java
src/main/java/com/example/service/UserServiceImpl.java
+80
-0
application.yml
src/main/resources/application.yml
+4
-1
BookDAO.xml
src/main/resources/mapper/BookDAO.xml
+220
-0
没有找到文件。
README.md
0 → 100644
浏览文件 @
0598f71d
-
项目简介
本项目实现了一个简单的图书借阅系统。
-
环境依赖
IDE:IntelliJ IDEA2019.1.3
JDK:1.8
MySql:8.0
-
目录结构描述
entity:模型层,存放实体类
dao:持久化层
service:业务逻辑层
controller:控制层,处理用户输入请求
pom.xml
浏览文件 @
0598f71d
...
...
@@ -40,6 +40,13 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.zaxxer
</groupId>
<artifactId>
HikariCP
</artifactId>
<version>
3.4.1
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
...
...
src/main/java/com/example/config/DateConvert.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.util.StringUtils
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
/**
* 格式化时间转换器
*/
@Configuration
public
class
DateConvert
{
@Bean
public
Converter
<
String
,
Date
>
DateConvert
()
{
return
new
Converter
<
String
,
Date
>()
{
@Override
public
Date
convert
(
String
source
)
{
if
(
StringUtils
.
isEmpty
(
source
))
{
return
null
;
}
else
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
Date
date
=
null
;
try
{
date
=
df
.
parse
(
source
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
date
;
}
}
};
}
@Bean
public
Converter
<
String
,
LocalDate
>
LocalDateConvert
()
{
return
new
Converter
<
String
,
LocalDate
>()
{
@Override
public
LocalDate
convert
(
String
source
)
{
if
(
StringUtils
.
isEmpty
(
source
))
{
return
null
;
}
else
{
DateTimeFormatter
df
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
LocalDate
date
=
null
;
try
{
date
=
LocalDate
.
parse
(
source
,
df
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
date
;
}
}
};
}
@Bean
public
Converter
<
String
,
LocalDateTime
>
LocalDateTimeConvert
()
{
return
new
Converter
<
String
,
LocalDateTime
>()
{
@Override
public
LocalDateTime
convert
(
String
source
)
{
if
(
StringUtils
.
isEmpty
(
source
))
{
return
null
;
}
else
{
DateTimeFormatter
df
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
LocalDateTime
date
=
null
;
try
{
date
=
LocalDateTime
.
parse
(
source
,
df
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
date
;
}
}
};
}
}
src/main/java/com/example/config/MybatisConfig.java
0 → 100644
浏览文件 @
0598f71d
//package com.example.config;
//
//import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;
//import com.zaxxer.hikari.HikariConfig;
//import com.zaxxer.hikari.HikariDataSource;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.annotation.PreDestroy;
//import javax.sql.DataSource;
//import java.io.IOException;
//
///**
// * 数据持久层配置
// *
// * @author smartye
// */
//@Configuration
//@MapperScan(basePackages = "com.example.dao")
//@EnableTransactionManagement
//public class MybatisConfig {
//
// Log log = LogFactory.getLog(getClass());
//
// HikariDataSource ds;
//
// @Bean
// public DataSource dataSource(@Value("com.mysql.cj.jdbc.Driver") String driverClassName,
// @Value("jdbc:mysql://localhost:3306/book?useSSL=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai") String jdbcUrl,
// @Value("root") String username,
// @Value("root") String password
// ) {
// HikariConfig config = new HikariConfig();
// config.setDriverClassName(driverClassName);
// config.setJdbcUrl(jdbcUrl);
// config.setUsername(username);
// config.setPassword(password);
// config.addDataSourceProperty("cachePrepStmts", true);
// config.addDataSourceProperty("useServerPrepStmts", true);
// config.addDataSourceProperty("maintainTimeStats", false);
// config.setIdleTimeout(60000);
// config.setConnectionTimeout(60000);
// config.setValidationTimeout(3000);
// config.setMaximumPoolSize(20);
// config.setMaxLifetime(60000);
// config.setMinimumIdle(10);
// config.setConnectionTestQuery("select 1");
// ds = new HikariDataSource(config);
// return ds;
// }
//
// @Bean
// public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) throws IOException {
// SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
// bean.setDataSource(dataSource);
// ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// bean.setMapperLocations(resolver.getResources("classpath*:mapper/*.xml"));
// return bean;
// }
//
// /**
// * 开启Spring的事务处理
// */
// @Bean
// public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) {
// DataSourceTransactionManager manager = new DataSourceTransactionManager();
// manager.setDataSource(dataSource);
// return manager;
// }
//
// @PreDestroy
// public void destroy() {
// ds.close();
// log.debug("关闭数据库连接池");
// AbandonedConnectionCleanupThread.checkedShutdown();
// }
//}
\ No newline at end of file
src/main/java/com/example/controller/BookController.java
浏览文件 @
0598f71d
...
...
@@ -3,60 +3,48 @@ package com.example.controller;
import
com.example.entity.Book
;
import
com.example.service.BookService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
value
=
"/book"
)
public
class
BookController
{
@Autowired
private
BookService
bookService
;
@RequestMapping
(
value
=
"/insert"
)
public
String
book
(){
Book
book
=
new
Book
();
book
.
setName
(
"西游记"
);
book
.
setAuthor
(
"吴承恩"
);
book
.
setPrice
(
52.3
);
book
.
setNum
(
10
);
int
i
=
bookService
.
insert
(
book
);
return
"成功加入"
+
i
+
"条记录"
;
public
List
<
Book
>
book
(
Book
book
){
bookService
.
insert
(
book
);
return
bookService
.
selectAll
();
}
@RequestMapping
(
value
=
"/selectAll"
)
public
String
findAll
(){
public
List
<
Book
>
findAll
(){
List
<
Book
>
bookList
=
bookService
.
selectAll
();
bookList
.
stream
().
forEach
(
System
.
out
::
println
);
return
bookList
.
toString
();
return
bookList
;
}
@RequestMapping
(
value
=
"/selectById"
)
public
Book
selectById
(){
Book
book
=
bookService
.
selectById
(
1
);
public
Book
selectById
(
int
id
){
Assert
.
notNull
(
id
,
"id不能为空"
);
Book
book
=
bookService
.
selectById
(
id
);
return
book
;
}
@RequestMapping
(
value
=
"/update"
)
public
String
update
(){
Book
book
=
new
Book
();
book
.
setName
(
"红楼梦"
);
book
.
setAuthor
(
"曹雪芹"
);
book
.
setPrice
(
52.2
);
book
.
setNum
(
13
);
int
i
=
bookService
.
update
(
2
,
book
);
return
"成功更新"
+
i
+
"条记录"
;
public
List
<
Book
>
update
(
Book
book
){
bookService
.
update
(
book
.
getId
(),
book
);
return
bookService
.
selectAll
();
}
@RequestMapping
(
value
=
"/delete"
)
public
String
delete
(
){
int
i
=
bookService
.
delete
(
3
);
return
"成功删除"
+
i
+
"条记录"
;
public
List
<
Book
>
delete
(
int
id
){
bookService
.
delete
(
id
);
return
bookService
.
selectAll
()
;
}
}
src/main/java/com/example/controller/RecordController.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
controller
;
import
com.example.entity.Book
;
import
com.example.entity.Record
;
import
com.example.service.RecordService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
value
=
"/record"
)
public
class
RecordController
{
@Autowired
private
RecordService
recordService
;
@RequestMapping
(
value
=
"/insert"
)
public
List
<
Record
>
insert
(
Record
record
){
recordService
.
insert
(
record
);
return
recordService
.
selectAll
();
}
@RequestMapping
(
"/returnBook"
)
public
Record
returnBook
(
int
recordId
){
return
recordService
.
returnBook
(
recordId
);
}
@RequestMapping
(
"/selectById"
)
public
Record
selectById
(
int
recordId
){
return
recordService
.
selectById
(
recordId
);
}
@RequestMapping
(
"/selectAll"
)
public
List
<
Record
>
selectAll
(){
return
recordService
.
selectAll
();
}
}
src/main/java/com/example/controller/UserController.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
controller
;
import
com.example.entity.User
;
import
com.example.service.UserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
value
=
"/user"
)
public
class
UserController
{
@Autowired
private
UserService
userService
;
@RequestMapping
(
value
=
"/selectById"
)
public
User
select
(
int
userId
){
return
userService
.
selectById
(
userId
);
}
@RequestMapping
(
value
=
"/selectAll"
)
public
List
<
User
>
selectAll
(){
return
userService
.
selectAll
();
}
@RequestMapping
(
value
=
"/insert"
)
public
List
<
User
>
insert
(
User
user
){
userService
.
insert
(
user
);
return
userService
.
selectAll
();
}
@RequestMapping
(
value
=
"/delete"
)
public
List
<
User
>
delete
(
int
userID
){
userService
.
delete
(
userID
);
return
userService
.
selectAll
();
}
@RequestMapping
(
value
=
"/update"
)
public
List
<
User
>
update
(
User
user
){
userService
.
update
(
user
.
getUserId
(),
user
);
return
userService
.
selectAll
();
}
}
src/main/java/com/example/dao/DaoMapper.java
浏览文件 @
0598f71d
...
...
@@ -2,28 +2,50 @@ package com.example.dao;
import
com.example.entity.Book
;
import
org.apache.ibatis.annotations.*
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* 描述:书籍相关操作服务层
*
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供书籍的增删改查接口
* @data 2020/4/13
**/
@Repository
@Mapper
public
interface
DaoMapper
{
// 新增一个book
/**
*
* @param book
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:37
*/
@Insert
(
"insert into book(name,author,price,num)values(#{name},#{author},#{price},#{num})"
)
int
insert
(
Book
book
);
// 删除一个book
@Delete
(
"delete from book where id = #{id}"
)
int
delete
(
Integer
id
);
// 更改一个book
@Update
(
"update book set name=#{book.name},author=#{book.author},price=#{book.price},num=#{book.num} where id =#{id}"
)
int
update
(
Integer
id
,
Book
book
);
// 查询一个book
@Select
(
"select id,name,author,price,num from book where id=#{id}"
)
Book
selectById
(
Integer
id
);
// 查询全部book
@Select
(
"select id,name,author,price,num from book"
)
List
<
Book
>
selectAll
();
...
...
src/main/java/com/example/dao/RecordMapper.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
dao
;
import
com.example.entity.Record
;
import
org.apache.ibatis.annotations.*
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
/**
* 描述:书籍相关操作服务层
*
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供记录的增删改查接口
* @data 2020/4/13
*
**/
@Repository
@Mapper
public
interface
RecordMapper
{
@Insert
(
"insert into record(bookId,userId)values(#{bookId},#{userId})"
)
int
insert
(
Record
record
);
@Delete
(
"delete from record where recordId=#{recordId}"
)
int
delete
(
int
recordId
);
@Update
(
"update record set returnDate=#{record.returnDate},hasReturn=#{record.hasReturn} where recordId =#{recordId}"
)
int
update
(
int
recordId
,
Record
record
);
@Select
(
"select * from record where recordId =#{recordId} "
)
Record
selectById
(
int
recordId
);
@Select
(
"select * from record"
)
List
<
Record
>
selectAll
();
}
src/main/java/com/example/dao/UserMapper.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
dao
;
import
com.example.entity.User
;
import
org.apache.ibatis.annotations.*
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* 描述:书籍相关操作服务层
* @author Yangxue
* @version V1.0
* @class DaoMapper
* @packageName com.example.dao
* @description 提供用户的增删改查接口
* @data 2020/4/13
**/
@Repository
@Mapper
public
interface
UserMapper
{
@Insert
(
"insert into user(name,age)values(#{name},#{age})"
)
int
insert
(
User
user
);
@Update
(
"update user set name=#{user.name},age=#{user.age} where userId =#{userId}"
)
int
update
(
int
userId
,
User
user
);
@Delete
(
"delete from user where userId =#{userId}"
)
int
delete
(
int
userId
);
@Select
(
"select * from user where userId =#{userId} "
)
User
selectById
(
int
userId
);
@Select
(
"select userId,name, age from user"
)
List
<
User
>
selectAll
();
}
src/main/java/com/example/entity/Book.java
浏览文件 @
0598f71d
...
...
@@ -3,23 +3,31 @@ package com.example.entity;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
//import javax.persistence.*;
/**
* @author: yangxue
* @createDate: 2020/4/13
* @description: this is the Book class.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
Book
{
/**
*书籍编号
*/
private
int
id
;
// @Column(name = "bookName")
/*
* 书籍名称
* */
private
String
name
;
// @Column(name = "author")
private
String
author
;
//
@Column(name = "price")
//
书籍的价格
private
Double
price
;
//
@Column(name = "num")
//
书籍的数量
private
long
num
;
...
...
src/main/java/com/example/entity/Record.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.Date
;
/**
* @author: yangxue
* @createDate: 2020/4/13
* @description: this is the Record class.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
Record
{
/*
* 记录编号
* */
private
Integer
recordId
;
/*
* 书籍编号
* */
private
Integer
bookId
;
/*
* 用户编号
* */
private
Integer
userId
;
/*
* 借书日期
* */
private
Date
lendDate
;
/*
* 还书日期
* */
private
Date
returnDate
;
/*
* 是否归还
* */
private
boolean
hasReturn
;
}
src/main/java/com/example/entity/User.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author: yangxue
* @createDate: 2020/4/13
* @description: this is the User class.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
User
{
/*
* 用户编号
* */
private
int
userId
;
/*
* 用户姓名
* */
private
String
name
;
/*
* 用户年龄
* */
private
int
age
;
}
src/main/java/com/example/service/BookService.java
浏览文件 @
0598f71d
...
...
@@ -5,21 +5,18 @@ import org.apache.ibatis.annotations.Delete;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
java.util.List
;
public
interface
BookService
{
int
insert
(
Book
book
);
// 删除一个book
int
delete
(
Integer
id
);
// 更改一个book
int
update
(
Integer
id
,
Book
book
);
int
update
(
Integer
id
,
Book
book
);
// 查询一个book
Book
selectById
(
Integer
id
);
// 查询全部book
List
<
Book
>
selectAll
();
}
src/main/java/com/example/service/BookServiceImpl.java
浏览文件 @
0598f71d
...
...
@@ -12,26 +12,64 @@ public class BookServiceImpl implements BookService {
@Autowired
private
DaoMapper
daoMapper
;
/**
*
* @param book
* @Return : 成功添加的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:41
* @describe:添加
*/
@Override
public
int
insert
(
Book
book
)
{
return
daoMapper
.
insert
(
book
);
}
/**
*
* @param id
* @Return : 成功删除的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:41
* @describe: 删除书籍
*/
@Override
public
int
delete
(
Integer
id
)
{
return
daoMapper
.
delete
(
id
);
}
/**
*
* @param id,book
* @Return : 成功更新的记录数
* @Author : YangXue
* @Date : 2020/4/14 10:43
* @describe: 更新书籍
*/
@Override
public
int
update
(
Integer
id
,
Book
book
)
{
public
int
update
(
Integer
id
,
Book
book
)
{
return
daoMapper
.
update
(
id
,
book
);
}
/**
* @param id
* @Return : com.example.entity.Book
* @Author : YangXue
* @Date : 2020/4/14 10:45
* @describe: 根据书籍编号查找书籍
*/
@Override
public
Book
selectById
(
Integer
id
)
{
return
daoMapper
.
selectById
(
id
);
}
/**
* @Return : java.util.List<com.example.entity.Book>
* @Author : YangXue
* @Date : 2020/4/14 10:47
* * * @describe: 查找全部书籍
*/
@Override
public
List
<
Book
>
selectAll
()
{
return
daoMapper
.
selectAll
();
...
...
src/main/java/com/example/service/RecordService.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
service
;
import
com.example.entity.Book
;
import
com.example.entity.Record
;
import
org.apache.ibatis.annotations.Delete
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
java.util.List
;
public
interface
RecordService
{
int
insert
(
Record
record
);
int
delete
(
int
recordId
);
int
update
(
int
recordId
,
Record
record
);
Record
selectById
(
int
recordId
);
List
<
Record
>
selectAll
();
Record
returnBook
(
int
RecordId
);
}
src/main/java/com/example/service/RecordServiceImpl.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
service
;
import
com.example.dao.RecordMapper
;
import
com.example.entity.Book
;
import
com.example.entity.Record
;
import
com.example.entity.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
RecordServiceImpl
implements
RecordService
{
@Autowired
private
RecordMapper
recordMapper
;
@Autowired
private
BookService
bookService
;
@Autowired
private
UserService
userService
;
/**
*
* @param record
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:49
* @describe: 借书时生成新订单
*/
@Override
public
int
insert
(
Record
record
)
{
Assert
.
notNull
(
record
.
getUserId
(),
"用户ID不能为空"
);
Assert
.
notNull
(
record
.
getBookId
(),
"书籍ID不能为空"
);
User
user
=
userService
.
selectById
(
record
.
getUserId
());
Book
book
=
bookService
.
selectById
(
record
.
getBookId
());
Assert
.
notNull
(
user
,
"用户不存在"
);
Assert
.
notNull
(
book
,
"书籍不存在"
);
if
(
book
.
getNum
()<=
0
){
throw
new
IllegalArgumentException
(
"库存不足"
);
}
book
.
setNum
(
book
.
getNum
()-
1
);
bookService
.
update
(
book
.
getId
(),
book
);
return
recordMapper
.
insert
(
record
);
}
/**
*
* @param recordId
* @Return : com.example.entity.Record
* @Author : YangXue
* @Date : 2020/4/14 10:49
* @describe: 根据订单号还书
*/
@Override
public
Record
returnBook
(
int
recordId
)
{
Record
record
=
recordMapper
.
selectById
(
recordId
);
if
(
record
.
isHasReturn
()==
false
){
record
.
setReturnDate
(
new
Date
());
record
.
setHasReturn
(
true
);
Book
book
=
bookService
.
selectById
(
record
.
getBookId
());
book
.
setNum
(
book
.
getNum
()+
1
);
bookService
.
update
(
book
.
getId
(),
book
);
recordMapper
.
update
(
recordId
,
record
);
}
return
recordMapper
.
selectById
(
record
.
getRecordId
());
}
/**
*
* @param recordId
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:50
* @describe: 根据记录编号查找借书记录
*/
@Override
public
int
delete
(
int
recordId
)
{
return
0
;
}
/**
* @param recordId
* @param record
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:51
* @describe: 更新记录的信息
*/
@Override
public
int
update
(
int
recordId
,
Record
record
)
{
return
recordMapper
.
update
(
recordId
,
record
);
}
/**
*
* @param recordId
* @Return : com.example.entity.Record
* @Author : YangXue
* @Date : 2020/4/14 10:52
* @describe: 根据编号查找记录
*/
@Override
public
Record
selectById
(
int
recordId
)
{
return
recordMapper
.
selectById
(
recordId
);
}
/**
*
* @Return : java.util.List<com.example.entity.Record>
* @Author : YangXue
* @Date : 2020/4/14 10:53
* * @describe: 根据全部记录
*/
@Override
public
List
<
Record
>
selectAll
()
{
return
recordMapper
.
selectAll
();
}
}
src/main/java/com/example/service/UserService.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
service
;
import
com.example.entity.User
;
import
org.apache.ibatis.annotations.Delete
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
interface
UserService
{
int
insert
(
User
user
);
int
update
(
int
userId
,
User
user
);
int
delete
(
int
userId
);
User
selectById
(
int
userId
);
List
<
User
>
selectAll
();
}
src/main/java/com/example/service/UserServiceImpl.java
0 → 100644
浏览文件 @
0598f71d
package
com
.
example
.
service
;
import
com.example.dao.UserMapper
;
import
com.example.entity.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
UserServiceImpl
implements
UserService
{
@Autowired
private
UserMapper
userMapper
;
/**
*
* @param user
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:55
* @describe: 添加用户
*/
@Override
public
int
insert
(
User
user
)
{
return
userMapper
.
insert
(
user
);
}
/**
* @param userId
* @param user
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:56
* @describe: 更新用户信息
*/
@Override
public
int
update
(
int
userId
,
User
user
)
{
return
userMapper
.
update
(
userId
,
user
);
}
/**
*
* @param userId
* @Return : int
* @Author : YangXue
* @Date : 2020/4/14 10:56
* @describe: 根据用户编号删除用户信息
*/
@Override
public
int
delete
(
int
userId
)
{
return
userMapper
.
delete
(
userId
);
}
/**
*
* @param userId
* @Return : com.example.entity.User
* @Author : YangXue
* @Date : 2020/4/14 10:57
* @describe: 根据用户编号查找用户
*/
@Override
public
User
selectById
(
int
userId
)
{
User
user
=
userMapper
.
selectById
(
userId
);
return
user
;
}
/**
*
* @Return : java.util.List<com.example.entity.User>
* @Author : YangXue
* @Date : 2020/4/14 10:57
* @describe: 查找全部用户信息
*/
@Override
public
List
<
User
>
selectAll
()
{
return
userMapper
.
selectAll
();
}
}
src/main/resources/application.yml
浏览文件 @
0598f71d
...
...
@@ -6,7 +6,10 @@ spring:
username
:
root
password
:
root
driver-class-name
:
com.mysql.cj.jdbc.Driver
jackson
:
date-format
:
yyyy年MM月dd日HH点mm分ss
time-zone
:
GMT+8
# mybatis
# mybatis
����
mybatis
:
type-aliases-package
:
com.fdd.mybatis.dao
src/main/resources/mapper/BookDAO.xml
0 → 100644
浏览文件 @
0598f71d
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.example.dao.BookDAO"
>
<resultMap
id=
"BaseResultMap"
type=
"com.example.entity.Book1"
>
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"author"
jdbcType=
"VARCHAR"
property=
"author"
/>
<result
column=
"name"
jdbcType=
"VARCHAR"
property=
"name"
/>
<result
column=
"num"
jdbcType=
"BIGINT"
property=
"num"
/>
<result
column=
"price"
jdbcType=
"DOUBLE"
property=
"price"
/>
</resultMap>
<sql
id=
"Example_Where_Clause"
>
<where>
<foreach
collection=
"oredCriteria"
item=
"criteria"
separator=
"or"
>
<if
test=
"criteria.valid"
>
<trim
prefix=
"("
prefixOverrides=
"and"
suffix=
")"
>
<foreach
collection=
"criteria.criteria"
item=
"criterion"
>
<choose>
<when
test=
"criterion.noValue"
>
and ${criterion.condition}
</when>
<when
test=
"criterion.singleValue"
>
and ${criterion.condition} #{criterion.value}
</when>
<when
test=
"criterion.betweenValue"
>
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when
test=
"criterion.listValue"
>
and ${criterion.condition}
<foreach
close=
")"
collection=
"criterion.value"
item=
"listItem"
open=
"("
separator=
","
>
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql
id=
"Update_By_Example_Where_Clause"
>
<where>
<foreach
collection=
"example.oredCriteria"
item=
"criteria"
separator=
"or"
>
<if
test=
"criteria.valid"
>
<trim
prefix=
"("
prefixOverrides=
"and"
suffix=
")"
>
<foreach
collection=
"criteria.criteria"
item=
"criterion"
>
<choose>
<when
test=
"criterion.noValue"
>
and ${criterion.condition}
</when>
<when
test=
"criterion.singleValue"
>
and ${criterion.condition} #{criterion.value}
</when>
<when
test=
"criterion.betweenValue"
>
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when
test=
"criterion.listValue"
>
and ${criterion.condition}
<foreach
close=
")"
collection=
"criterion.value"
item=
"listItem"
open=
"("
separator=
","
>
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql
id=
"Base_Column_List"
>
id, author, `name`, num, price
</sql>
<select
id=
"selectByExample"
parameterType=
"com.example.entity.Book1Example"
resultMap=
"BaseResultMap"
>
select
<if
test=
"distinct"
>
distinct
</if>
<include
refid=
"Base_Column_List"
/>
from book
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
<if
test=
"orderByClause != null"
>
order by ${orderByClause}
</if>
<if
test=
"limit != null"
>
<if
test=
"offset != null"
>
limit ${offset}, ${limit}
</if>
<if
test=
"offset == null"
>
limit ${limit}
</if>
</if>
</select>
<select
id=
"selectByPrimaryKey"
parameterType=
"java.lang.Integer"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from book
where id = #{id,jdbcType=INTEGER}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.Integer"
>
delete from book
where id = #{id,jdbcType=INTEGER}
</delete>
<delete
id=
"deleteByExample"
parameterType=
"com.example.entity.Book1Example"
>
delete from book
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</delete>
<insert
id=
"insert"
parameterType=
"com.example.entity.Book1"
>
insert into book (id, author, `name`,
num, price)
values (#{id,jdbcType=INTEGER}, #{author,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{num,jdbcType=BIGINT}, #{price,jdbcType=DOUBLE})
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.example.entity.Book1"
>
insert into book
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"author != null"
>
author,
</if>
<if
test=
"name != null"
>
`name`,
</if>
<if
test=
"num != null"
>
num,
</if>
<if
test=
"price != null"
>
price,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=INTEGER},
</if>
<if
test=
"author != null"
>
#{author,jdbcType=VARCHAR},
</if>
<if
test=
"name != null"
>
#{name,jdbcType=VARCHAR},
</if>
<if
test=
"num != null"
>
#{num,jdbcType=BIGINT},
</if>
<if
test=
"price != null"
>
#{price,jdbcType=DOUBLE},
</if>
</trim>
</insert>
<select
id=
"countByExample"
parameterType=
"com.example.entity.Book1Example"
resultType=
"java.lang.Long"
>
select count(*) from book
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</select>
<update
id=
"updateByExampleSelective"
parameterType=
"map"
>
update book
<set>
<if
test=
"record.id != null"
>
id = #{record.id,jdbcType=INTEGER},
</if>
<if
test=
"record.author != null"
>
author = #{record.author,jdbcType=VARCHAR},
</if>
<if
test=
"record.name != null"
>
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if
test=
"record.num != null"
>
num = #{record.num,jdbcType=BIGINT},
</if>
<if
test=
"record.price != null"
>
price = #{record.price,jdbcType=DOUBLE},
</if>
</set>
<if
test=
"_parameter != null"
>
<include
refid=
"Update_By_Example_Where_Clause"
/>
</if>
</update>
<update
id=
"updateByExample"
parameterType=
"map"
>
update book
set id = #{record.id,jdbcType=INTEGER},
author = #{record.author,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
num = #{record.num,jdbcType=BIGINT},
price = #{record.price,jdbcType=DOUBLE}
<if
test=
"_parameter != null"
>
<include
refid=
"Update_By_Example_Where_Clause"
/>
</if>
</update>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.example.entity.Book1"
>
update book
<set>
<if
test=
"author != null"
>
author = #{author,jdbcType=VARCHAR},
</if>
<if
test=
"name != null"
>
`name` = #{name,jdbcType=VARCHAR},
</if>
<if
test=
"num != null"
>
num = #{num,jdbcType=BIGINT},
</if>
<if
test=
"price != null"
>
price = #{price,jdbcType=DOUBLE},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.example.entity.Book1"
>
update book
set author = #{author,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
num = #{num,jdbcType=BIGINT},
price = #{price,jdbcType=DOUBLE}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论