基于Spring+Mybatis+jsp+servlet的用户登录注册功能(数据库查找和插入用户),jsp写的前端(css+javascript),使用IDEA

基于Spring+Mybatis+jsp+servlet的用户登录注册功能(数据库查找和插入用户),jsp写的前端(css+javascript),使用IDEA

!!!代码放在最后
网页前端的设计:jsp编写,使用css美化(字体使用Google font,图标使用font awemome,颜色使用palettes|flat ui colors,谷歌可找到,个人觉得挺好用)
使用了简单的js进行表单验证用户名长度、密码、确认密码
项目结构
在这里插入图片描述
(1)建立一个名为spring的数据库,user_information的表,字段id、username、password
在这里插入图片描述

(2)前端jsp、css代码编写
(3)sqlMapConfig.xml的Mybatis总配置文件
(4)ApplicationContext.xml的Spring总配置文件
(5)编写User类 bean
(6)UserMapper接口和UserMapper.xml定义实现SQL语句findById、findByName、findByUser、insertUser方法
(7)UserService接口和UserServiceImpl实现类(实现addAccount和hasAccount方法)
(8)util工具包下的servlet类(LoginServlet和RegisterServlet)

配置文件:
(1)sqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <typeAliases>
        <package name="com.dingxiang.bean"/>
    </typeAliases>
    <mappers>
        <mapper class="com.dingxiang.mapper.UserMapper"/>
    </mappers>
</configuration>

(2)UserMapper.xml(配置UserMapper接口实现)

<?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.dingxiang.mapper.UserMapper">
    <select id="findById" resultType="User" parameterType="Integer">
        select * from spring.user_information where id=#{id}
    </select>
    <select id="findByName" parameterType="String" resultType="User">
        select * from spring.user_information where username=#{username}
    </select>
    <select id="findByUser" parameterType="User" resultType="User">
        select * from spring.user_information where username=#{username} and password=#{password}
    </select>
    <insert id="insertUser" parameterType="User">
        insert  into spring.user_information (username,password) values(#{username},#{password})
    </insert>
</mapper>

(3)ApplicationContext.xml(配置DataSource、sqlsessionFactory、Mapper实现把User交给Spring管理,数据库实现Mybatis由Spring帮我们完成)

<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframe
  • 5
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值