I write lightweight km for self-development. Does not want to display parameters in the form -

if (document.getElementById("license_key_first")) { $.ajax({ type: "GET", url: "/api/cp/first", success: function (info) { $("#key_first").html(info.key_first); } }); } 

I get the data from the table, put bryaki, the server gets everything you need from the database.

Controller Code -

 @RestController @RequestMapping(path = "/api/cp") public class UserCpController { @Autowired private UserCpService service; @RequestMapping(method = RequestMethod.GET, path = "/first") public String getLicenseKeyFirst(@AuthenticationPrincipal UserDetailsDecorator currentUser) { return retriveText(service.getLicenseKeyFirst(currentUser.getEntity()).key_first); } @RequestMapping(method = RequestMethod.GET, path = "/second") public String getLicenseKeySecond(@AuthenticationPrincipal UserDetailsDecorator currentUser) { return retriveText(service.getLicenseKeySecond(currentUser.getEntity()).key_second); } @RequestMapping(method = RequestMethod.GET, path = "/period") public Timestamp getLicensePeriod(@AuthenticationPrincipal UserDetailsDecorator currentUser) { return service.getLicensePeriod(currentUser.getEntity()).period; } private String retriveText(String text) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { final char ch = text.charAt(i); if (!Character.isHighSurrogate(ch) && !Character.isLowSurrogate(ch)) { sb.append(ch); } } return sb.toString(); } } 

Service Code -

 @Service public class UserCpService { @Autowired private TblAccountRepository pcRepository; public CpLicenseInfo getLicenseKeyFirst(TblAccountEntity entity) { final CpLicenseInfo info = new CpLicenseInfo(); info.key_first = pcRepository.findBycAccId(entity.getcAccId()).getcLicenseKeyFirst(); return info; } public CpLicenseInfo getLicenseKeySecond(TblAccountEntity entity) { final CpLicenseInfo info = new CpLicenseInfo(); info.key_second = pcRepository.findBycAccId(entity.getcAccId()).getcLicenseKeySecond(); return info; } public CpLicenseInfo getLicensePeriod(TblAccountEntity entity) { final CpLicenseInfo info = new CpLicenseInfo(); info.period = pcRepository.findBycAccId(entity.getcAccId()).getcLicensePeriod(); return info; } } 

Pojo Information -

 public class CpLicenseInfo { public String key_first; public String key_second; public Timestamp period; } 

Module code where parameters are passed -

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <table class="table table-hover table-striped" id="license_key_first"> <tr> <th>Key: <strong id="key_first"/></th> </tr> </table> 

What am I doing wrong?

  • "Does not want to withdraw" - and what he wants? What is going on? Code $("#key_first").html(info.key_first); performed? - Igor
  • It seems that there is no @igor, the mapper displays to the log that the key is transferred to the page, but no actual result. I take the key for the user from the database and try to bring it to <strong id = "key_first" /> - GenCloud

1 answer 1

Solved by sending to pojo client side by json

 @RequestMapping(method = RequestMethod.GET, path = "/first") public @ResponseBody CpLicenseInfo getLicenseKeyFirst(@AuthenticationPrincipal UserDetailsDecorator currentUser) { return service.getLicenseKeyFirst(currentUser.getEntity()); } if (document.getElementById("license_key_first")) { $.ajax({ type: "GET", url: "/api/cp/first", dataType: 'json', contentType: 'application/json', mimeType: 'application/json', success: function (data) { var result = data.key_first; $("#key_first").text(result); } }); }