Spring的dao层
package com.hpe.dao;
import
org.springframework.stereotype.Repository; //dao层注解配置 @Repository
public class HelloDao { public int getUser(){ }
}
System.out.println(\找到了用户\); return 1;
Spring的service层 package com.hpe.service;
import
org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import com.hpe.dao.HelloDao; //service层注解配置 @Service
public class HelloService {
public HelloService() {
}
}
System.out.println(\构造方法开始执行\
//启动spring自动装配 @Autowired
private HelloDao hd; public boolean hService(){ }
int i = hd.getUser(); if(i>0){ }
return false;
return true;
Spring的controller层 package com.hpe.controller;
import
org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import
org.springframework.web.bind.annotation.RequestMapping;
import com.hpe.bean.UserBean; import com.hpe.service.HelloService; //spring提供的dao层的控制 @Controller
public class HelloController {
}
//启用注解(自动装配) @Autowired
private HelloService hs;
public void setHs(HelloService hs) { }
//设置访问地址
@RequestMapping(\//从客户端获取表单信息的注解配置 public String hc(UserBean user){ }
System.out.println(user.getUsername()); System.out.println(user.getPassword()); boolean b = hs.hService(); if(b){ }
return \
return \this.hs = hs;
前端登录页面login.jsp
<%@ page language=\ contentType=\charset=UTF-8\
pageEncoding=\%>
\>
content=\>
登录成功页面main.jsp
<%@ page language=\ contentType=\charset=UTF-8\
pageEncoding=\%>
\>
content=\>
测试页面(由于没有连接数据源,用户名和密码可以随意输入)
测试成功页面