基于javaweb+mysql的ssm+maven小区失物招领系统(java+ssm+jsp+layui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven小区失物招领系统(java+ssm+jsp+layui+mysql)
项目介绍
基于SSM的小区失物招领
角色:管理员、物业、失主
小区失物招领网站的主要使用者分为管理员;个人中心、业主管理、失主管理、物品类型管理、失物展示管理、失物认领管理、在线投诉管理、论坛交流、系统管理,
业主;个人中心、失物展示管理、失物认领管理、在线投诉管理、我的收藏管理,前台首页;首页、失物展示、论坛信息、新闻资讯、我的、跳转到后台、客服,
失主;个人中心、失物认领管理、我的收藏管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后端:SSM(Spring+SpringMVC+Mybatis)
前端:JSP+CSS+JS+JQUERY+Layui
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
-
将项目中db.xml配置文件中的数据库配置改为自己的配置,然后运行;
/**
* 失物展示
* 后端接口
* @email
*/
@RestController
@RequestMapping("/shiwuzhanshi")
public class ShiwuzhanshiController {
@Autowired
private ShiwuzhanshiService shiwuzhanshiService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ShiwuzhanshiEntity shiwuzhanshi, HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yezhu")) {
shiwuzhanshi.setZhanghao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<ShiwuzhanshiEntity> ew = new EntityWrapper<ShiwuzhanshiEntity>();
PageUtils page = shiwuzhanshiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shiwuzhanshi), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
/**
* 登录相关
*/
@RequestMapping("config")
@RestController
public class ConfigController{
@Autowired
private ConfigService configService;
/**
* 列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ConfigEntity config){
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
PageUtils page = configService.queryPage(params);
return R.ok().put("data", page);
}
/**
* 列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ConfigEntity config){
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
PageUtils page = configService.queryPage(params);
return R.ok().put("data", page);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id){
if(user==null || !user.getMima().equals(password)) {
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(), username,"shizhu", "失主" );
return R.ok().put("token", token);
}
/**
* 注册
*/
@IgnoreAuth
@RequestMapping("/register")
public R register(@RequestBody ShizhuEntity shizhu){
//ValidatorUtils.validateEntity(shizhu);
ShizhuEntity user = shizhuService.selectOne(new EntityWrapper<ShizhuEntity>().eq("shizhuhao", shizhu.getShizhuhao()));
if(user!=null) {
return R.error("注册用户已存在");
}
Long uId = new Date().getTime();
shizhu.setId(uId);
shizhuService.insert(shizhu);
return R.ok();
}
/**
* 退出
*/
@RequestMapping("/logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
ShizhuEntity user = shizhuService.selectById(id);
return R.ok().put("data", user);
}
/**
* 密码重置
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody ShizhuEntity shizhu, HttpServletRequest request){
shizhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shizhu);
ShizhuEntity user = shizhuService.selectOne(new EntityWrapper<ShizhuEntity>().eq("shizhuhao", shizhu.getShizhuhao()));
if(user!=null) {
return R.error("用户已存在");
}
shizhu.setId(new Date().getTime());
shizhuService.insert(shizhu);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody ShizhuEntity shizhu, HttpServletRequest request){
//ValidatorUtils.validateEntity(shizhu);
shizhuService.updateById(shizhu);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
shizhuService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
wrapper.le(columnName, map.get("remindend"));
}
int count = newsService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
/**
* 登录相关
*/
@RequestMapping("users")
@RestController
}
}
/**
* 权限(Token)验证
*/
@Component
public class AuthorizationInterceptor implements HandlerInterceptor {
public static final String LOGIN_TOKEN_KEY = "Token";
@Autowired
private TokenService tokenService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//支持跨域请求
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with,request-source,Token, Origin,imgType, Content-Type, cache-control,postman-token,Cookie, Accept,authorization");
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
IgnoreAuth annotation;
if (handler instanceof HandlerMethod) {
annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
} else {
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
ShizhuEntity user = shizhuService.selectById(id);
return R.ok().put("data", user);
}
/**
* 密码重置
*/
@IgnoreAuth
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
ShizhuEntity user = shizhuService.selectOne(new EntityWrapper<ShizhuEntity>().eq("shizhuhao", username));
if(user==null) {
return R.error("账号不存在");
}
user.setMima("123456");
shizhuService.updateById(user);
return R.ok("密码已重置为:123456");
}
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ShizhuEntity shizhu, HttpServletRequest request){
EntityWrapper<ShizhuEntity> ew = new EntityWrapper<ShizhuEntity>();
PageUtils page = shizhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shizhu), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ShizhuEntity shizhu, HttpServletRequest request){
EntityWrapper<ShizhuEntity> ew = new EntityWrapper<ShizhuEntity>();
PageUtils page = shizhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shizhu), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 列表
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody ConfigEntity config){
// ValidatorUtils.validateEntity(config);
configService.updateById(config);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
configService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
}
/**
* 权限(Token)验证
*/
@Component
public class AuthorizationInterceptor implements HandlerInterceptor {
public static final String LOGIN_TOKEN_KEY = "Token";
@Autowired
private TokenService tokenService;
/**
* 在线投诉
* 后端接口
* @email
*/
@RestController
@RequestMapping("/zaixiantousu")
public class ZaixiantousuController {
@Autowired
private ZaixiantousuService zaixiantousuService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ZaixiantousuEntity zaixiantousu, HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yezhu")) {
zaixiantousu.setZhanghao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<ZaixiantousuEntity> ew = new EntityWrapper<ZaixiantousuEntity>();
PageUtils page = zaixiantousuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zaixiantousu), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ZaixiantousuEntity zaixiantousu, HttpServletRequest request){
EntityWrapper<ZaixiantousuEntity> ew = new EntityWrapper<ZaixiantousuEntity>();
PageUtils page = zaixiantousuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, zaixiantousu), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ZaixiantousuEntity> wrapper = new EntityWrapper<ZaixiantousuEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yezhu")) {
wrapper.eq("zhanghao", (String)request.getSession().getAttribute("username"));
}
int count = zaixiantousuService.selectCount(wrapper);
return R.ok().put("count", count);
}
shizhu.setId(new Date().getTime());
shizhuService.insert(shizhu);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody ShizhuEntity shizhu, HttpServletRequest request){
shizhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shizhu);
ShizhuEntity user = shizhuService.selectOne(new EntityWrapper<ShizhuEntity>().eq("shizhuhao", shizhu.getShizhuhao()));
if(user!=null) {
return R.error("用户已存在");
}
shizhu.setId(new Date().getTime());
shizhuService.insert(shizhu);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody ShizhuEntity shizhu, HttpServletRequest request){
//ValidatorUtils.validateEntity(shizhu);
shizhuService.updateById(shizhu);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
shizhuService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
@RequestMapping("/query")
public R query(ShiwuzhanshiEntity shiwuzhanshi){
EntityWrapper< ShiwuzhanshiEntity> ew = new EntityWrapper< ShiwuzhanshiEntity>();
ew.allEq(MPUtil.allEQMapPre( shiwuzhanshi, "shiwuzhanshi"));
ShiwuzhanshiView shiwuzhanshiView = shiwuzhanshiService.selectView(ew);
return R.ok("查询失物展示成功").put("data", shiwuzhanshiView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ShiwuzhanshiEntity shiwuzhanshi = shiwuzhanshiService.selectById(id);
shiwuzhanshi.setClicknum(shiwuzhanshi.getClicknum()+1);
shiwuzhanshi.setClicktime(new Date());
shiwuzhanshiService.updateById(shiwuzhanshi);
return R.ok().put("data", shiwuzhanshi);
}
/**
* 前端详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ShiwuzhanshiEntity shiwuzhanshi = shiwuzhanshiService.selectById(id);
shiwuzhanshi.setClicknum(shiwuzhanshi.getClicknum()+1);
shiwuzhanshi.setClicktime(new Date());
shiwuzhanshiService.updateById(shiwuzhanshi);
return R.ok().put("data", shiwuzhanshi);
}
/**
* 赞或踩
*/
@RequestMapping("/thumbsup/{id}")
public R vote(@PathVariable("id") String id,String type){
ShiwuzhanshiEntity shiwuzhanshi = shiwuzhanshiService.selectById(id);
if(type.equals("1")) {
shiwuzhanshi.setThumbsupnum(shiwuzhanshi.getThumbsupnum()+1);
} else {
shiwuzhanshi.setCrazilynum(shiwuzhanshi.getCrazilynum()+1);
}
shiwuzhanshiService.updateById(shiwuzhanshi);
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
shiwuzhanshiService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ShiwuzhanshiEntity> wrapper = new EntityWrapper<ShiwuzhanshiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yezhu")) {
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
if(user==null) {
return R.error("账号不存在");
}
user.setPassword("123456");
userService.update(user,null);
return R.ok("密码已重置为:123456");
}
/**
* 列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,UserEntity user){
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/list")
public R list( UserEntity user){
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
ew.allEq(MPUtil.allEQMapPre( user, "user"));
return R.ok().put("data", userService.selectListView(ew));
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id){
UserEntity user = userService.selectById(id);
return R.ok().put("data", user);
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
UserEntity user = userService.selectById(id);
return R.ok().put("data", user);
}
/**
* 保存
*/
@PostMapping("/save")
public R save(@RequestBody UserEntity user){
// ValidatorUtils.validateEntity(user);
/**
* 失物认领
* 后端接口
* @email
*/
@RestController
@RequestMapping("/shiwurenling")
public class ShiwurenlingController {
@Autowired
private ShiwurenlingService shiwurenlingService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ShiwurenlingEntity shiwurenling, HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yezhu")) {
shiwurenling.setZhanghao((String)request.getSession().getAttribute("username"));
}
if(tableName.equals("shizhu")) {
shiwurenling.setShizhuhao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<ShiwurenlingEntity> ew = new EntityWrapper<ShiwurenlingEntity>();
PageUtils page = shiwurenlingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shiwurenling), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ShiwurenlingEntity shiwurenling, HttpServletRequest request){
EntityWrapper<ShiwurenlingEntity> ew = new EntityWrapper<ShiwurenlingEntity>();
PageUtils page = shiwurenlingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shiwurenling), params), params));
request.setAttribute("data", page);
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( ShiwurenlingEntity shiwurenling){
EntityWrapper<ShiwurenlingEntity> ew = new EntityWrapper<ShiwurenlingEntity>();
/**
* 失主
* 后端接口
* @email
*/
@RestController
@RequestMapping("/shizhu")
public class ShizhuController {
}
/**
* 上传文件映射表
*/
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked", "rawtypes", "unchecked", "rawtypes"})
public class FileController{
@Autowired
private ConfigService configService;
//改成自己电脑项目的路径
private String uploadPath="C:\\Users\\Administrator\\Desktop\\SSM的小区失物招领网站\\project\\src\\main\\webapp\\upload\\";
/**
* 上传文件
*/
@RequestMapping("/upload")
public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception {