initial commit
Este commit está contenido en:
14
src/main/java/com/manalejandro/mongodbcrud/MongodbcrudApplication.java
Archivo normal
14
src/main/java/com/manalejandro/mongodbcrud/MongodbcrudApplication.java
Archivo normal
@@ -0,0 +1,14 @@
|
||||
package com.manalejandro.mongodbcrud;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMongoRepositories(basePackages = { "com.manalejandro.mongodbcrud.repositories" })
|
||||
public class MongodbcrudApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MongodbcrudApplication.class, args);
|
||||
}
|
||||
}
|
||||
13
src/main/java/com/manalejandro/mongodbcrud/ServletInitializer.java
Archivo normal
13
src/main/java/com/manalejandro/mongodbcrud/ServletInitializer.java
Archivo normal
@@ -0,0 +1,13 @@
|
||||
package com.manalejandro.mongodbcrud;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(MongodbcrudApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.manalejandro.mongodbcrud.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.manalejandro.mongodbcrud.forms.IndexForm;
|
||||
import com.manalejandro.mongodbcrud.model.Item;
|
||||
import com.manalejandro.mongodbcrud.services.ItemService;
|
||||
import com.manalejandro.mongodbcrud.vo.IndexVO;
|
||||
|
||||
@Controller
|
||||
public class IndexController implements ErrorController {
|
||||
|
||||
private ItemService itemService;
|
||||
|
||||
@Autowired
|
||||
public IndexController(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index(final @ModelAttribute IndexForm indexForm, final Model model) {
|
||||
IndexVO indexVO = new IndexVO();
|
||||
if (indexForm.getId() == null) {
|
||||
indexVO.getListItem().addAll(itemService.getAll());
|
||||
} else {
|
||||
Item item = itemService.getItem(indexForm.getId());
|
||||
indexForm.setId(item.getId());
|
||||
indexForm.setNombre(item.getNombre());
|
||||
indexForm.setApellido1(item.getApellido1());
|
||||
indexForm.setApellido2(item.getApellido2());
|
||||
}
|
||||
model.addAttribute("indexVO", indexVO);
|
||||
return "index";
|
||||
}
|
||||
|
||||
public String getErrorPath() {
|
||||
return "error";
|
||||
}
|
||||
|
||||
}
|
||||
41
src/main/java/com/manalejandro/mongodbcrud/forms/IndexForm.java
Archivo normal
41
src/main/java/com/manalejandro/mongodbcrud/forms/IndexForm.java
Archivo normal
@@ -0,0 +1,41 @@
|
||||
package com.manalejandro.mongodbcrud.forms;
|
||||
|
||||
public class IndexForm {
|
||||
|
||||
private String id;
|
||||
private String nombre;
|
||||
private String apellido1;
|
||||
private String apellido2;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellido1() {
|
||||
return apellido1;
|
||||
}
|
||||
|
||||
public void setApellido1(String apellido1) {
|
||||
this.apellido1 = apellido1;
|
||||
}
|
||||
|
||||
public String getApellido2() {
|
||||
return apellido2;
|
||||
}
|
||||
|
||||
public void setApellido2(String apellido2) {
|
||||
this.apellido2 = apellido2;
|
||||
}
|
||||
}
|
||||
56
src/main/java/com/manalejandro/mongodbcrud/model/Item.java
Archivo normal
56
src/main/java/com/manalejandro/mongodbcrud/model/Item.java
Archivo normal
@@ -0,0 +1,56 @@
|
||||
package com.manalejandro.mongodbcrud.model;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
public class Item {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String nombre;
|
||||
private String apellido1;
|
||||
private String apellido2;
|
||||
|
||||
public Item() {
|
||||
super();
|
||||
};
|
||||
|
||||
public Item(String nombre, String apellido1, String apellido2) {
|
||||
this.nombre = nombre;
|
||||
this.apellido1 = apellido1;
|
||||
this.apellido2 = apellido2;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellido1() {
|
||||
return apellido1;
|
||||
}
|
||||
|
||||
public void setApellido1(String apellido1) {
|
||||
this.apellido1 = apellido1;
|
||||
}
|
||||
|
||||
public String getApellido2() {
|
||||
return apellido2;
|
||||
}
|
||||
|
||||
public void setApellido2(String apellido2) {
|
||||
this.apellido2 = apellido2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.manalejandro.mongodbcrud.repositories;
|
||||
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.manalejandro.mongodbcrud.model.Item;
|
||||
|
||||
@Repository
|
||||
public interface ItemRepository extends MongoRepository<Item, String> {
|
||||
}
|
||||
13
src/main/java/com/manalejandro/mongodbcrud/services/ItemService.java
Archivo normal
13
src/main/java/com/manalejandro/mongodbcrud/services/ItemService.java
Archivo normal
@@ -0,0 +1,13 @@
|
||||
package com.manalejandro.mongodbcrud.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.manalejandro.mongodbcrud.model.Item;
|
||||
|
||||
public interface ItemService {
|
||||
|
||||
public Item getItem(String id);
|
||||
|
||||
public List<Item> getAll();
|
||||
|
||||
}
|
||||
28
src/main/java/com/manalejandro/mongodbcrud/services/ItemServiceImpl.java
Archivo normal
28
src/main/java/com/manalejandro/mongodbcrud/services/ItemServiceImpl.java
Archivo normal
@@ -0,0 +1,28 @@
|
||||
package com.manalejandro.mongodbcrud.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.manalejandro.mongodbcrud.model.Item;
|
||||
import com.manalejandro.mongodbcrud.repositories.ItemRepository;
|
||||
|
||||
@Service
|
||||
public class ItemServiceImpl implements ItemService {
|
||||
|
||||
private ItemRepository itemRepository;
|
||||
|
||||
@Autowired
|
||||
public ItemServiceImpl(ItemRepository itemRepository) {
|
||||
this.itemRepository = itemRepository;
|
||||
}
|
||||
|
||||
public List<Item> getAll() {
|
||||
return this.itemRepository.findAll();
|
||||
}
|
||||
|
||||
public Item getItem(String id) {
|
||||
return this.itemRepository.findById(id).isPresent() ? this.itemRepository.findById(id).get() : null;
|
||||
}
|
||||
}
|
||||
56
src/main/java/com/manalejandro/mongodbcrud/vo/IndexVO.java
Archivo normal
56
src/main/java/com/manalejandro/mongodbcrud/vo/IndexVO.java
Archivo normal
@@ -0,0 +1,56 @@
|
||||
package com.manalejandro.mongodbcrud.vo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.manalejandro.mongodbcrud.model.Item;
|
||||
|
||||
public class IndexVO {
|
||||
|
||||
private List<Item> listItem = new ArrayList<Item>();
|
||||
private String id;
|
||||
private String nombre;
|
||||
private String apellido1;
|
||||
private String apellito2;
|
||||
|
||||
public List<Item> getListItem() {
|
||||
return listItem;
|
||||
}
|
||||
|
||||
public void setListItem(List<Item> listItem) {
|
||||
this.listItem = listItem;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getApellido1() {
|
||||
return apellido1;
|
||||
}
|
||||
|
||||
public void setApellido1(String apellido1) {
|
||||
this.apellido1 = apellido1;
|
||||
}
|
||||
|
||||
public String getApellito2() {
|
||||
return apellito2;
|
||||
}
|
||||
|
||||
public void setApellito2(String apellito2) {
|
||||
this.apellito2 = apellito2;
|
||||
}
|
||||
|
||||
}
|
||||
2
src/main/resources/application.properties
Archivo normal
2
src/main/resources/application.properties
Archivo normal
@@ -0,0 +1,2 @@
|
||||
server.servlet.context-path=/mongodbcrud
|
||||
server.port=3117
|
||||
10
src/main/resources/templates/error.html
Archivo normal
10
src/main/resources/templates/error.html
Archivo normal
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Error</title>
|
||||
</head>
|
||||
<body>
|
||||
Error
|
||||
</body>
|
||||
</html>
|
||||
10
src/main/resources/templates/index.html
Archivo normal
10
src/main/resources/templates/index.html
Archivo normal
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.manalejandro.mongodbcrud;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MongodbcrudApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Referencia en una nueva incidencia
Block a user