基于ssm影视论坛系统java web jsp电影评价影评系统源码和文档

开发环境:

  1. jdk 8
  2. intellij idea
  3. tomcat 8.5.40
  4. mysql 5.7

所用技术:

  1. Spring+SpringMVC+MyBatis
  2. layui
  3. jsp

演示视频:

基于ssm影视论坛系统java web jsp电影评价影评系统源码和文档

 

maven项目pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>CommonWeb</groupId>
    <artifactId>CommonWeb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <spring.version>4.3.6.RELEASE</spring.version>
        <mysql.version>8.0.12</mysql.version>
        <druid.version>1.0.9</druid.version>
        <log4j.version>1.2.17</log4j.version>
        <mybatis.version>3.2.7</mybatis.version>
        <shiro.version>1.2.3</shiro.version>
        <jstl.version>1.2</jstl.version>
        <kaptcha.version>2.3.2</kaptcha.version>
    </properties>
    <dependencies>


        <!--java爬虫 \\-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient-cache</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.10.3</version>
        </dependency>
        <!--java爬虫 //-->


        <!-- poi操作excel -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.8</version>
        </dependency>


        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--Spring aop -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!--org.aspectj -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.10</version>
        </dependency>
        <!-- 事务 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Spring test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- 数据库驱动 mysql driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>
        <!-- kaptcha -->
        <dependency>
            <groupId>com.github.penggle</groupId>
            <artifactId>kaptcha</artifactId>
            <version>${kaptcha.version}</version>
        </dependency>
        <!-- 日志 -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>
        <!-- 二维码 -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.2.1</version>
        </dependency>
        <!-- 二维码 -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>3.2.1</version>
        </dependency>
        <!-- java mail -->
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.4.4</version>
        </dependency>
        <!-- shiro -->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>${shiro.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-ehcache</artifactId>
            <version>${shiro.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-web</artifactId>
            <version>${shiro.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>${shiro.version}</version>
        </dependency>
        <!-- 添加jtl支持 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <!-- 添加Servlet支持 -->
        <!-- <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!-- tools -->
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <!-- file upload tools -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.7.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.7.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.7.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- redis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.8.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
    </dependencies>
    <build>
        <finalName>CommonWeb</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
</project>

 

 

 

package com.module.controller.pc;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.module.controller.base.BaseController;
import com.module.mapper.*;
import com.module.pojo.*;
import com.module.util.ResultUtil;
import com.module.util.TreeList;
import org.apache.commons.lang.StringUtils;
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.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前端控制器
 */
@Controller
public class FrontController extends BaseController {

    @Autowired
    InformMapper informMapper;
    @Autowired
    UserinfoMapper userinfoMapper;
    @Autowired
    WenjuanMapper wenjuanMapper;
    @Autowired
    WenjuanjieguoMapper wenjuanjieguoMapper;
    @Autowired
    SorttypeMapper sorttypeMapper;
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    LinkurlMapper linkurlMapper;
    @Autowired
    LiuyanMapper liuyanMapper;
    @Autowired
    FastLiuyanMapper fastLiuyanMapper;
    /**
     * 评论显示页面
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/liuyan")
    public String liuyan(Model model) {
        Page<Object> pageInfo = PageHelper.startPage(1, 100, true);
        pageInfo.setOrderBy(" id desc ");
        List<Liuyan> liuyanList = liuyanMapper.selectAll(null);
        TreeList tree = new TreeList(liuyanList);
        List<Liuyan> listTree = tree.buildTree();
        model.addAttribute("liuyanList", listTree);
        return "pc/liuyan";
    }

    /**
     * 评论提交页面
     *
     * @param liuyan
     * @return
     */
    @RequestMapping("pc/liuyanSubmit")
    public String liuyanSubmit(Liuyan liuyan) {
        liuyan.setCreatetime(new Date());
        liuyanMapper.insertLiuyan(liuyan);
        if (null == liuyan.getIntro()) {
            return "redirect:liuyan";
        } else {
            return "redirect:articleDetail?id=" + liuyan.getIntro();
        }
    }

    /**
     * 跳转到问卷管理页面
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/wenjuan")
    public String wenjuan(Model model) {
        List<Wenjuan> wenjuanList = wenjuanMapper.selectAll(null);
        model.addAttribute("wenjuanList", wenjuanList);
        return "pc/wenjuan";
    }


    /**
     * 关于我们
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/about")
    public String about(Model model) {
        return "pc/about";
    }


    @RequestMapping("pc/")
    public String index(Model model) {
        return "pc/index";
    }



    @RequestMapping("/")
    public String index1(Model model) {
        return "pc/index";
    }






    @RequestMapping("pc/articleList")
    public String indexType(Model model, Integer p, Integer limit, String keyword, String name, String orderStr, String type, HttpSession session) {
        limit = 6;
        if (null == p) { //默认第一页
            p = 1;
        }
        if (null == limit) { //默认每页10条
            limit = 9;
        }
        Map map = new HashMap();
        if (StringUtils.isNotEmpty(type)) {
            map.put("type", type);
            model.addAttribute("type", type);
        }
        if (StringUtils.isNotEmpty(keyword)) {
            map.put("keyword", keyword);
            map.put("type", null);
            model.addAttribute("keyword", keyword);
        }
        Page<Object> pageInfo = PageHelper.startPage(p, limit, true);
        pageInfo.setOrderBy(" id desc ");
        List<Article> beanDataList = articleMapper.selectAll(map);
        model.addAttribute("beanDataList", beanDataList);
        setPageParams(model, "pc/articleList", pageInfo); //绑定分页参数
        return "pc/articleList";
    }

    /**
     * 系统首页
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/index")
    public String index(Model model, Integer p, Integer limit, String keyword, String title, String author, String orderStr, String type, HttpSession session) {

        limit = 6;
        if (null == p) { //默认第一页
            p = 1;
        }
        if (null == limit) { //默认每页10条
            limit = 9;
        }
        Map map = new HashMap();
        if (StringUtils.isNotEmpty(keyword)) {
            map.put("keyword", keyword);
            model.addAttribute("keyword", keyword);
        }
        if (StringUtils.isNotEmpty(title)) {
            map.put("title", title);
            model.addAttribute("title", title);
        }
        if (StringUtils.isNotEmpty(author)) {
            map.put("author", author);
            model.addAttribute("author", author);
        }
        if (StringUtils.isNotEmpty(type)) {
            map.put("type", type);
            model.addAttribute("type", type);
        }
        Page<Object> pageInfo = PageHelper.startPage(p, limit, true);
        if (StringUtils.isNotEmpty(orderStr)) {
            pageInfo.setOrderBy(orderStr);
        } else {
            pageInfo.setOrderBy(" id desc ");
        }
        List<Article> beanDataList = articleMapper.selectAll(map);
        model.addAttribute("beanDataList", beanDataList);
        setPageParams(model, "pc/index", pageInfo); //绑定分页参数
        List<Sorttype> sorttypeList = sorttypeMapper.selectAll(null);
        model.addAttribute("sorttypeList", sorttypeList);
        setLinkurlContent(session); //查询友情链接
        return "pc/index";
    }


    /**
     * 系统首页
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/main")
    public String main(Model model, Integer p, Integer limit, String keyword, String title, String author, String orderStr, String type, HttpSession session) {

        limit = 6;
        if (null == p) { //默认第一页
            p = 1;
        }
        if (null == limit) { //默认每页10条
            limit = 9;
        }
        Map map = new HashMap();
        if (StringUtils.isNotEmpty(keyword)) {
            map.put("keyword", keyword);
            model.addAttribute("keyword", keyword);
        }
        if (StringUtils.isNotEmpty(title)) {
            map.put("title", title);
            model.addAttribute("title", title);
        }
        if (StringUtils.isNotEmpty(author)) {
            map.put("author", author);
            model.addAttribute("author", author);
        }
        if (StringUtils.isNotEmpty(type)) {
            map.put("type", type);
            model.addAttribute("type", type);
        }
        Page<Object> pageInfo = PageHelper.startPage(p, limit, true);
        if (StringUtils.isNotEmpty(orderStr)) {
            pageInfo.setOrderBy(orderStr);
        } else {
            pageInfo.setOrderBy(" id desc ");
        }
        List<Article> beanDataList = articleMapper.selectAll(map);
        model.addAttribute("beanDataList", beanDataList);
        setPageParams(model, "pc/main", pageInfo); //绑定分页参数
        List<Sorttype> sorttypeList = sorttypeMapper.selectAll(null);
        model.addAttribute("sorttypeList", sorttypeList);
        setLinkurlContent(session); //查询友情链接
        return "pc/main";
    }



    @RequestMapping("pc/articleIndex")
    public String articleIndex(Model model, Integer p, Integer limit, String keyword, String title, String author, String orderStr, String type, HttpSession session) {
        limit = 6;
        if (null == p) { //默认第一页
            p = 1;
        }
        if (null == limit) { //默认每页10条
            limit = 9;
        }
        Map map = new HashMap();
        if (StringUtils.isNotEmpty(keyword)) {
            map.put("keyword", keyword);
            model.addAttribute("keyword", keyword);
        }
        if (StringUtils.isNotEmpty(title)) {
            map.put("title", title);
            model.addAttribute("title", title);
        }
        if (StringUtils.isNotEmpty(author)) {
            map.put("author", author);
            model.addAttribute("author", author);
        }
        if (StringUtils.isNotEmpty(type)) {
            map.put("type", type);
            model.addAttribute("type", type);
        }
        Page<Object> pageInfo = PageHelper.startPage(p, limit, true);
        if (StringUtils.isNotEmpty(orderStr)) {
            pageInfo.setOrderBy(orderStr);
        } else {
            pageInfo.setOrderBy(" id desc ");
        }
        List<Article> beanDataList = articleMapper.selectAll(map);
        model.addAttribute("beanDataList", beanDataList);

        setPageParams(model, "pc/index", pageInfo); //绑定分页参数
        List<Sorttype> sorttypeList = sorttypeMapper.selectAll(null);
        model.addAttribute("sorttypeList", sorttypeList);
        setLinkurlContent(session); //查询友情链接
        return "pc/articleIndex";
    }

    /**
     * 将友情链接放入session中
     *
     * @param session
     */
    public void setLinkurlContent(HttpSession session) {
        List<Linkurl> linkurlList = linkurlMapper.selectAll(null);
        session.setAttribute("linkurlList", linkurlList);
    }

    /**
     * 帖子详情
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("pc/articleDetail")
    public String articleDetail(Integer id, Model model,Integer type) {
        Article beanData = articleMapper.selectArticleById(id);
        model.addAttribute("beanData", beanData);
        List<Wenjuan> wenjuanList = wenjuanMapper.selectAll(null);
        model.addAttribute("wenjuanList", wenjuanList);

        Page<Object> pageInfo = PageHelper.startPage(1, 1000, true);
        pageInfo.setOrderBy(" id desc ");
        Map map = new HashMap();
        map.put("artid", id);
        List<FastLiuyan> liuyanList = fastLiuyanMapper.selectAll(map);
        model.addAttribute("liuyanList", liuyanList);

        Map map1 = new HashMap();
        map1.put("iddd",beanData.getId());
        List<Article> beanDataList = articleMapper.selectAllRAND(map1);

        model.addAttribute("beanDataList", beanDataList);

        //评价回复都算上

        int liuyansize = 0;
        if(liuyanList.size()>0){
            liuyansize+=liuyanList.size();
            for (FastLiuyan fastLiuyan:liuyanList) {
                Map map2 = new HashMap();
                map2.put("artid", fastLiuyan.getId());
                List<Liuyan> liuyans = liuyanMapper.selectAll(map2);
                if(liuyans.size()>0){
                    liuyansize+=liuyans.size();
                    fastLiuyan.setHuifunum(liuyans.size());
                }else{
                    fastLiuyan.setHuifunum(0);
                }

            }
        }

        model.addAttribute("liuyansize", liuyansize);


        if(type!=null){
          if(type==1){
              beanData.setCai(beanData.getCai()+1);
          } else{
              beanData.setZan(beanData.getZan()+1);
          }
        }


         beanData.setHits(beanData.getHits()+1);
        articleMapper.updateArticle(beanData);

        return "pc/articleDetail";
    }

    @RequestMapping("pc/submitWenjuan")
    public String submitWenjuan(Integer id, String username, Model model, HttpServletRequest request) {
        Wenjuanjieguo j = new Wenjuanjieguo();
        j.setA1(request.getParameter("xx1"));
        j.setA2(request.getParameter("xx2"));
        j.setA3(request.getParameter("xx3"));
        j.setA4(request.getParameter("xx4"));
        j.setA5(request.getParameter("xx5"));
        j.setA6(request.getParameter("xx6"));
        j.setA7(request.getParameter("xx7"));
        j.setA8(request.getParameter("xx8"));
        j.setA9(request.getParameter("xx9"));
        j.setA10(request.getParameter("xx10"));
        j.setUsername(username);
        j.setCreatetime(new Date());
        System.out.println("j = " + j);
        List<Wenjuan> wenjuanList = wenjuanMapper.selectAll(null);
        wenjuanjieguoMapper.insertWenjuanjieguo(j);
        return "pc/submitSuccess";
    }


    @RequestMapping("pc/informIndex")
    public String informIndex(Model model, Integer p, Integer limit, String keyword) {
        limit = 10;
        if (null == p) { //默认第一页
            p = 1;
        }
        if (null == limit) { //默认每页10条
            limit = 10;
        }
        Map map = new HashMap();
        if (StringUtils.isNotEmpty(keyword)) {
            map.put("keyword", keyword);
        }
        Page<Object> pageInfo = PageHelper.startPage(p, limit, true);
        List<Inform> beanDataList = informMapper.selectAll(map);
        model.addAttribute("beanDataList", beanDataList);
        setPageParams(model, "pc/informIndex", pageInfo); //绑定分页参数
        return "pc/informIndex";
    }


    /**
     * 获取验证码
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/code")
    public String code(Model model) {
        return "pc/code";
    }

    /**
     * 跳转登陆页
     *
     * @param model
     * @return
     */
    @RequestMapping("pc/login")
    public String login(Model model) {
        return "pc/login";
    }

    /**
     * 退出登录
     *
     * @param request
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("pc/loginOut")
    public String loginOut(HttpServletRequest request, Integer id, Model model) {
        HttpSession session = request.getSession();
        session.removeAttribute("loginUserinfo");
        return "pc/login";
    }

    /**
     * 登录提交
     *
     * @param username
     * @param password
     * @param vercode
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("pc/loginSubmit")
    public ResultUtil loginSubmit(String username, String password, String vercode, HttpServletRequest request) {
        HttpSession session = request.getSession();
        if (StringUtils.isBlank(vercode)) {
            return ResultUtil.error("验证码不能为空");
        }
        String randCode = session.getAttribute("randCode").toString();
        if (!randCode.equals(vercode)) {
            return ResultUtil.error("验证码不正确");
        }
        if (StringUtils.isBlank(username)) {
            return ResultUtil.error("用户名不能为空");
        }
        if (StringUtils.isBlank(password)) {
            return ResultUtil.error("登录密码不能为空");
        }
        Map map = new HashMap();
        map.put("name", username);
        List<Userinfo> beanList = userinfoMapper.selectAll(map);
        if (beanList.size() > 0) {
            Userinfo userinfo = beanList.get(0);
            if (userinfo.getPassword().equals(password)) {
                session.setAttribute("loginUserinfo", userinfo);
                session.setAttribute("loginUserinfoID", userinfo.getId());
                return ResultUtil.ok("登录成功");
            } else {
                return ResultUtil.error("用户名或者密码错误");
            }
        } else {
            return ResultUtil.error("用户名或者密码错误");
        }

    }

    @RequestMapping("pc/register")
    public String reg() {
        return "pc/register";
    }

    @ResponseBody
    @RequestMapping("pc/registerSubmit")
    public ResultUtil regSubmit(HttpServletRequest request, Userinfo userinfo, String vercode) {
        HttpSession session = request.getSession();
        if (StringUtils.isBlank(vercode)) {
            return ResultUtil.error("验证码不能为空");
        }
        String randCode = session.getAttribute("randCode").toString();
        if (!randCode.equals(vercode)) {
            return ResultUtil.error("验证码不正确");
        }
        if (StringUtils.isBlank(userinfo.getName())) {
            return ResultUtil.error("姓名不能为空");
        }
        if (StringUtils.isBlank(userinfo.getPassword())) {
            return ResultUtil.error("登录密码不能为空");
        }
        userinfo.setCreatetime(new Date());
        userinfoMapper.insertUserinfo(userinfo);
        return ResultUtil.ok("注册成功");
    }

    /**
     * 用户个人中心
     *
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("pc/userinfoCenter")
    public String userinfoCenter(Model model, HttpSession session) {
        int userInfoID = getLoginUserInfoID(session);
        Userinfo userinfo = userinfoMapper.selectUserinfoById(userInfoID);
        model.addAttribute("userinfo", userinfo);
        return "pc/userinfoCenter";
    }

    /**
     * 更新个人信息
     */
    @RequestMapping("pc/updateUserinfo")
    @ResponseBody
    public ResultUtil updateUserinfo(Userinfo userinfo, HttpSession session) {
        Date nowTime = new Date();
        userinfo.setCreatetime(nowTime);
        try {
            userinfoMapper.updateUserinfo(userinfo);
            userinfo = getLoginUserInfo(session);
            session.setAttribute("loginUserinfo", userinfo);
            return ResultUtil.ok("修改用户信息成功");
        } catch (Exception e) {
            return ResultUtil.error("修改用户信息出错,稍后再试!");
        }
    }

    /**
     * 获取前端登录用户ID
     *
     * @param session
     * @return
     */
    public int getLoginUserInfoID(HttpSession session) {
        int userID = (int) session.getAttribute("loginUserinfoID");
        return userID;
    }

    public Userinfo getLoginUserInfo(HttpSession session) {
        int userID = (int) session.getAttribute("loginUserinfoID");
        Userinfo userinfo = userinfoMapper.selectUserinfoById(userID);
        return userinfo;
    }
}

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿毕业分享网

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值