刚刚已经把登录做完了,现在做注册功能吧!!QAQ
先把刚刚的登录页面复制一份然后改改,就是注册页面了
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
<title>注册页面title>
head>
<body>
<form action="register" method="post">
用户名:<input type="text" name="username"/> <br>
密码:<input type="password" name="password"/>
个性签名:<input type="text" name="perms"/> <br>
<input type="submit" value="我要注册">
form>
body>
html>
public interface UserDao {
//查询单个用户的接口
User queryUser(@Param("name")String name,@Param("pwd")String pwd);
//添加用户的接口
Integer AddUser(@Param("name")String name,@Param("pwd")String pwd,@Param("perms")String perms);
//判断用户是否存在的接口
Integer querUserByName(String name);
}
public interface UserService {
User queryUser(String name,String pwd);
Integer querUserByName(String name);
Integer AddUser(String name,String pwd,String perms);
}
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserDao userDao;
@Override
public User queryUser(String name, String pwd) {
// TODO Auto-generated method stub
return userDao.queryUser(name, pwd);
}
@Override
public Integer AddUser(String name, String pwd, String perms) {
// TODO Auto-generated method stub
return userDao.AddUser(name, pwd, perms);
}
@Override
public Integer querUserByName(String name) {
// TODO Auto-generated method stub
return userDao.querUserByName(name);
}
}
<mapper namespace="com.liliya.dao.UserDao">
<select id="queryUser" parameterType="string" resultType="User">
select id,name,pwd,perms
from mybatis.user
where `name`=#{name} and `pwd`=#{pwd}
select>
<select id="querUserByName" resultType="int">
select count(1) from mybatis.user where `name`=#{name};
select>
<insert id="AddUser">
insert into mybatis.user (name,pwd,perms)
values (#{name},#{pwd},#{perms})
insert>
mapper>
首先就是判断用户名是不是已经存在了,如果是已经存在了,那就返回一条消息,告诉用户,用户名存在了。如果注册成功的话就进入hello页面。。
@RequestMapping("/register")
public String register(String username,String password,String perms,Model model) {
//如果用户不存在
if (userService.querUserByName(username)==0) {
userService.AddUser(username, password, perms);
model.addAttribute("name", username);
return "hello";
}else {
model.addAttribute("msg", "用户名已经存在了");
return "register";
}
}
效果如图!!!
然后查询数据库也是可以查到的
注册登录到这里就完成了!!!
接下来就是写分页了
https://blog.csdn.net/zhihu_0/article/details/107730152