博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring——第一个Spring程序HelloSpring
阅读量:3943 次
发布时间:2019-05-24

本文共 1398 字,大约阅读时间需要 4 分钟。

Spring——第一个Spring程序HelloSpring

1.创建普通的Maven项目

在这里插入图片描述
2.导入jar包

org.springframework
spring-webmvc
4.3.9.RELEASE

我们可以看到,只要导入spring-webmvc这个包,Maven就会自动导入依赖的其他jar包

在这里插入图片描述
3.创建pojo

package com.muhan.pojo;public class User {
private String name; public User() {
} public User(String name) {
this.name = name; } public String getName() {
return name; } public void setName(String name) {
this.name = name; } @Override public String toString() {
return "User{" + "name='" + name + '\'' + '}'; }}

4.编写Spring的配置文件applicationContext.xml

5.测试

import com.muhan.pojo.User;import org.junit.Test;import org.springframework.context.support.ClassPathXmlApplicationContext;public class UserTest {
@Test public void test(){
//获取ClassPathXmlApplicationContext对象,关联spring配置文件applicationContext.xml ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); //获取对象名为user的对象 User user = (User) context.getBean("user"); System.out.println(user); //获取对象名为user2的对象 User user2 = (User) context.getBean("user2"); System.out.println(user2); }}

结果展示:

在这里插入图片描述

6.项目结构

在这里插入图片描述

转载地址:http://xoiwi.baihongyu.com/

你可能感兴趣的文章
SQLite Tutorial 4 : How to export SQLite file into CSV or Excel file
查看>>
Optimizate objective function in matrix
查看>>
Convert polygon faces to triangles or quadrangles
查看>>
read obj in matlab
查看>>
find out the neighbour matrix of a mesh
查看>>
Operators and special characters in matlab
查看>>
As-Conformal-As-Possible Surface Registration
查看>>
qmake Variable Reference
查看>>
Lesson 2 Gradient Desent
查看>>
find border vertex
查看>>
matlab sliced variable
查看>>
create symbolic array
查看>>
TAUCS库的编译(vs2010)
查看>>
color vector using in plotting example points and lines between corresponding vertices
查看>>
mex 里面调用matlab函数
查看>>
matlab中cuda编程中分配grid和block dimension的时候的注意事项
查看>>
GPU CUDA and MEX Programming
查看>>
arrayfun用法
查看>>
矩阵积分
查看>>
optimization on macOS
查看>>