0% found this document useful (0 votes)
8 views3 pages

Jpa Example

Uploaded by

madhan.780890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Jpa Example

Uploaded by

madhan.780890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

application.

properties
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=ragu
spring.datasource.password=ragu1234
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

controller
@Controller
public class HomeController {
@Autowired
ExampleService exampleService;

@RequestMapping("/")
public String home() {
return "index";
}

@PostMapping("/add")
public String add(Example example) {
exampleService.saveExample(example);
return "Added";
}
}

Model

@Entity
@Table(name = "Example_JPA")
public class Example {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private int EmpId;
private String Name_;
private int Age;
private String Address;

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public int getEmpId() {


return EmpId;
}

public void setEmpId(int empId) {


EmpId = empId;
}
public String getName_() {
return Name_;
}

public void setName_(String name_) {


Name_ = name_;
}

public int getAge() {


return Age;
}

public void setAge(int age) {


Age = age;
}

public String getAddress() {


return Address;
}

public void setAddress(String address) {


Address = address;
}
}

Service

@Service
public class ExampleService {
@Autowired
ExampleResp exampleResp;
public void saveExample(Example example) {
exampleResp.save(example);
}
}

Repository
@Repository
public interface ExampleResp extends JpaRepository<Example, Integer> {
}

index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<form action="add" method="post">


EmpId<input type="text" name="EmpId"><br><br>
Name<input type="text" name="Name_"><br><br>
Age<input type="text" name="Age"><br><br>
Address <input type="text" name="Address"><br><br>
<input type="submit" value="Add">
</form>

</body>
</html>

Added.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Inserted Successfully
</body>
</html>

You might also like