springboot与返回视图

1.使用jsp返回

application.properties
############## OAuth ################
server.port=8082
#jsp path
spring.view.prefix=/WEB-INF/page/
spring.view.suffix=.jsp

依赖包

<dependency>
			<groupId>apache-taglibs</groupId>
			<artifactId>jstl</artifactId>
			<version>1.1.2</version>
		</dependency>
		<!-- jsp解析器 -->
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<scope>provided</scope>
		</dependency>

启动方法

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RestController;

//@SpringBootApplication
@PropertySource("classpath:application.properties")
// @EnableTransactionManagement(proxyTargetClass = true)
@ImportResource({ "classpath*:springContext.xml" })
@ComponentScan("com.zy")
// @EnableAutoConfiguration
@RestController
@EnableAutoConfiguration
public class RumTimeBox {

	public static void main(String[] args) {
		SpringApplication.run(RumTimeBox.class, args);
		System.out.println("success!");
	}

	protected SpringApplicationBuilder config(SpringApplicationBuilder applicationBuilder) {
		return applicationBuilder.sources(RumTimeBox.class);
	}

}

2.springboot 与freemarker

配置文件application.properties

############## OAuth ################
server.port=8082
#jsp path
#spring.view.prefix=/WEB-INF/page/
#spring.view.suffix=.html
spring.freemarker.checkTemplateLocation=false
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=/WEB-INF/page/

依赖包

<dependency>
			<groupId>org.freemarker</groupId>
			<artifactId>freemarker</artifactId>
			<version>2.3.25-incubating</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>

启动方法

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RestController;

//@SpringBootApplication
@PropertySource("classpath:application.properties")
// @EnableTransactionManagement(proxyTargetClass = true)
@ImportResource({ "classpath*:springContext.xml" })
@ComponentScan("com.zy")
// @EnableAutoConfiguration
@RestController
@EnableAutoConfiguration
public class RumTimeBox extends SpringBootServletInitializer {
	/**
	 * springboot默认启动
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		SpringApplication.run(RumTimeBox.class, args);
		System.out.println("success!");
	}

	/**
	 * 重写启动方法,用于使用第三方配置如jetty 启动时使用
	 */
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(RumTimeBox.class);
	}

}

springboot配置文件中只有配置注解扫描<context:component-scan base-package="com.zy" />

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值