Skip to content

Commit 9bb07e6

Browse files
SpringBootJpaExample SpringBootWebMvcJspExample
1 parent de6afb5 commit 9bb07e6

File tree

27 files changed

+1125
-0
lines changed

27 files changed

+1125
-0
lines changed

SpringBootJpaExample/doc/help.txt

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
mvn clean install
3+
mvn packatge
4+
mvn spring-boot:run
5+
6+
http://localhost:8080/index.jsp
7+
------------------------------------------------------
8+
Get Request
9+
http://localhost:8080/employee/list
10+
Accept:application/xml
11+
------------------------------------------------------
12+
Get Request
13+
http://localhost:8080/employee/list
14+
Accept:application/json
15+
------------------------------------------------------
16+
Get Request
17+
http://localhost:8080/employee/find/100
18+
Accept:application/json
19+
Accept:application/xml
20+
------------------------------------------------------
21+
Delete REquest
22+
http://localhost:8080/employee/delete/106
23+
------------------------------------------------------
24+
Post Request
25+
http://localhost:8080/employee/save
26+
Accept:application/json
27+
Content-Type:application/json
28+
{
29+
"employeeId": 106,
30+
"employeeFirstName": "Espark",
31+
"employeeLastName": "Kumar",
32+
"employeeEmail": "esprk@kumar",
33+
"employeeSalary": 500
34+
}
35+
36+
------------------------------------------------------
37+
Post Request
38+
http://localhost:8080/employee/save
39+
Accept:application/xml
40+
Content-Type:application/xml
41+
<Employee xmlns="">
42+
<employeeId>106</employeeId>
43+
<employeeFirstName>Espark</employeeFirstName>
44+
<employeeLastName>Kumar</employeeLastName>
45+
<employeeEmail>espark@kumar</employeeEmail>
46+
<employeeSalary>500</employeeSalary>
47+
</Employee>

