Guest User

Untitled

a guest
Nov 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. @Entity
  2. @Table(name="typedifficulte")
  3. public class Type {
  4.  
  5. @Id
  6. @GeneratedValue(strategy = GenerationType.AUTO)
  7. //@GeneratedValue(strategy = GenerationType.TABLE)
  8. private long idType;
  9. private String description;
  10.  
  11.  
  12. public String getDescription() {
  13. return description;
  14. }
  15. public void setDescription(String description) {
  16. this.description = description;
  17. }
  18.  
  19. public long getIdType() {
  20. return idType;
  21. }
  22. public void setIdType(long idType) {
  23. this.idType = idType;
  24. }
  25. }
  26.  
  27. import org.springframework.data.repository.CrudRepository;
  28. public interface TypeRepository extends CrudRepository<Type,Long> {
  29. Type findByDescription(String description);
  30. }
  31.  
  32. import java.util.Collection;
  33. public interface TypeService {
  34. Collection<Type> getAllTypes();
  35. }
  36.  
  37. import java.util.Collection;
  38. import javax.annotation.Resource;
  39. import org.apache.commons.collections4.IteratorUtils;
  40. import org.springframework.stereotype.Service;
  41.  
  42. @Service(value="typeService")
  43. public class TypeServiceImpl implements TypeService {
  44.  
  45. @Resource
  46. private TypeRepository typeRepository;
  47.  
  48. @Override
  49. public Collection<Type> getAllTypes() {
  50. return IteratorUtils.toList(this.typeRepository.findAll().iterator());
  51. }
  52. }
  53.  
  54. import org.springframework.web.bind.annotation.RequestMapping;
  55. import org.springframework.web.bind.annotation.RequestMethod;
  56. import org.springframework.web.bind.annotation.RestController;
  57.  
  58. @RestController
  59. public class TypeController {
  60.  
  61. @Resource
  62. private TypeService typeService;
  63.  
  64. @RequestMapping(value= "/getAllTypes", method = RequestMethod.GET)
  65. public Collection<Type> getAllTypes() {
  66. return this.typeService.getAllTypes();
  67. }
  68. }
  69.  
  70. spring:
  71. profile:dev
  72. datasource.url:jdbc:sqlite:C:Usersuser pcDesktopPDFtestrest.db
  73. datasource.driverClassName:org.sqlite.JDBC
  74. jpa:
  75. hibernate:
  76. hbm2ddl.auto:update
  77. properties:
  78. hibernate:
  79. dialect:org.hibernate.dialect.SQLiteDialect
  80. datasource:
  81. url:jdbc:sqlite:C:Usersuser pcDesktopPDFtestrest.db
  82. username:user
  83. password:user
  84. driverClassName:org.sqlite.JDBC
  85.  
  86. import org.springframework.boot.SpringApplication;
  87. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  88. import org.springframework.context.annotation.ComponentScan;
  89. import org.springframework.context.annotation.Configuration;
  90.  
  91. @Configuration
  92. @EnableAutoConfiguration
  93. @ComponentScan
  94. public class MainLauncher {
  95. public static void main(String[] args) {
  96. SpringApplication.run(MainLauncher.class, args);
  97. }
  98. }
Add Comment
Please, Sign In to add comment