標籤:spring boot
一、建立工程
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/99/11/wKioL1lDhHmCc3_0AACchr2LV6o135.jpg" title="1497597109(1).jpg" alt="wKioL1lDhHmCc3_0AACchr2LV6o135.jpg" />
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/99/11/wKiom1lDhKvS9BgwAAE4CYkOeeA762.jpg" title="1497597156(1).jpg" alt="wKiom1lDhKvS9BgwAAE4CYkOeeA762.jpg" />
注意建立的工程下沒有webapp目錄eclipse下會自動建立webapp目錄這裡我們需要自動建立一個webapp目錄並建立WEB-INF。
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M00/99/11/wKiom1lDhzbBzsgLAABDTSJB-dM691.jpg" title="1497597815(1).jpg" alt="wKiom1lDhzbBzsgLAABDTSJB-dM691.jpg" />
對ServletInitializer.java進行說明
1、這個類相當於我們以前的web.xml
2、只有3.0以上才可以否則需要添加web.xml
二、配置
2.1、pom.xml配置
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope></dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency>
2.2、配置首碼與尾碼類似於sspringmvc
spring.profiles.active=dev#配置首碼與尾碼spring.mvc.view.prefix=/WEB-INF/templates/spring.mvc.view.suffix=.jsp
四、代碼
package com.example.demo.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;/** * Created by ly on 2017/6/16. */@Controller@RequestMapping("/demo1")public class Index { @RequestMapping("/index") public String index(Model model) throws Exception { model.addAttribute("title" ,"ceshi"); return "index"; }}
idea這裡有點問題下面改用eclipse結構如下
650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/99/16/wKioL1lDqcOz9m74AABuiO841NQ335.jpg" title="1497606660(1).jpg" alt="wKioL1lDqcOz9m74AABuiO841NQ335.jpg" />
index.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><!DOCTYPE html><html><head lang="en"><title>Spring Boot Demo - FreeMarker</title><link href="/static/css/index.css" rel="stylesheet" /></head><body><h1 id="title">${title}</h1><c:url value="http://www.roncoo.com" var="url"/><spring:url value="http://www.roncoo.com" htmlEscape="true" var="springUrl" />Spring URL: ${springUrl}<br>JSTL URL: ${url}<!-- <script type="text/javascript" src="/static/webjars/jquery/2.1.4/jquery.min.js"></script><script>$(function(){$(‘#title‘).click(function(){alert(‘1o‘);});})</script> --></body></html>
訪問http://localhost:8988/demo1/index
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/99/16/wKioL1lDqWOxp75iAABILem-yOk280.jpg" title="1497606565(1).jpg" alt="wKioL1lDqWOxp75iAABILem-yOk280.jpg" />
本文出自 “我愛大金子” 部落格,請務必保留此出處http://1754966750.blog.51cto.com/7455444/1939115
springBoot(6):web開發-模板引擎jsp