SpringMvc 5,可以参考这一篇《Spring和Spring Mvc 5整合详解》
Spring Mvc的启动方式不同于Spring Boot,Spring Boot内嵌了tomcat容器,可以打包成jar文件快速启动。Spring Mvc仍需要打包成war包。所以,它是离不开web.xml配置。
配置Spring和Spring Mvc,主要有:
Git地址:
Gitee
项目地址:
品茗IT-同步发布
品茗IT 提供在线支持:
如果大家正在寻找一个java的学习环境,或者在开发中遇到困难,可以加入我们的java学习圈,点击即可加入,共同学习,节约学习时间,减少很多在学习中遇到的难题。
org.springframework
spring-core
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
UmpEnt
log4jConfigLocation
classpath:properties/log4j.properties
log4jRefreshInterval
600000
org.springframework.web.util.Log4jConfigListener
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
springDispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-servlet.xml
1
springDispatcherServlet
/
/index.html
这个配置文件里可以写入一些bean的配置。
Spring是一个大的父容器,Spring Mvc是其中的一个子容器。父容器不能访问子容器对象,但是子容器可以访问父容器对象。 因此,bean的配置要写到这个文件中,而不是Spring Mvc的配置文件中。
application/json;charset=UTF-8
Spring是一个大的父容器,Spring Mvc是其中的一个子容器。父容器不能访问子容器对象,但是子容器可以访问父容器对象。 因此,bean的配置要写到这个文件中,而不是Spring Mvc的配置文件中。
package com.cff.springwork.web.endpoint.test;
import java.util.UUID;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.cff.springwork.web.entity.WelEntity;
@RestController("testController")
@RequestMapping("/test")
public class TestController {
@RequestMapping("/welCome")
public WelEntity welCome(@RequestParam String reqType){
String uuid = UUID.randomUUID().toString();
String welMsg = "welcome 程序猿";
if(reqType != null && "1000".equals(reqType)){
welMsg = "welcome 程序媛";
}
WelEntity welEntity = new WelEntity();
welEntity.setUuid(uuid);
welEntity.setWelMsg(welMsg);
return welEntity;
}
}
实体:
package com.cff.springwork.web.entity;
public class WelEntity {
private String uuid;
private String welMsg;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getWelMsg() {
return welMsg;
}
public void setWelMsg(String welMsg) {
this.welMsg = welMsg;
}
}
SkyNet
这是html
喜欢这篇文章么,喜欢就加入我们一起讨论Spring技术吧!