spring+springmvc框架配置详解(2)

2019-04-21 14:23

TestSS

contextConfigLocation

classpath:applicationContext.xml

org.springframework.web.context.ContextLoaderListener

springMVC org.springframework.web.servlet.DispatcherServlet

springMVC /

index.html index.htm index.jsp default.html

default.htm default.jsp

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=\> 主页 欢迎进入主页

测试页面(由于没有连接数据源,用户名和密码可以随意输入)

测试成功页面


spring+springmvc框架配置详解(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:企业职工薪酬所得税会计处理分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: