古诗词学习网 Java web 项目设计

本文描述了一个基于Java和SpringBoot的古诗词学习网项目设计,包括用户管理、诗歌信息管理、文件上传等功能,以及对应的Controller实现,如用户注册、编辑诗歌和作者、数据查询和退出登录等操作。
摘要由CSDN通过智能技术生成

       传统美文学习是供中学学生学习的网站,因此该网站应能满足中学学生的常规需求,如用户注册,阅读古诗文,查找古诗文、名句、古籍,音频、视频学习古诗文,巩固古诗文学习的游戏,添加、纠正古诗文相关信息,下载古诗文相关信息,根据日常浏览来推送喜欢的古诗文,根据平时阅读文章生成相应题库对读者进行测试,参加古诗文选拔大赛等。对于网站管理者能管理古诗文相关信息和古诗文分类信息,管理用户信息,审核用户添加古诗文信息等。

开发语言:Java

后端框架:springboot

前端框架:freemarker

服务器:tomcat

数据库:mysql

数据库工具:Navicat

开发软件:eclipse/myeclipse/idea

古诗词学习网 Java web 项目设计

package com.gsc.controller;

import com.gsc.entity.Poet;
import com.gsc.entity.Poetry;
import com.gsc.entity.User;
import com.gsc.service.PoetService;
import com.gsc.service.PoetryService;
import com.gsc.tools.Result;
import com.gsc.tools.UploadFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AdminControllerr {

    @Autowired
    private PoetryService poetryService;

    @Autowired
    private PoetService poetService;

    @RequestMapping("/admin")
    public String admin(){
        return "/admin/index";
    }

    @RequestMapping("/toFindPoetryAll")
    public String toFindPoetryAll(){
        return "/admin/findPoetry";
    }

    @RequestMapping("/toFindPoetAll")
    public String toFindPoetAll(){
        return "/admin/findPoet";
    }

    @ResponseBody
    @RequestMapping("/upFile")
    public Object upFile(HttpServletRequest request) {
        Map map = UploadFile.uploadImages(request);
        Map obj = new HashMap();
        obj.put("error", 0);
        obj.put("url", map.get("url") + "");
        System.out.println(obj.toString());
        return obj;
    }

    @RequestMapping("/toEditPoetry")
    public String toEditPoetry(String id, Model model){
        List poets = poetService.findPoetAll();
        if("0".equals(id)){
            Poetry poetry = new Poetry();
            // 设置默认值
            poetry.setPid(0);
            poetry.setCid(0);
            poetry.setAudio(0);
            model.addAttribute("poetry", poetry);
        }else {
            model.addAttribute("poetry", poetryService.findPoetry(id));
        }
        model.addAttribute("poets", poets);
        return "/admin/editPoetry";
    }

    /**
     * 保存诗词
     * @param poetry
     * @return
     */
    @ResponseBody
    @RequestMapping("/savePoetry")
    public Result savePoetry(Poetry poetry){
        int count = 0;
        if(poetry.getId() > 0){
            count = poetryService.editPoetry(poetry);
        }else{
            count = poetryService.addPoetry(poetry);
        }
        if(count > 0){
            return new Result("10000","操作成功");
        }
        return new Result("00000","操作失败,请稍候再试!");
    }

    /**
     * 查询所有古诗词
     * @param poetry
     * @return
     */
    @ResponseBody
    @RequestMapping("/findPoetryAll")
    public Result findPoetryAll(Poetry poetry){
        return poetryService.findPoetryAll(poetry);
    }

    @RequestMapping("/toEditPoet")
    public String toEditPoet(String id, Model model){
        if("0".equals(id)){
            model.addAttribute("poet", new Poet());
        }else {
            model.addAttribute("poet", poetService.findPoet(id));
        }
        return "/admin/editPoet";
    }

    /**
     * 保存作者
     * @param poet
     * @return
     */
    @ResponseBody
    @RequestMapping("/savePoet")
    public Result savePoet(Poet poet, HttpServletRequest request){
        Map map = UploadFile.uploadImages(request);
        poet.setImg(map.get("url")+"");
        int count = 0;
        if(poet.getId() > 0){
            count = poetService.editPoet(poet);
        }else{
            count = poetService.addPoet(poet);
        }
        if(count > 0){
            return new Result("10000","操作成功");
        }
        return new Result("00000","操作失败,请稍候再试!");
    }

    /**
     * 查询所有作者
     * @param poet
     * @return
     */
    @ResponseBody
    @RequestMapping("/findPoetAll")
    public Result findPoetAll(Poet poet){
        return poetService.findPoetAll(poet);
    }

    /**
     * 退出登录
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/logout")
    public String logout(HttpServletRequest request) throws Exception{
        HttpSession session = request.getSession();
        session.removeAttribute("user");
        return "redirect:/index";
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值