杨校老师课堂基于SSM整合之用户登录案例【Eclipse - Maven版】2

简介: 杨校老师课堂基于SSM整合之用户登录案例【Eclipse - Maven版】

杨校老师课堂基于SSM整合之用户登录案例【Eclipse - Maven版】1:https://developer.aliyun.com/article/1543099


5. UserServiceImpl.java

 package cn.javabs.ssm.service.impl;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import cn.javabs.ssm.dao.UserDao;
import cn.javabs.ssm.entity.User;
import cn.javabs.ssm.service.UserService;
 
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
 
  @Autowired
  private UserDao userDao;
 
  public User login(String username, String password) {
    System.out.println(username);
 
    User user = this.userDao.userLogin(username, password);
    System.out.println("df");
    System.out.println("ghj" + user);
 
    return user;
  }
 
}

6. UserController

package cn.javabs.ssm.controller;
 
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
 
import cn.javabs.ssm.entity.User;
import cn.javabs.ssm.service.UserService;
 
@Controller
public class UserController {
 
  @Autowired
  private UserService userService;
 
  @PostMapping("/userLogin.action")
  public String userLogin(HttpSession session, String username, String password, Model model) {
    System.out.println("password = " + password);
    User user = userService.login(username, password);
    System.out.println("user:" + user);
 
    if (user != null) {
      session.setAttribute("USER", user);
      return "user";
    }
    model.addAttribute("msg", "您登陆失败");
    return "message";
  }
}

7.在webapp下创建一个文件夹,命名为admin

分别创建三个网页:login.jsp    message.jsp     user.jsp

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="basePath"  ></c:set>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
  <form action="${basePath}/userLogin.action" method="post">
    Account: <input type="text" name="username" /> <br /> 
    
    Password:<input type="text" name="password" /> <br /> 
    
         <input type="submit"  value="登录">
  </form>
</body>
</html>


message.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>提示页面</title>
</head>
<body>
    ${msg}
</body>
</html>

user.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录成功主页</title>
</head>
<body>
  <h2>${sessionScope.USER.username},您好。</h2>
</body>
</html>

在webapp再建一个jsp,命名为:index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录入口</title>
</head>
<body>
 
  <jsp:forward page="/admin/login.jsp"></jsp:forward>
 
</body>
</html>

右键项目,选择 Run As  ---  选择 Maven Build(从上数第二个)

接下来在Goals的后方输入: tomcat7:run 然后点击 下方的 Run

如图:


代码托管:

目录
相关文章
|
7天前
|
Java Apache Maven
杨校老师课堂之Maven下载与配置阿里云镜像
杨校老师课堂之Maven下载与配置阿里云镜像
42 0
|
7天前
|
Java 应用服务中间件 Maven
杨校老师课堂基于SSM整合之用户登录案例【Eclipse - Maven版】1
杨校老师课堂基于SSM整合之用户登录案例【Eclipse - Maven版】
18 0
|
16天前
|
Java Apache Maven
Maven 项目文档
本教程聚焦于创建Maven项目文档。在C:/MVN目录下,使用命令`mvn archetype:generate -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false`生成java项目。
|
9天前
|
Java Apache Maven
Maven 项目文档
在`C:/MVN/consumerBanking`中创建Maven Java项目,使用命令`mvn archetype:generate`生成基础结构。确保`pom.xml`包含`maven-site-plugin`和`maven-project-info-reports-plugin`,版本至少为3.3和2.7,以避免`NoClassDefFoundError`。运行`mvn site`生成文档。
|
19天前
|
Java Apache Maven
Maven 项目文档
在C:/MVN下,使用`mvn archetype:generate`命令创建`consumerBanking`项目,设置相关参数。为解决`mvn site`运行时的NoClassDefFoundError,需在`pom.xml`中添加或更新maven-site-plugin和maven-project-info-reports-plugin至版本3.3和2.7以上。
|
15天前
|
Java 编译器 Maven
使用intellij idea搭建SSM架构的maven项目 详细
使用intellij idea搭建SSM架构的maven项目 详细
35 4
|
3天前
|
Java Apache Maven
Maven 项目文档
使用Maven创建`consumerBanking`项目,执行`mvn archetype:generate`命令初始化。确保`pom.xml`包含`maven-site-plugin`至少版本3.3和`maven-project-info-reports-plugin`至少版本2.7,以避免NoClassDefFoundError。升级插件解决文档构建问题。
|
9天前
|
Java Apache Maven
Maven 项目文档
在`C:/MVN/consumerBanking`,使用`mvn archetype:generate`命令创建Java项目后,确保更新`pom.xml`,添加`maven-site-plugin`和`maven-project-info-reports-plugin`,至少版本3.3和2.7。运行`mvn site`时遇到`NoClassDefFoundError`,需升级`maven-site-plugin`至3.3以上以解决。
|
4天前
|
存储 安全 Java
2024ide构建maven项目是总是卡在解析Maven依赖项目 加速方案
2024ide构建maven项目是总是卡在解析Maven依赖项目 加速方案
14 4
2024ide构建maven项目是总是卡在解析Maven依赖项目 加速方案
|
14天前
|
Java Apache Maven
Maven 项目文档
在C:/MVN下,使用`mvn archetype:generate`命令创建`consumerBanking`项目,设置相关参数。确保`pom.xml`包含最新`maven-site-plugin`(至少3.3版本)和`maven-project-info-reports-plugin`(至少2.7版本),以避免`NoClassDefFoundError`。若未配置,执行`mvn site`会出错。