Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer adding to jpa #7

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d66441
Added Index Page and controller
springframeworkguru Nov 6, 2015
eecfc02
Adding .mvn to gitignore
springframeworkguru Nov 6, 2015
d806ca9
Added Index Page and controller
springframeworkguru Nov 6, 2015
ab33273
Added Web Jars
springframeworkguru Nov 6, 2015
56f9fd5
Added Product Listing
springframeworkguru Nov 7, 2015
3e4eebe
Added Display Product
springframeworkguru Nov 9, 2015
d75c97e
Added Create a Product
springframeworkguru Nov 9, 2015
b7b97e9
Added Create a Product
springframeworkguru Nov 9, 2015
8be594a
Added delete a Product
springframeworkguru Nov 14, 2015
c7f19c7
added customer
springframeworkguru Nov 16, 2015
af80230
added spring mvc test examples for index and crud (product only)
springframeworkguru Nov 18, 2015
0caaa61
added spring mvc test examples for index and crud (product only)
springframeworkguru Nov 18, 2015
29470dc
Merge branch 'master' into spring-mvc-test-crud-customer
springframeworkguru Nov 20, 2015
5f25fd9
fixed URL mapping issue for index
springframeworkguru Nov 20, 2015
ab7bb06
added dev tools
springframeworkguru Dec 1, 2015
94d8389
added jars for spring data jpa and h2
springframeworkguru Dec 9, 2015
171c8f4
Converted Product to JPA Entity
springframeworkguru Dec 9, 2015
6ad1014
Converted Product to JPA Entity
springframeworkguru Dec 9, 2015
5be187c
converted Customer Object to JPA Entity
springframeworkguru Dec 9, 2015
35ee0f2
new file indahouse
Dec 19, 2016
0639a00
new file indahouse
Dec 19, 2016
8d0cbad
new file indahouse
Dec 19, 2016
71e5287
add new jenkins pipeline definition
Dec 19, 2016
7280992
add new jenkins pipeline definition
Dec 19, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Thumbs.db
.project
.classpath
.idea
.mvn
*.iml
atlassian-ide-plugin.xml
target
12 changes: 12 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node{

stage("Checkout"){
checkout scm
}

stage("Build"){
withEnv(["PATH+MAVEN=${tool 'M3'}"]){
sh 'mvn clean install -DskipTests'
}
}
}
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!--WebJars-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/guru/springframework/SpringmvcApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringmvcApplication {

public static void main(String[] args) {
SpringApplication.run(SpringmvcApplication.class, args);
ApplicationContext ctx = SpringApplication.run(SpringmvcApplication.class, args);

// for (String name : ctx.getBeanDefinitionNames()){
// System.out.println(name);
// }
// System.out.println("******* Bean Count *******");
// System.out.println(ctx.getBeanDefinitionCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package guru.springframework.controllers;

import guru.springframework.domain.Customer;
import guru.springframework.services.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
* Created by jt on 11/15/15.
*/
@RequestMapping("/customer")
@Controller
public class CustomerController {

private CustomerService customerService;

@Autowired
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}

@RequestMapping({"/list", "/"})
public String listCustomers(Model model){
model.addAttribute("customers", customerService.listAll());
return "customer/list";
}

@RequestMapping("/show/{id}")
public String showCustomer(@PathVariable Integer id, Model model){
model.addAttribute("customer", customerService.getById(id));
return "customer/show";
}

@RequestMapping("/edit/{id}")
public String edit(@PathVariable Integer id, Model model){
model.addAttribute("customer", customerService.getById(id));
return "customer/customerform";
}

@RequestMapping("/new")
public String newCustomer(Model model){
model.addAttribute("customer", new Customer());
return "customer/customerform";
}

@RequestMapping(method = RequestMethod.POST)
public String saveOrUpdate(Customer customer){
Customer newCustomer = customerService.saveOrUpdate(customer);
return "redirect:customer/show/" + newCustomer.getId();
}

@RequestMapping("/delete/{id}")
public String delete(@PathVariable Integer id){
customerService.delete(id);
return "redirect:/customer/list";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package guru.springframework.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* Created by jt on 11/6/15.
*/
@Controller
public class IndexController {

@RequestMapping({"/", ""})
public String index(){
return "index";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package guru.springframework.controllers;

import guru.springframework.domain.Product;
import guru.springframework.services.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
* Created by jt on 11/6/15.
*/
@Controller
public class ProductController {

private ProductService productService;

@Autowired
public void setProductService(ProductService productService) {
this.productService = productService;
}

@RequestMapping("/product/list")
public String listProducts(Model model){
model.addAttribute("products", productService.listAll());
return "product/list";
}

@RequestMapping("/product/show/{id}")
public String getProduct(@PathVariable Integer id, Model model){
model.addAttribute("product", productService.getById(id));
return "product/show";
}

@RequestMapping("product/edit/{id}")
public String edit(@PathVariable Integer id, Model model){
model.addAttribute("product", productService.getById(id));
return "product/productform";
}

@RequestMapping("/product/new")
public String newProduct(Model model){
model.addAttribute("product", new Product());
return "product/productform";
}

@RequestMapping(value = "/product", method = RequestMethod.POST)
public String saveOrUpdateProduct(Product product){
Product savedProduct = productService.saveOrUpdate(product);
return "redirect:/product/show/" + savedProduct.getId();
}

@RequestMapping("/product/delete/{id}")
public String delete(@PathVariable Integer id){
productService.delete(id);
return "redirect:/product/list";
}
}
117 changes: 117 additions & 0 deletions src/main/java/guru/springframework/domain/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package guru.springframework.domain;

import javax.persistence.*;

/**
* Created by jt on 11/14/15.
*/
@Entity
public class Customer implements DomainObject {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@Version
private Integer version;

private String firstName;
private String lastName;
private String email;
private String phoneNumber;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zipCode;

@Override
public Integer getId() {
return id;
}

@Override
public void setId(Integer id) {
this.id = id;
}

public Integer getVersion() {
return version;
}

public void setVersion(Integer version) {
this.version = version;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getAddressLine1() {
return addressLine1;
}

public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}

public String getAddressLine2() {
return addressLine2;
}

public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getZipCode() {
return zipCode;
}

public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
11 changes: 11 additions & 0 deletions src/main/java/guru/springframework/domain/DomainObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package guru.springframework.domain;

/**
* Created by jt on 11/14/15.
*/
public interface DomainObject {

Integer getId();

void setId(Integer id);
}
Loading