**
First:确保服务器能跳转页面。
**
**
Second:在dao层设置接口
**
import com.code.bean.User;
public interface IUserDao {
//验证登录
//查询Select
User doLogin(String username);
}
**
Third:实现Service层
**
import com.code.bean.User;
public interface IUserService {
User doLogin(String username);
}
import com.code.bean.User;
import com.code.dao.IUserDao;
import com.code.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class IUserServiceImpl implements IUserService{
@Autowired
private IUserDao userDao;
@Override
public User doLogin(String username) {
return userDao.doLogin(username);
}
}
**
Fourth:实现Controller层
**
|import com.code.bean.User;
import com.code.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("/doLogin.do")
public String doLogin(String username,String password){
//1.调用service,查询得到结果,自动补全返回值 Ctrl+Alt+V
User user = userService.doLogin(username);
//2.判断
if(user != null){
if (user.getPassword().equals(password)){
System.out.println("密码正确,登录成功!");
return "main";
}else{
System.out.println("密码错误,登陆失败!");
return "../login";
}
}else{
System.out.println("用户不存在,请重新输入!");
return "../login";
}
}
}
**
Fifth:修改jsp页面参数
**
<form action="${pageContext.request.contextPath}/user/doLogin.do" method="post">
<div class="form-group has-feedback">
<input type="text" name="username" class="form-control"
placeholder="用户名"> <span
class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control"
placeholder="密码"> <span
class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label><input type="checkbox"> 记住 下次自动登录</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
</div>
<!-- /.col -->
</div>
</form>
**
Finally:测试登录页面
**