作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
管理员角色包含以下功能:
管理员登录,发布公告,修改资料,查看新帖,查看精华帖请求,封锁用户,创建讨论区等功能。
用户角色包含以下功能:
按分类查看,用户登录,查看帖子详情,查看我的帖子,提交帖子,资料修改,查看申请记录等功能。
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
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.数据库:MySql 5.7版本;
技术栈
1. 后端:mysql+Spring+hibernate+spring mcv
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
运行截图
相关代码
管理端控制器
@Controller("adviceAction")
@Scope("prototype")
public class AdviceAction extends ActionSupport implements ModelDriven<Advice>{
private Advice advice;
@Autowired
private AdviceService adviceService;
@Override
public Advice getModel() {
if(advice==null) advice = new Advice();
return advice;
}
public String advice(){
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//鏌ヨ鎵�湁鎰忚
Pager<Advice> pagers=adviceService.findAll();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}else{
return "login";
}
}
public String yijian(){
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int userId = Integer.parseInt( session.getAttribute("userId").toString());
adviceService.saveAdvice(userId,advice);
ActionContext.getContext().put("url", "/advice_advice.do");
return "redirect";
}else{
return "login";
}
}
public String adviceList(){
Pager<Advice> pagers=adviceService.findAll();
ActionContext.getContext().put("pagers", pagers);
return SUCCESS;
}
//设置取消是否在首页显示
public String fzsy(){
adviceService.updatefzsy(advice);
ActionContext.getContext().put("url", "/advice_adviceList.do");
return "redirect";
}
public String del(){
adviceService.del(advice);
ActionContext.getContext().put("url", "/advice_adviceList.do");
return "redirect";
}
}
登录管理控制器
@Controller("loginAction")
@Scope("prototype")
public class LoginAction {
//首页
public String index() {
return "success";
}
//登陆页面
public String login() {
return "success";
}
//注册页面
public String register() {
return "success";
}
//退出
public String tuichu() {
ActionContext ac = ActionContext.getContext();
Map session = ac.getSession();
session.remove("userName");
session.remove("userId");
return "login";
}
}
用户管理控制器
@Controller("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport implements ModelDriven<User>{
@Autowired
private UserService userService;
@Autowired
private SayMoodService sayMoodService;
@Autowired
private FriendService friendService;
private int otherId;
public int getOtherId() {
return otherId;
}
public void setOtherId(int otherId) {
this.otherId = otherId;
}
private int groupId;
private int friendId;
public int getFriendId() {
return friendId;
}
public void setFriendId(int friendId) {
this.friendId = friendId;
}
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
private static final long serialVersionUID = 1L;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public SayMoodService getSayMoodService() {
return sayMoodService;
}
public void setSayMoodService(SayMoodService sayMoodService) {
this.sayMoodService = sayMoodService;
}
public FriendService getFriendService() {
return friendService;
}
public void setFriendService(FriendService friendService) {
this.friendService = friendService;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
private User user;
//========================图片上传
private File file;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
//========================图片上传
@Override
public User getModel() {
if(user==null) user = new User();
return user;
}
//注册
public String register(){
System.out.println(user.getAddress());
user.setIsDelete(2);
user.setCreateTime(new Date());
user.setJifen(0);
userService.add(user);
return "login";
}
//登陆
public String login(){
User u =userService.load(user);
if(u == null){
return "register";
}else{
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("userName", u.getUserName());
session.setAttribute("userId", u.getId());
return "index";
}
}
public String list() throws IllegalAccessException, InvocationTargetException {
User tu = (User)ActionContext.getContext().getSession().get("loginUser");
ActionContext.getContext().put("list", userService.listAllCanSendUser(1));
return SUCCESS;
}
public String add() {
userService.add(user);
return "success";
}
/**
* 个人主页
* @return
*/
public String homePage() {
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//个人主页需要查询一下信息
//1.相册信息
// 1)url
Pager<SayMood> sayMoods = sayMoodService.loadPhoto(userId);
ActionContext.getContext().put("sayMoods", sayMoods);
//2.好友 查询这个用户所有的好友
List<Friend> friends = friendService.loadFriends(userId);
//对好友进行分组
List<Friend> f1 = new ArrayList<Friend>();
List<Friend> f2 = new ArrayList<Friend>();
List<Friend> f3 = new ArrayList<Friend>();
List<Friend> f4 = new ArrayList<Friend>();
for(Friend fr : friends){
if(fr.getUser().getId() == userId){
fr.setName(fr.getFriendUser().getUserName());
}
if(fr.getFriendUser().getId() == userId){
fr.setName(fr.getUser().getUserName());
}
//家人,同学,朋友,陌生人
if(fr.getGroups() == 1){
f1.add(fr);
}
if(fr.getGroups() == 2){
f2.add(fr);
}
if(fr.getGroups() == 3){
f3.add(fr);
}
if(fr.getGroups() == 4){
f4.add(fr);
}
}
ActionContext.getContext().put("f1", f1);
ActionContext.getContext().put("f2", f2);
ActionContext.getContext().put("f3", f3);
ActionContext.getContext().put("f4", f4);
//3好友推荐 查询兴趣 年龄 地址一样的
List<User> friendtus = friendService.loadTuiJian(userId);
User u = userService.loadUserById(userId);
ActionContext.getContext().put("js", u);
ActionContext.getContext().put("tjs", friendtus);
return SUCCESS;
}else{
return "login";
}
}
/**
* 别人的主页
* @return
*/
public String otherHomePage() {
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int userId = Integer.parseInt( session.getAttribute("userId").toString());
//个人主页需要查询一下信息
//1.相册信息
// 1)url
/*
* otherId代表是从好友表的主键id
* 现在为了查询好友的id需要
*/
Friend frd =friendService.loadByid(otherId);
int relId = 0;
if(frd.getUser().getId() == userId){
relId = frd.getFriendUser().getId();
}else{
relId = frd.getUser().getId();
}
Pager<SayMood> sayMoods = sayMoodService.loadPhoto(relId);
ActionContext.getContext().put("sayMoods", sayMoods);
//2.好友 查询这个用户所有的好友
List<Friend> friends = friendService.loadFriends(relId);
//对好友进行分组
List<Friend> f1 = new ArrayList<Friend>();
List<Friend> f2 = new ArrayList<Friend>();
List<Friend> f3 = new ArrayList<Friend>();
List<Friend> f4 = new ArrayList<Friend>();
for(Friend fr : friends){
if(fr.getUser().getId() == userId){
fr.setName(fr.getFriendUser().getUserName());
}
if(fr.getFriendUser().getId() == userId){
fr.setName(fr.getUser().getUserName());
}
//家人,同学,朋友,陌生人
if(fr.getGroups() == 1){
f1.add(fr);
}
if(fr.getGroups() == 2){
f2.add(fr);
}
if(fr.getGroups() == 3){
f3.add(fr);
}
if(fr.getGroups() == 4){
f4.add(fr);
}
}
ActionContext.getContext().put("f1", f1);
ActionContext.getContext().put("f2", f2);
ActionContext.getContext().put("f3", f3);
ActionContext.getContext().put("f4", f4);
//3好友推荐 查询兴趣 年龄 地址一样的
// List<User> friendtus = friendService.loadTuiJian(otherId);
User u = userService.loadUserById(relId);
ActionContext.getContext().put("js", u);
ActionContext.getContext().put("tjs", null);
return "otherHomePage";
}else{
return "login";
}
}
/**
* 图片上传
* @return
* @throws Exception
*/
public String fileUpload() throws Exception{
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int userId = Integer.parseInt( session.getAttribute("userId").toString());
String root = ServletActionContext.getServletContext().getRealPath("/")+"upload";
//String root = ServletActionContext.getServletContext().getRealPath("upload");
//String root = ServletActionContext.getRequest().getContextPath()+"/"+"upload";
InputStream is = new FileInputStream(file);
fileFileName = UUIDUtils.create()+fileFileName;
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
//接下来存到说说表中
SayMood sayMood = new SayMood();
sayMood.setContent("\\upload\\"+fileFileName);
sayMood.setCreateTime(new Date());
sayMood.setDzs(0);
sayMood.setIsDelete(2);
sayMood.setType(2);
User u = userService.getUser(userId);
sayMood.setSayUser(u);
sayMoodService.save(sayMood);
/**
* 积分规则还没有做。上传图片需要加积分
*/
//上传完毕,跳转列表action
ActionContext.getContext().put("url", "/user_homePage.do");
return "redirect";
}else{
return "login";
}
}
//================================================
//以下是好友管理模块
//================================================
/**
* 查询好友
* @return
*/
public String findFriend(){
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int myId = Integer.parseInt( session.getAttribute("userId").toString());
List<User> users= userService.findFriend(user.getUserName(),myId);
ActionContext.getContext().put("findName", user.getUserName());
ActionContext.getContext().put("findFriends", users);
ActionContext.getContext().put("url", "user_homePage");
}
return "chain";
}
/**
* 添加
* @return
*/
public String addFriend(){
//需要两个id 一个是自己的,一个是传来的
HttpSession session = ServletActionContext.getRequest().getSession();
if(session.getAttribute("userId") != null){
int myId = Integer.parseInt( session.getAttribute("userId").toString());
// HttpServletRequest request = ServletActionContext.getRequest();
//int groupId= Integer.parseInt(request.getParameter("groupId").toString());
friendService.addFriend(myId,user.getId(),groupId);
}
ActionContext.getContext().put("url", "user_homePage");
return "chain";
}
/**
* 删除好友
* @return
*/
public String deleteFriend(){
friendService.deleteFriend(friendId);
ActionContext.getContext().put("url", "/user_homePage.do");
return "redirect";
}
}
如果也想学习本系统,下面领取。关注并回复:104ssh