/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
③User
5.handle目录
①LoginHandlerInterceptor:登录拦截
public class LoginHandlerInterceptor implements HandlerInterceptor {
// 目标方法执行之前
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object loginUser = request.getSession().getAttribute("loginUser");
if (loginUser==null){
// 未登录
request.setAttribute("msg","没有权限请先登录");
request.getRequestDispatcher("/index.html").forward(request,response);
return false;
}else{
return true;
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
②MyLocalResolver:启用国际化配置
public class MyLocalResolver implements LocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest httpServletRequest) {
String l = httpServletRequest.getParameter("l");
Locale locale =Locale.getDefault();
if(!StringUtils.isEmpty(l)){
String [] spilt = l.split("_");
locale = new Locale(spilt[0],spilt[1]);
}
return locale;
}
@Override
public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
}
}
③MyMetaObjectHandler
④UserLoginHandlerInterceptor
6.mapper
①BookMapper
②CategoryMapper
③UserMapper
7.service
①BookServiceImpl
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {
public Book addCover(BookDto book,MultipartFile photo) {
String path = "D:/360MoveData/Users/张振东/Desktop/图书管理系统/bookmanagersystem/src/main/resources/static/asserts/img/"; // 保存路径
String fileName = null;
if (!photo.isEmpty()) {
fileName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
String suffix = photo.getOriginalFilename()
.substring(photo.getOriginalFilename().lastIndexOf("."));
System.out.println(suffix);
if (!suffix.equals(".jpg") || !suffix.equals(".png") || !suffix.equals(".gif")) {
}
try {
// Spring提供了文件操作类FileCopyUtils
FileCopyUtils.copy(photo.getInputStream(), new FileOutputStream( path + fileName + suffix));
fileName = "http://www.nucsell.com:8080/asserts/img/" + fileName + suffix;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// return dealResultMap(false, "上传失败");
}
}
System.out.println(path);
Book book1 = new Book();
book1.setId(book.getId());
book1.setName(book.getName());
book1.setPrice(book.getPrice());
book1.setCover(fileName);
book1.setDescription(book.getDescription());
book1.setCid(book.getCid());
return book1;
}
}
②CategoryServiceImpl
③UserServiceImpl
④BookService
⑤CategoryService
⑥UserService
- pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zzd</groupId>
<artifactId>bookmanagersystem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bookmanagersystem</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 热部署工具-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- 简化开发-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 导入mybatis——plus 是自己开放的,不是官方的-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<!--mybatis代码生成器-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.2.0</version>
</dependency>
<!-- 代码生成里面需要模板,so加上了freemarker-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!--集成swagger2,生成接口文档并调试-->
<!-- 引入swagger-bootstrap-ui包 /doc.html-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
以上为项目的基本介绍和部分代码
6.运行截图
- 接口文档页面:
图6.1接口文档页面
- 登录界面
(1)普通用户登录界面
图6.2 普通用户登录界面
- 管理员登录界面(i18n)
图6.3 管理员登录界面(zh)
图6.4 管理员登录界面(en)
- 注册页面
图6.5注册界面
- 用户前台主界面
图6.6 用户前台主界面
- 查询分类界面(如编程)
图6.7查询分类界面
- 后台管理主界面
图6.8后台管理主界面
- 书籍管理主界面
图6.9查询书籍
图6.10增加书籍
图6.11 修改书籍
- 书籍类型管理主界面
图6.12查询书籍类型
图6.13增加书籍类型
图6.14修改书籍类型
- 用户管理主界面
图6.17修改用户 | ||||
6.实验结论及心得 这次实验花了我5天时间完成,在这期间我学到了好多东西,在通宵熬夜的时候,感觉只要做出来一切都是值得的。我使用到了Swagger接口文档进行开发,使用Github进行协同开发,使用SpringBoot+BootStrapUI进行开发,数据库使用云端数据库进行搭建并开发,使用nginx进行反向代理(本项目域名为www.nucsell.com:8080),本项目曾使用docker部署到阿里云服务器上,基本使用Restful风格的接口,符合阿里巴巴开发规范 |