package org.zz.myspringboot.controller;
import com.github.pagehelper.PageInfo;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.zz.myspringboot.entity.User;
import org.zz.myspringboot.service.UserService;
import org.zz.myspringboot.utils.FileUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Zhou Wenzhe
* @date 2018/6/27
*/
//@Controller
@RestController
public class UserController {
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserService userService;
@GetMapping("index")
public ModelAndView findAll(@Valid Integer page,Integer pageSize) {
page = 1;
pageSize = 10;
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
List<User> list1 = userService.findAll(page,pageSize);
modelAndView.addObject("list", list1);
return modelAndView;
}
@PostMapping("/update")
public Map update(@Valid Long id, String username, Integer age, String address) {
userService.update(id, username, age, address);
Map map = new HashMap();
map.put("success", 1);
return map;
}
@PostMapping("/add")
//@ResponseBody
public Map add(@Valid String username, Integer age, String address) {
userService.add(username, age, address);
Map map = new HashMap();
map.put("success", 1);
return map;
}
@GetMapping("/delete")
public ModelAndView delete(@Valid Long id) {
ModelAndView modelAndView = new ModelAndView("redirect:/index");
userService.delete(id);
return modelAndView;
}
@PostMapping("/findUser")
public User update(Integer id) {
User user = userService.findUserById(id);
return user;
}
@RequestMapping("/importFile")
public void importFile(HttpServletResponse response) {
List<User> userList = userService.findAll();
FileUtil.exportExcel(userList, "花名册", "德玛西亚", User.class, "414.xls", response);
}
// 下载pdf文档
@RequestMapping("/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 告诉浏览器用什么软件可以打开此文件
response.setHeader("content-Type", "application/pdf");
// 下载文件的默认名称
response.setHeader("Content-Disposition", "attachment;filename=user.pdf");
Document document = new Document();
PdfWriter.getInstance(document, response.getOutputStream());
document.open();
BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/SIMYOU.TTF",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
List<User> list = userService.findAll();
for (User user : list) {
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell();
cell.setPhrase(new com.itextpdf.text.Paragraph(user.getUsername()));
table.addCell(cell);
document.add(table);
cell = new PdfPCell();
cell.setPhrase(new com.itextpdf.text.Paragraph(user.getAge().toString()));
table.addCell(cell);
document.add(table);
cell = new PdfPCell();
cell.setPhrase(new com.itextpdf.text.Paragraph(user.getAddress()));
table.addCell(cell);
document.add(table);
}
document.close();
}
@PostMapping("index1")
public PageInfo<User> findAll1(@Valid Integer page, Integer pageSize) {
page = 1;
pageSize = 2;
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
List<User> list1 = userService.findAll(page,pageSize);
modelAndView.addObject("list", list1);
return new PageInfo<>(list1);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源介绍】 毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip毕设项目:基于springboot的宿舍人员信息管理系统.zip 【备注】 该项目是个人毕设项目,答辩评审平均分达到95分,代码都经过测试ok后才上传,确保运行!欢迎下载使用,可用于小白学习、进阶。 该资源主要针对计算机、通信、人工智能、自动化等相关专业的学生、老师或从业者下载使用,亦可作为期末课程设计、课程大作业、毕业设计等。 项目整体具有较高的学习借鉴价值!基础能力强的可以在此基础上修改调整,以实现不同的功能。 欢迎下载,欢迎沟通,互相学习,共同进步!提供答疑!
资源推荐
资源详情
资源评论
收起资源包目录
毕设项目:基于springboot的宿舍人员信息管理系统.zip (41个子文件)
java-project
mvnw.cmd 5KB
pom.xml 5KB
src
test
java
org
zz
myspringboot
MyspringbootApplicationTests.java 351B
main
resources
application.properties 1KB
templates
index.html 10KB
success.html 216B
static
js
layui.js 6KB
jquery.pagination.js 11KB
bootstrap-paginator.js 20KB
jquery-1.11.0.min.js 94KB
highlight.min.js 45KB
css
layui.css 59KB
page.css 1KB
bootstrap-3.3.7
dist
js
bootstrap.js 68KB
bootstrap.min.js 36KB
css
bootstrap-theme.min.css.map 25KB
bootstrap.min.css 118KB
bootstrap-theme.css.map 47KB
bootstrap-theme.css 26KB
bootstrap.css.map 380KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
bootstrap.min.css.map 529KB
fonts
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.woff2 18KB
java
org
zz
myspringboot
mapper
UserMapper.java 908B
UserMapper.xml 507B
controller
UserController.java 4KB
utils
FileUtil.java 4KB
MyspringbootApplication.java 335B
service
UserService.java 511B
impl
UserServiceImpl.java 1KB
entity
User.java 2KB
exception
NormalException.java 278B
.mvn
wrapper
maven-wrapper.properties 110B
maven-wrapper.jar 46KB
mvnw 6KB
.gitignore 366B
共 41 条
- 1
资源评论
z同学的编程之路
- 粉丝: 1934
- 资源: 2130
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功