Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  5. <script src="form.js"></script>
  6. <meta charset="ISO-8859-1">
  7. <title>Insert title here</title>
  8. </head>
  9. <body ng-app="fapp">
  10. <div ng-controller="myctrl">
  11. <form >
  12. Email<input type="text" data-ng-model="x.email"></input>
  13. Password<input type="password" data-ng-model="x.password"></input>
  14. <button ng-click="SendData()">Submit</button>
  15. <div id="display"></div>
  16. </form>
  17.  
  18. </div>
  19. </body>
  20. </html>
  21.  
  22. angular.module("fapp",[]);
  23. angular.module("fapp").controller('myctrl',function($scope,$http){
  24.  
  25.  
  26.  
  27. $scope.SendData = function () {
  28. $http.post('/insert', $scope.x)
  29. .then(function (response) {
  30.  
  31. var stringData = JSON.stringify(response.data.email)
  32. var string = stringData.replace(/^"(.*)"$/, '$1');
  33. document.getElementById("display").innerHTML = string ;
  34.  
  35. },function(reason){
  36. console.log("fail")
  37. })
  38.  
  39. };
  40.  
  41. })
  42.  
  43. @RestController
  44. public class UserController {
  45.  
  46.  
  47. @Autowired
  48. public UserService service;
  49. @RequestMapping(value = "/insert" , method = RequestMethod.POST)
  50.  
  51. public @ResponseBody Users insert(@RequestBody Users user) {
  52.  
  53. String p=user.getPassword();
  54. String e=user.getEmail();
  55.  
  56.  
  57. return service.insert(e,p);
  58.  
  59. }
  60.  
  61. @RequestMapping("/")
  62. public String get() {
  63. return "form";
  64. }
  65.  
  66. }
  67.  
  68. package com.example.demo;
  69.  
  70. import org.jvnet.hk2.annotations.Service;
  71. import org.springframework.beans.factory.annotation.Autowired;
  72. import org.springframework.stereotype.Component;
  73. @Service
  74. @Component
  75. public class UserService {
  76. @Autowired
  77. public UserRepo dao;
  78.  
  79.  
  80. public Users insert(String email,String password) {
  81. // TODO Auto-generated method stub
  82. Users user = new Users(email,password);
  83. dao.save(user);
  84. return user;
  85.  
  86.  
  87. }
  88.  
  89.  
  90. }
  91.  
  92. package com.example.demo;
  93.  
  94. import org.springframework.data.repository.CrudRepository;
  95.  
  96. public interface UserRepo extends CrudRepository<Users,String>{
  97.  
  98. }
  99.  
  100. package com.example.demo;
  101.  
  102. // default package
  103. // Generated Aug 19, 2017 2:11:16 AM by Hibernate Tools 4.3.5.Final
  104.  
  105. import javax.persistence.Column;
  106. import javax.persistence.Entity;
  107. import javax.persistence.Id;
  108. import javax.persistence.Table;
  109.  
  110. /**
  111. * Users generated by hbm2java
  112. */
  113. @Entity
  114. @Table(name = "users", catalog = "getbenefit")
  115. public class Users implements java.io.Serializable {
  116.  
  117. private String email;
  118. private String password;
  119.  
  120. public Users() {
  121. }
  122.  
  123. public Users(String email) {
  124. this.email = email;
  125. }
  126.  
  127. public Users(String email, String password) {
  128. this.email = email;
  129. this.password = password;
  130. }
  131.  
  132. @Id
  133.  
  134. @Column(name = "email", unique = true, nullable = false, length = 22)
  135. public String getEmail() {
  136. return this.email;
  137. }
  138.  
  139. public void setEmail(String email) {
  140. this.email = email;
  141. }
  142.  
  143. @Column(name = "password", length = 22)
  144. public String getPassword() {
  145. return this.password;
  146. }
  147.  
  148. public void setPassword(String password) {
  149. this.password = password;
  150. }
  151.  
  152. }
  153.  
  154. spring.datasource.url=jdbc:mysql://localhost/dbname
  155. spring.datasource.username=****
  156. spring.datasource.password=****
  157. spring.datasource.driverClassName=com.mysql.jdbc.Driver
  158. spring.jpa.show-sql = true
  159. spring.jpa.hibernate.ddl-auto = update
  160. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement