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的更多相关文章

  1. Spring MVC Framework 注解

    ControllerAdvice Spring MVC Framework会把 @ControllerAdvice注解内部使用 @ExceptionHandler.@InitBinder.@Model ...

  2. WebWork2和Spring MVC Framework的比较

    http://daihaixiang.blog.163.com/blog/static/3830134200711411515336/ WebWork2和Spring MVC Framework的比较 ...

  3. 理解ASP.NET MVC Framework Action Filters

    原文:http://www.cnblogs.com/darkdawn/archive/2009/03/13/1410477.html 本指南主要解释action filters,action filt ...

  4. ASP.NET MVC Framework

    ASP.NET MVC Framework是微软在ASP.NET中所添加的一组类库,这组类库可以使用Model-View-Controller的设计模式来开发ASP.NET的应用程序.它与现有的ASP ...

  5. Karma - MVC Framework for Unity3D

    Karma is an MVC framework for Unity3D. Because of how Unity is structured, it actually turns out to ...

  6. 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 ...

  7. 【转】Code Your Own PHP MVC Framework in 1 Hour

      原文: https://www.codeproject.com/Articles/1080626/Code-Your-Own-PHP-MVC-Framework-in-Hour --------- ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. SAP MaxDB Backup and Restore

    Back up the data and redo log entries from the data and log areas of your database to data carriers ...

  2. react native props上存在的属性,显示不存在

    问题:类型“Readonly<{}> & Readonly<{ children?: ReactNode; }>”上不存在属性“navigation”.ts(2339) ...

  3. 有关二次离线和 Yuno loves sqrt technology II

    二次离线 前置技能 莫队 修改查询 \(O(\sqrt n )-O(1)\) 平衡 概念 考虑朴素莫队离线询问,过程中维护信息从 \([l,r]\) 扩展为 \([l\pm 1,r\pm 1]\) , ...

  4. 11G 新特性之 密码延迟认证

    11G 新特性之 密码延迟认证 11G 新特性之 密码延迟认证 Table of Contents 1. 特性简述 2. 特性潜在引发问题 3. 关闭特性 1 特性简述 为了防止用户密码的暴力破解,从 ...

  5. [VBA]指定列求和

    ##指定列求和 需求: 求和:列为“销售金额”的数值 Sub 求和()Dim i As Integer, j As IntegerFor i = 3 To 56For j = 15 To 81 Ste ...

  6. iOS 图表工具charts之LineChartView

    关于charts的系列视图介绍传送门: iOS 图表工具charts介绍 iOS 图表工具charts之LineChartView iOS 图表工具charts之BarChartView iOS 图表 ...

  7. Custom Configuration 的两种方法:2.XmlSerializer XmlAttribute

    第二种:XmlSerializer XmlAttribute 1.CustomConfiguration.xml 2.CustomConfigurationSetting.cs 3.CustomCon ...

  8. Linux 的路由功能

    目录 文章目录 目录 前文列表 路由器 Router 路由 Routing 静态路由与动态路由 通过路由实现的全网通信示例 Linux 作为路由器 route 指令 路由表项的类型 ip route ...

  9. 113路径总和II

    题目: 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 来源: https://leetcode-cn.com/problems/path-sum-ii/ 法一: ...

  10. Java学习之==>数组【array】

    一.定义数组 /** * 一维数组定义 * * 为数组插入元素 */ public void case1() { // 声明 int[] arr1; // 声明+初始化 int[] arr2 = ne ...