学maven咯——搭建springmvc helloworld

之前断断续续用过一段时间maven,但是并没有系统并仔细的学习过,刚好最近接触的几个项目maven用的比价多所以决定稍微学习一下。那啥,不会详细的写啥是maven,有啥优缺点,或者其他更多的理论知识,只是结合自己使用过程中遇到的问题做一些备忘,至于基础那些啥的,有度娘你问我干啥子?

首先,创建maven项目的时候,会填几个东西,但是比较模糊的就2个:groupId和artifactId。我比较倾向的描述是:groupId就是项目名,也就是java常用的包名里com.xxx这一节,而artifactId就是模块名,也就是比如说你的项目里有微信这个一个模块,传统的包名就是com.xxx.wechat中wechat这一节。

我用的开发工具是eclipse,创建完mevan project 之后,会有几个路径:

src/main/java:丢java文件的地方

src/main/resources:丢配置文件的地方

src/main/webapp:丢页面的地方

还有一个比较重要的文件:pom.xml:

在该文件中增加阿里maven仓库镜像,可以提高jar包获取速度,增加如下:

        <repositories>
		<repository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

然后加入需要的jar包依赖:
                <dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

在resources中增加springmvc配置文件并在web.xml中配置。

在src/main/java下增加一个简单的HelloController,在src/main/webapp/WEB-INF下增加对应的页面文件(比如helloworld.jsp)。

完成以上步骤之后就可以扔进tomcat启动了,大概就这样。

另外,在做这个的时候碰上了el表达式失效的问题,官方解释是web版本太低,在2.3以下的时候会发生这种问题,神知道我为啥会碰上2.3以下的demo,碰上这个问题的话要么在页面增加isELIgnored=false,或者升版本,不过大部分人已经不会用2.3以下版本了所以这个坑一般也不会有人踩进去。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值