Issue
I implemented jbpm business process in my springboot application and I am using its methods. I can't post my data in Mysql, I am using methods from another generated java classes and I need to use them. How can I change my code in the controller in the way that I can use these methods?
This is the Controller
'''
package com.iway.app.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iway.app.rest.model.EvaluationRequest;
import com.iway.rest.businesscentral.handler.ApiClient;
import com.iway.rest.businesscentral.handler.ProcessInstancesApi;
import org.springframework.web.bind.annotation.RequestBody;
import lombok.extern.slf4j.Slf4j;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
public class EvaluationRestController {
//@Autowired
//private ApiClient apiClient;
@Autowired
private ProcessInstancesApi processInstancesApi;
@CrossOrigin(origins = "*")
@PostMapping("/evaluation")
public ResponseEntity startEvaluationProcess(@RequestBody EvaluationRequest evaluationRequest) {
Long process = processInstancesApi.startProcess("evaluation_1.0.0-SNAPSHOT", "evaluation", evaluationRequest.toString());
System.out.println("Processus Started : "+process);
return ResponseEntity.ok(process);
}
}
'''
This is the Repository '''
package com.iway.app.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.iway.app.rest.model.EvaluationRequest;
public interface EvaluationRepository extends JpaRepository<EvaluationRequest, Long>{
}
'''
This is the Model
'''
package com.iway.app.rest.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.Gson;
@Entity
@Table(name = "Evaluation")
public class EvaluationRequest implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@JsonProperty("employee")
private String employee;
@JsonProperty("reason")
private String reason;
private long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "employee", nullable = false)
public String getEmployee() {
return employee;
}
public void setEmployee(String employee) {
this.employee = employee;
}
@Column(name = "reason", nullable = false)
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Override
public String toString() {
Gson gson = new Gson();
return gson.toJson(this);
}
}
'''
Solution
you have to save your parameters into the model class and call save function from repository class. Ex.
@Autowired
EvaluationRepository er;
Under ur System.out.println("Processus Started : "+process);
er.save(yourmodelclass);
Please refer this : https://www.codejava.net/frameworks/spring-boot/spring-boot-restful-crud-api-examples-with-mysql-database
Answered By - lee yiyang