Skip to content
Snippets Groups Projects
Verified Commit 27a7baf8 authored by Julien Wittouck's avatar Julien Wittouck
Browse files

:tada: : add screencast starter code

parents
No related branches found
No related tags found
No related merge requests found
/target/
.classpath
.project
.settings/
*.class
pom.xml 0 → 100755
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.eservices</groupId>
<artifactId>screencast-13</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Screencast Spring Web MVC Simple</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>5.1.11.RELEASE</spring.version>
<slf4j.version>1.7.29</slf4j.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.fasterxml.jackson.core</groupId> -->
<!-- <artifactId>jackson-core</artifactId> -->
<!-- <version>2.10.1</version> -->
<!-- <scope>runtime</scope> -->
<!-- </dependency> -->
</dependencies>
</project>
\ No newline at end of file
package fr.eservices.week402.app;
// Set this class as a configuration class.
// scan fr.eservices.week402.ctrl for components
// enable spring web mvc
public class AppConfig {
// Add a method to provide an InternalReourceViewResolver
// put views in /WEB-INF/views
// all views should be some jsp
}
package fr.eservices.week402.app;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
/* *
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register( AppConfig.class );
container.addListener( new ContextLoaderListener(dispatcherContext) );
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", DispatcherServlet.class);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/app/*");
/* */
}
}
package fr.eservices.week402.ctrl;
// TODO: Annotation to expose this controller
public class HelloController {
// TODO: Annotaiton to map this method to /hello !
public String sayHello(
String name
) {
String message = "Hello " + name + " !";
// TODO: pass message to view ...
return "/sample.jsp";
}
}
package fr.eservices.week402.ctrl;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import fr.eservices.week402.model.TimeObject;
@RestController
@RequestMapping(path="/simple")
public class SimpleController {
@GetMapping(path="/add")
public String add(
@RequestParam int a,
@RequestParam int b
) {
return Integer.toString( a + b );
}
@GetMapping(path="/time")
public TimeObject getTime() {
TimeObject t = new TimeObject();
Date now = new Date();
t.day = DateFormat.getDateInstance(DateFormat.SHORT).format(now);
t.day = DateFormat.getTimeInstance(DateFormat.SHORT).format(now);
t.locale = Locale.getDefault().toString();
t.timestamp = (long) (now.getTime() / 1000);
return t;
}
}
package fr.eservices.week402.model;
public class TimeObject {
public String
day, time, locale;
public long timestamp;
}
<!DOCTYPE html>
<html lang="en">
<%
String ctxPath = request.getContextPath();
%>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title>Signin Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="<%= ctxPath %>/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="<%= ctxPath %>/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="<%= ctxPath %>/css/signin.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">Panel heading</div>
Message is : xxxx
</div>
</div> <!-- /container -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="<%= ctxPath %>/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment