源码获取:博客首页 "资源" 里下载!
技术框架: HTML+CSS+JavaScript+jsp+mysql+Spring+SpringMVC+mybatis+Spring boot
数据库: Mysql数据库
/**
*
*管理员控制层
*/
@Controller
@RequestMapping("/admin")
@Scope("prototype")
public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
private ReturnResult returnResult = new ReturnResult();
@Resource(name = "adminService")
private IAdminService adminService;
/**
* 管理员登录
* @param admin
* @param session
* @return
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
@ResponseBody
public ReturnResult login(TAdmin admin, HttpSession session) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
admin = adminService.login(admin);
if (admin != null) {
admin.setPassword(null);
session.setAttribute("admin", admin);
returnResult.setStatus(ReturnCodeType.SUCCESS);
}
} catch (Exception e) {
logger.error("登录失败:" + e);
}
return returnResult;
}
/**
* 从session获取管理员信息
* @param session
* @return
*/
@RequestMapping(value="getAdminInfo", method = RequestMethod.POST)
@ResponseBody
public ReturnResult getAdminInfo(HttpSession session) {
returnResult.setStatus(ReturnCodeType.FAILURE);
TAdmin admin = (TAdmin) session.getAttribute("admin");
if (admin != null) {
returnResult.setStatus(ReturnCodeType.SUCCESS).setData(admin);
} else {
logger.info("获取管理员信息失败:管理员未登录");
}
return returnResult;
}
/**
* 退出
* @param session
* @return
*/
@RequestMapping(value="logout", method = RequestMethod.POST)
@ResponseBody
public ReturnResult logout(HttpSession session) {
session.invalidate();
return returnResult.setStatus(ReturnCodeType.SUCCESS);
}
}
/**
* 评论控制层
*
*/
@Controller
@Scope("prototype")
public class CommentController {
private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
private ReturnResult returnResult = new ReturnResult();
@Resource(name = "commentService")
private ICommentService commentService;
/**
* 添加评论
*
* @param comment
* @param HttpServletRequest
* @return
*/
@RequestMapping(value = "addComment", method = RequestMethod.POST)
@ResponseBody
public ReturnResult addInfo(TComment comment,HttpSession session) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
TUser user = (TUser) session.getAttribute("user");
comment.setUserid(user.getId());
comment.setCreatetime(new Date());
commentService.insert(comment);
returnResult.setStatus(ReturnCodeType.SUCCESS);
} catch (Exception e) {
logger.error("新增comment失败" + e);
}
return returnResult;
}
/**
* 删除评论
*
* @param comment
* @param HttpServletRequest
* @return
*/
@RequestMapping(value = "deleteComment", method = RequestMethod.POST)
@ResponseBody
public ReturnResult deleteComment(Integer id) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
commentService.deleteByPrimaryKey(id);
returnResult.setStatus(ReturnCodeType.SUCCESS);
} catch (Exception e) {
logger.error("删除comment失败" + e);
}
return returnResult;
}
/**
* 根据摄影师id查询评论
*
* @param comment
* @param HttpServletRequest
* @return
*/
@RequestMapping(value = "getCommentByPid", method = RequestMethod.GET)
@ResponseBody
public ReturnResult getCommentByPid(Integer pid) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
returnResult.setStatus(ReturnCodeType.SUCCESS).setData(commentService.selectBySQL("SELECT a.`comment`,a.createTime,b.`name` FROM t_comment a,t_user b where a.userId=b.id AND a.photographerId="+pid));
} catch (Exception e) {
logger.error("根据摄影师id查询评论" + e);
}
return returnResult;
}
/**
* 分页获取comment
* @return
*/
@RequestMapping(value = "getCommentListByPage", method = RequestMethod.POST)
@ResponseBody
public ReturnResult getCommentListByPage(PageVO page) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
Map resultMap = new HashMap();
StringBuffer sql = new StringBuffer("SELECT DISTINCT * FROM t_comment WHERE 1=1");
List
/**
*
*景点信息控制层
*/
@Controller
@Scope("prototype")
public class SpotsController {
private static final Logger logger = LoggerFactory.getLogger(SpotsController.class);
private ReturnResult returnResult = new ReturnResult();
@Resource(name = "spotsService")
private ISpotsService spotsService;
/**
* 添加拍摄景点
*
* @param spots
* @param HttpServletRequest
* @return
*/
@RequestMapping(value = "addSpots", method = RequestMethod.POST)
@ResponseBody
public ReturnResult addSpots(TSpots spots, HttpServletRequest request) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
Map map = OperationFileUtil.multiFileUpload(request,
request.getServletContext().getRealPath("/") + "uploads\\spots\\");
String filePath = "";
for (Map.Entry entry : map.entrySet()) {
filePath = entry.getValue();
}
filePath = filePath.replace(request.getServletContext().getRealPath("/"), "/");
spots.setPath(filePath);
spots.setCreatetime(new Date());
spotsService.insert(spots);
returnResult.setStatus(ReturnCodeType.SUCCESS);
} catch (Exception e) {
logger.error("新增spots失败" + e);
}
return returnResult;
}
/**
* 修改spots
* @param spots
* @return
*/
@RequestMapping(value = "updateSpots", method = RequestMethod.POST)
@ResponseBody
public ReturnResult updateSpots(TSpots spots) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
spotsService.updateBySQL("UPDATE t_spots SET name='" + spots.getName() + "',content='"+spots.getContent()+"', status="+spots.getStatus()+" WHERE id=" + spots.getId());
returnResult.setStatus(ReturnCodeType.SUCCESS);
} catch (Exception e) {
logger.error("修改spots失败" + e);
}
return returnResult;
}
/**
* 分页获取spots
* @return
*/
@RequestMapping(value = "getSpotsListByPage", method = RequestMethod.POST)
@ResponseBody
public ReturnResult getSpotsListByPage(PageVO page) {
returnResult.setStatus(ReturnCodeType.FAILURE);
try {
Map resultMap = new HashMap();
StringBuffer sql = new StringBuffer("SELECT DISTINCT * FROM t_spots WHERE 1=1");
List
源码获取:博客首页 "资源" 里下载!