data rest crud, angular fe (#1199)

* data rest crud, angular fe

* fix formatting, remove extra imports

* fix config

* change student entity to employee

* expose ids

* update boot version, removes ids, check null id
This commit is contained in:
lor6
2017-02-27 17:04:00 +02:00
committed by KevinGilmore
parent 288d464e16
commit 8617faf9cf
11 changed files with 395 additions and 5 deletions
@@ -0,0 +1,14 @@
package org.baeldung.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class EmployeeController {
@RequestMapping(value = "/employeePage")
public String getEmployeePage() {
return "employee";
}
}
@@ -0,0 +1,13 @@
package org.baeldung.web.dao;
import java.util.List;
import org.baeldung.web.entity.Employee;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource(collectionResourceRel = "employee", path = "employees")
public interface EmployeeCRUDRepository extends CrudRepository<Employee, Long> {
List<Employee> findByName(@Param("name") String name);
}
@@ -3,6 +3,7 @@ package org.baeldung.web.dao;
import org.baeldung.web.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
public interface StudentRepository extends JpaRepository<Student, Long> {
public interface StudentRepository extends JpaRepository<Student, Long>
{
}
@@ -0,0 +1,57 @@
package org.baeldung.web.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Integer age;
public Employee() {
}
public Employee(long id, String name, Integer age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
@@ -0,0 +1,36 @@
package org.baeldung.web.main;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan("org.baeldung.web.controller")
public class MvcConfig extends WebMvcConfigurerAdapter{
public MvcConfig(){
super();
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/pages/");
bean.setSuffix(".html");
return bean;
}
}
@@ -2,7 +2,7 @@ package org.baeldung.web.main;
import javax.sql.DataSource;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -26,7 +26,7 @@ public class PersistenceConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).addScript("db/sql/data.sql").build();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).addScript("db/sql/data.sql").addScript("db/sql/employees.sql").build();
return db;
}