入门登录

1、index.jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" import="java.util.*"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<form action="${pageContext.request.contextPath}/login">
    <table align="center" border='1' cellspacing='0'>
        <tr>

            <td style="width: 199px;height: 29px" align="center">username</td>
            <td style="width: 199px;height: 29px" align="center">password</td>

        </tr>

        <tr>
            <td>
                <input type="text" name="username" value="请输入值"/>
            </td>
            <td>
                <input type="text" name="password" value="请输入值"/>

            </td>

            <td colspan="2" align="center">
                <input type="submit" value="登录">
            </td>

        </tr>

    </table>

</form>

2、登录代码Cotroller

2.1 cotroller层
import com.mc.pojo.Login;
import com.mc.service.impl.LoginServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("")
public class LoginCotroller {
    @Resource
    LoginServiceImpl loginService;

    @RequestMapping("/login")
    public String toLogin(ModelAndView model, String username, HttpServletRequest request){
        Login login;
        login = loginService.setLogin(username);
        String password = request.getParameter("password").trim();
        System.out.println("password is:"+password);
        System.out.println("mysql password is"+login.getPassword());
        if (password.equals(login.getPassword())){
            System.out.println("mima true");
            return "redirect:user/listUser";
        }

        return "error";
    }
}

2.2 service层

import com.mc.maper.LoginMaper;
import com.mc.pojo.Login;
import com.mc.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("loginService")
public class LoginServiceImpl implements LoginService {
    @Autowired
    LoginMaper loginMaper;

    @Override
    public Login setLogin(String username) {
        return loginMaper.setLogin(username);
    }

 }

2.2 dao(maper) 层

package com.mc.maper;

import com.mc.pojo.Login;

import java.util.List;

public interface LoginMaper {
    Login setLogin(String username);
    
}

2.3mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mc.maper.LoginMaper">

    <!-- 为了返回list 类型而定义的returnMap -->
    <resultMap type="com.mc.pojo.Login" id="resultLogin">
        <id column="id" property="id"/>
        <result column="username" property="username"/>
        <result column="password" property="password"/>
        <result column="role" property="role"/>
        <result column="level" property="level"/>
    </resultMap>

    <!-- 登录-->
    <select id="setLogin" resultType="Login" parameterType="Login">
        select * from login where username=#{username}
    </select>

</mapper>

写的有点随意

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值