栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

chapter03

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

chapter03

1.UserController.java

package cn.edu.hncj.controller;

import cn.edu.hncj.pojo.User;
import cn.edu.hncj.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    @Autowired
    private IUserService userService;
    @RequestMapping(value = "/userLogin",method = RequestMethod.POST)
    public String userLogin(@Param("username")String username, @Param("password")String password, HttpServletRequest request){
        System.out.println(username+password);
        User userLogin= userService.userLogin(username,password);
        if(userLogin==null){
            request.setAttribute("msg","用户名或密码错误!!");
            return "forward:login.jsp";
        }

        return "redirect:success.jsp";
    }
}

2.IUserMapper

package cn.edu.hncj.dao;

import cn.edu.hncj.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface IUserMapper {
    @Select("select * from user where username = #{username} and password = #{password}")
    public User userLogin(@Param("username") String username, @Param("password") String password);
}

3.User

package cn.edu.hncj.pojo;

public class User {
    private int id;
    private String username;
    private String password;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

4.IUserService

package cn.edu.hncj.service;

import cn.edu.hncj.pojo.User;

public interface IUserService {
    User userLogin(String username,String password);
}

5.applicationContext.xml



    
    
        
        
        
        
    
    
        
    
    
        
    
    

6.db.properties

db.username=root
db.password=123456
db.url=jdbc:mysql://localhost:3306/chapter01?serverTimezone=UTC
db.driver=com.mysql.cj.jdbc.Driver

7.springmvc-config.xml



    
    
        
    
    
    

8.index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

  
    $Title$
  
  
  $END$
  

9.login.jsp

<%--
  Created by IntelliJ IDEA.
  User: 12282
  Date: 2022/5/24
  Time: 16:42
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% request.getAttribute("msg"); %>


    Title


${msg}
username:
password:

10.success.jsp

<%--
  Created by IntelliJ IDEA.
  User: 12282
  Date: 2022/5/24
  Time: 16:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


登陆成功啦!


11.pom.xml



    4.0.0

    cn.edu.hncj
    exam02
    1.0-SNAPSHOT
    war
    
        8
        8
    
    
        
            org.springframework
            spring-context
            5.3.8
        
        
            org.springframework
            spring-jdbc
            5.3.8
        
        
            org.springframework
            spring-tx
            5.3.8
        
        
            org.springframework
            spring-core
            5.3.8
        
        
            org.springframework
            spring-webmvc
            5.3.8
        
        
            org.mybatis
            mybatis
            3.5.9
        
        
            org.mybatis
            mybatis-spring
            2.0.7
        
        
            mysql
            mysql-connector-java
            8.0.22
        
        
            junit
            junit
            4.12
            compile
        
        
            com.mchange
            c3p0
            0.9.5.5
        
        
            javax.servlet
            javax.servlet-api
            3.1.0
            provided
        
        
            javax.servlet.jsp
            jsp-api
            2.2
            provided
        
        
            jstl
            jstl
            1.2
        
    

12.chapter02.iml



  
    
      
        
          
        
        
          
        
        
          
          
        
      
    
  

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929393.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号