• 团队代码


    2021年6月8日:

    主要控制层代码:

    package com.atguigu.crud.controller;

    import org.springframework.beans.factory.annotation.Autowired;


    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;

    import com.atguigu.crud.bean.Club;
    import com.atguigu.crud.bean.User;
    import com.atguigu.crud.service.ClubService;
    import com.atguigu.crud.service.UserService;
    import com.atguigu.crud.utils.ValidateCodeExpiredException;

    import net.sf.json.JSONArray;

    import java.util.List;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpSession;

    @Controller
    public class MainController {

    @Autowired
    UserService userService;
    @Autowired
    ClubService club;

    @RequestMapping(value = { "/register" })
    public String doregister(User user, HttpServletRequest request) {
    // 获取请求的ip地址
    user.setRegister_ip(request.getRemoteAddr());
    request.setAttribute("msg", "注册成功");
    return "forward:/register.jsp";
    }

    @RequestMapping("/login")
    public String dologin(String login_mail, String pwd, Model model, HttpSession session) {
    User user = userService.login(login_mail, pwd);
    if (user == null) {
    model.addAttribute("msg", "用户名或密码错误");
    } else {
    if (user.getStatus() == 0) {
    model.addAttribute("msg", "需激活|" + user.getId());
    } else {
    session.setAttribute("user", user);
    List<Club> list = club.list(user.getId());
    session.setAttribute("clublist", JSONArray.fromObject(list));
    if (user.getNick_name() == null) {
    return "redirect:/user/edit?action=xiu";
    }
    return "forward:/index.jsp";
    }
    }
    return "forward:/login.jsp";
    }

    @GetMapping(value = "/active", produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String active(Long userId, String code) {
    try {
    boolean result = userService.active(userId, code);
    if (result) {
    return "激活成功!";
    } else {
    return "验证码错误,请重新去邮箱确认";
    }
    } catch (ValidateCodeExpiredException e) {
    return e.getMessage();
    }
    }

    @GetMapping("/logout.html")
    public String logout(HttpSession session) {
    session.invalidate();
    return "redirect:/login.jsp";
    }

    @GetMapping("/index")
    public String logout1(String club, String user) {
    return "forward:/index.jsp?clubname=" + club + "&user=" + user;
    }
    }

  • 相关阅读:
    Wrong codepoints for non-ASCII characters inserted in UTF-8 database using CLP
    SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220
    XSD 数据类型
    Can't read [proguard.ClassPathEntry@1a0c10f] (No such file or directory)
    ubuntu 创建swap分区
    tar分层压缩
    MTK 自定义系统服务
    MTK framework系统默认设置
    MTK 修改默认屏幕亮度
    MTK 隐藏底部状态栏
  • 原文地址:https://www.cnblogs.com/yitiaokuailedexiaojingyu/p/14878058.html
Copyright © 2020-2023  润新知