Spring Framework Part4 self-summeries-a simplified MVC framework
1.关于Spring Framework xml的头部
<?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:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.littlepage"></context:component-scan>
</beans>
context:component-scan 表示扫描package,扫描com.littlepage包下的package
2.关于目录结构
3.测试层开始,测试层模拟入口,也就是类似的jsp提交
package com.littlepage.test; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.littlepage.controller.LoginController; public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext cpx=new ClassPathXmlApplicationContext("applicationContext.xml");
LoginController loginController = cpx.getBean("loginController",LoginController.class);
boolean isLogin=loginController.testLogin("root", "root");
if(isLogin) {
System.out.println("Login Success");
}else {
System.out.println("Login Failed");
}
cpx.close();
}
}
4.与jsp相连的层是controller层,从controller层开始接入service层,这边是controller层的内容
package com.littlepage.controller; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import com.littlepage.service.LoginService; @Controller
public class LoginController { @Autowired
private LoginService loginService; public boolean testLogin(String name,String password) {
return loginService.testLogin(name,password);
}
}
5.关于service层的验证
package com.littlepage.service; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.littlepage.dao.GetNameAndPassword;
import com.littlepage.pojo.User; @Service
public class LoginService { @Autowired
GetNameAndPassword getNameAndPassword; public boolean testLogin(String name, String password) {
User user=getNameAndPassword.getUser();
if(user.getName().equals(name)&&user.getPassword().equals(password)) return true;
return false;
} }
6.service层与dao层连,dao有一个orm映射,与pojo层相连
package com.littlepage.dao; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import com.littlepage.pojo.User; @Repository
public class GetNameAndPassword { @Autowired
private User user; public User getUser() {
return user;
}
}
7.pojo层注意,是一个prototype的scope,属性用@Value进行赋值
package com.littlepage.pojo; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; @Component
@Scope("prototype")
public class User { @Value("root")
private String name;
@Value("root")
private String password; public User() {
} public User(String name, String password) {
super();
this.name = name;
this.password = password;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} }
8.运行,测试结果无误
Spring Framework Part4 self-summeries-a simplified MVC framework的更多相关文章
- Spring MVC Framework 注解
ControllerAdvice Spring MVC Framework会把 @ControllerAdvice注解内部使用 @ExceptionHandler.@InitBinder.@Model ...
- WebWork2和Spring MVC Framework的比较
http://daihaixiang.blog.163.com/blog/static/3830134200711411515336/ WebWork2和Spring MVC Framework的比较 ...
- 理解ASP.NET MVC Framework Action Filters
原文:http://www.cnblogs.com/darkdawn/archive/2009/03/13/1410477.html 本指南主要解释action filters,action filt ...
- ASP.NET MVC Framework
ASP.NET MVC Framework是微软在ASP.NET中所添加的一组类库,这组类库可以使用Model-View-Controller的设计模式来开发ASP.NET的应用程序.它与现有的ASP ...
- Karma - MVC Framework for Unity3D
Karma is an MVC framework for Unity3D. Because of how Unity is structured, it actually turns out to ...
- How to create a site with AJAX enabled in MVC framework.
How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...
- 【转】Code Your Own PHP MVC Framework in 1 Hour
原文: https://www.codeproject.com/Articles/1080626/Code-Your-Own-PHP-MVC-Framework-in-Hour --------- ...
- TreeFrog Framework : High-speed C++ MVC Framework for Web Application http://www.treefrogframework.org
TreeFrog Framework : High-speed C++ MVC Framework for Web Application http://www.treefrogframework.o ...
- Please set registry key HKLM\Microsoft\.NET Framework\InstallRoot to point to the .NET Framework
安装.NET程序时会提示“Please set registry key HKLM\Microsoft\.NET Framework\InstallRoot to point to the .NET ...
随机推荐
- Hidden的应用
在写jsp中如果一个 请求的参数(例如:paramTypeCode)不能在另一个请求中使用,我们为了能让他在请求中使用可以利用隐藏域来表示,下面介绍他的用法: 1 <input type= ...
- IFB
本文翻译自Linux官方IFB文档 IFB(中介功能块设备)是IMQ(中介队列设备)的继任者,IMQ从来没有被集成过,IFB拥有IMQ的优点,在SMP上更加清晰明了,并且代码量缩减了非常多,旧的中介设 ...
- SQL2008附加数据库报错
sql server 2008如何导入mdf,ldf文件 网上找了很多解决sql server导入其他电脑拷过来的mdf文件,多数是不全,遇到的解决方法不一样等问题,下边是找到的解决问题的最全面方法! ...
- python学习笔记:(九)循环(for和while)
在python中循环包括for和while 1.while循环 while 判断条件: statements ----表示:判断条件为真时执行statements,为假不执行 2.for语句 for ...
- CentOS mysql安装
MySQL For Excel 1.3.5MySQL for Visual Studio 1.2.5MySQL Fabric 1.5.6 & MySQL Utilities 1.5.6Conn ...
- [译]深入 NGINX: 为性能和扩展所做之设计
来自:http://ifeve.com/inside-nginx-how-we-designed-for-performance-scale/ 这篇文章写了nginx的设计,写的很仔细全面, 同时里面 ...
- python学习之函数(二)
4.4.6 动态传参 动态传参是针对形参而言 1.动态位置参数 在静态位置参数时,我们知道,定义函数时有几个位置参数,调用时就必须给几个实参,不能多也不能少.有时候,实际应用过程中,参数往往不能固 ...
- 配置java开发环境,存在多个版本JDK时,怎样让所需版本生效
我本地有个1.7.0的java版本,后来我新装了一个13的版本,但是命令行查java版本的时候,生效的还是1.7.0的版本,经过资料查询以及自身亲测,现将过程记录如下: 1.电脑右键选择--属性--高 ...
- POJ3585 Accumulation Degree【换根dp】
题目传送门 题意 给出一棵树,树上的边都有容量,在树上任意选一个点作为根,使得往外流(到叶节点,叶节点可以接受无限多的流量)的流量最大. 分析 首先,还是从1号点工具人开始$dfs$,可以求出$dp[ ...
- mybatis多对多级联查询
1.实体 package com.govmade.govdata.modules.sys.pojo; import java.util.List; import javax.persistence.T ...