SpringBootJpaExample/pom.xml

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>SpringBootJpaExample</groupId>
9+
<artifactId>SpringBootJpaExample</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<packaging>war</packaging>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.3.1.RELEASE</version>
17+
</parent>
18+
19+
<organization>
20+
<name>ESpark</name>
21+
<url>http://adarshkumarsingh83.blogspot.in/</url>
22+
</organization>
23+
24+
<licenses>
25+
<license>
26+
<name>ESpark</name>
27+
<url>http://adarshkumarsingh83.blogspot.in/licenses/LICENSE-2.0.txt</url>
28+
<distribution>repo</distribution>
29+
</license>
30+
</licenses>
31+
32+
<developers>
33+
<developer>
34+
<id>adarshkumarsingh83</id>
35+
<name>Adarsh Kumar</name>
36+
<email>adarshkumarsingh83@gmail.com</email>
37+
<roles>
38+
<role>project architect</role>
39+
</roles>
40+
</developer>
41+
</developers>
42+
43+
<repositories>
44+
<repository>
45+
<id>maven2-repository.java.net</id>
46+
<name>Java.net Repository for Maven</name>
47+
<url>http://download.java.net/maven/2/</url>
48+
</repository>
49+
50+
<repository>
51+
<id>JBoss repository</id>
52+
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
53+
</repository>
54+
55+
<repository>
56+
<id>java.net</id>
57+
<url>https://maven.java.net/content/repositories/public/</url>
58+
</repository>
59+
60+
</repositories>
61+
62+
<properties>
63+
<project.name>SpringBootJpaExample</project.name>
64+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
65+
<java.version>1.7</java.version>
66+
<junit.version>4.11</junit.version>
67+
<slf4j.version>1.6.1</slf4j.version>
68+
<log4j.version>1.2.17</log4j.version>
69+
</properties>
70+
71+
<dependencies>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-web</artifactId>
76+
<version>1.3.1.RELEASE</version>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-starter-data-jpa</artifactId>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>org.springframework.boot</groupId>
86+
<artifactId>spring-boot-starter-test</artifactId>
87+
<version>1.2.6.RELEASE</version>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>javax.servlet</groupId>
92+
<artifactId>javax.servlet-api</artifactId>
93+
<scope>compile</scope>
94+
</dependency>
95+
96+
<dependency>
97+
<groupId>javax.servlet</groupId>
98+
<artifactId>jstl</artifactId>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>mysql</groupId>
103+
<artifactId>mysql-connector-java</artifactId>
104+
</dependency>
105+
106+
<dependency>
107+
<groupId>com.fasterxml.jackson.dataformat</groupId>
108+
<artifactId>jackson-dataformat-xml</artifactId>
109+
<version>2.7.0</version>
110+
</dependency>
111+
112+
<dependency>
113+
<groupId>junit</groupId>
114+
<artifactId>junit</artifactId>
115+
<version>${junit.version}</version>
116+
</dependency>
117+
118+
<dependency>
119+
<groupId>org.slf4j</groupId>
120+
<artifactId>slf4j-api</artifactId>
121+
<version>${slf4j.version}</version>
122+
</dependency>
123+
124+
<dependency>
125+
<groupId>log4j</groupId>
126+
<artifactId>log4j</artifactId>
127+
<version>${log4j.version}</version>
128+
</dependency>
129+
130+
</dependencies>
131+
132+
<build>
133+
<finalName>${project.name}</finalName>
134+
<outputDirectory>target/classes</outputDirectory>
135+
<resources>
136+
<resource>
137+
<directory>src/main/resources</directory>
138+
<filtering>true</filtering>
139+
</resource>
140+
</resources>
141+
<plugins>
142+
<plugin>
143+
<artifactId>maven-compiler-plugin</artifactId>
144+
<configuration>
145+
<source>${java.version}</source>
146+
<target>${java.version}</target>
147+
<encoding>${project.build.sourceEncoding}</encoding>
148+
</configuration>
149+
</plugin>
150+
151+
<plugin>
152+
<groupId>org.springframework.boot</groupId>
153+
<artifactId>spring-boot-maven-plugin</artifactId>
154+
</plugin>
155+
</plugins>
156+
</build>
157+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.controller;
32+
33+
import com.espark.adarsh.entities.Employee;
34+
import com.espark.adarsh.services.EmployeeService;
35+
import org.springframework.beans.factory.annotation.Autowired;
36+
import org.springframework.beans.factory.annotation.Qualifier;
37+
import org.springframework.web.bind.annotation.*;
38+
39+
import java.util.HashMap;
40+
import java.util.List;
41+
import java.util.Map;
42+
import java.util.Objects;
43+
44+
/**
45+
* @author Adarsh Kumar
46+
* @author $LastChangedBy: Adarsh Kumar$
47+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
48+
* @Espark @copyright all right reserve
49+
*/
50+
@RestController
51+
@RequestMapping(value = "/employee")
52+
public class EmployeeController {
53+
54+
@Autowired(required = true)
55+
@Qualifier(value = "employeeService")
56+
private EmployeeService employeeService;
57+
58+
59+
@RequestMapping(value = "/find/{employeeId}"
60+
, method = RequestMethod.GET
61+
, produces = {"application/json", "application/xml"})
62+
public Employee getEmployee(@PathVariable int employeeId) {
63+
Employee employee = employeeService.findOne(employeeId);
64+
return employee;
65+
}
66+
67+
@RequestMapping(value = "/list"
68+
, method = RequestMethod.GET
69+
, produces = {"application/json", "application/xml"})
70+
public List<Employee> getEmployees() {
71+
return this.employeeService.findAll();
72+
}
73+
74+
@RequestMapping(value = "/delete/{employeeId}", method = RequestMethod.DELETE)
75+
public Map<String,Object> deleteEmployee(@PathVariable final int employeeId) {
76+
this.employeeService.delete(employeeId);
77+
return new HashMap<String,Object>(){
78+
{
79+
put("message","Employee Deleted");
80+
put("employeeId ",employeeId);
81+
}
82+
};
83+
}
84+
85+
@RequestMapping(value="/save",method = RequestMethod.POST
86+
,consumes = {"application/json", "application/xml"}
87+
, produces = {"application/json", "application/xml"})
88+
public Map<String,Object> saveEmployee(@RequestBody final Employee employee){
89+
this.employeeService.saveEmployee(employee);
90+
return new HashMap<String,Object>(){
91+
{
92+
put("message","Employee Saved");
93+
put("employee",employee);
94+
}
95+
};
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.driver;
32+
33+
import org.springframework.boot.SpringApplication;
34+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
35+
import org.springframework.boot.autoconfigure.SpringBootApplication;
36+
import org.springframework.boot.builder.SpringApplicationBuilder;
37+
import org.springframework.boot.context.web.SpringBootServletInitializer;
38+
import org.springframework.boot.orm.jpa.EntityScan;
39+
import org.springframework.context.annotation.ComponentScan;
40+
import org.springframework.context.annotation.Configuration;
41+
import org.springframework.context.annotation.PropertySource;
42+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
43+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
44+
45+
/**
46+
* @author Adarsh Kumar
47+
* @author $LastChangedBy: Adarsh Kumar$
48+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
49+
* @Espark @copyright all right reserve
50+
*/
51+
@Configuration
52+
@SpringBootApplication
53+
@EnableAutoConfiguration
54+
@ComponentScan("com.espark.adarsh")
55+
@EntityScan(basePackages = "com.espark.adarsh.entities")
56+
@EnableJpaRepositories(basePackages = "com.espark.adarsh.repository")
57+
@PropertySource("classpath:application.properties")
58+
public class Application extends SpringBootServletInitializer {
59+
60+
@Override
61+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
62+
return application.sources(Application.class);
63+
}
64+
public static void main(String[] args) {
65+
SpringApplication.run(Application.class, args);
66+
}
67+
}

0 commit comments

Comments
 (0)