比如创建实体RoundC
1.实体包domain
创建实体类 RoundC
package com.mycompany.myapp.domain;
import javax.persistence.*;
/**
* Create by wys on 2018/7/22
*/
@Entity
@Table(name = "RoundC")
public class RoundC {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "radius")
private Double radius;
@Column(name = "perimeter")
private Double perimeter;
@Column(name = "pi")
private Double pi;
@Column(name = "n")
private Double n;
public RoundC() {};
public RoundC(Double radius,Double perimeter,Double pi,Double n) {
this.radius = radius;
this.perimeter = perimeter;
this.pi = pi;
this.n = n;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Double getRadius() {
return radius;
}
public void setRadius(Double radius) {
this.radius = radius;
}
public Double getPerimeter() {
return perimeter;
}
public void setPerimeter(Double perimeter) {
this.perimeter = perimeter;
}
public Double getPi() {
return pi;
}
public void setPi(Double pi) {
this.pi = pi;
}
public Double getN() {
return n;
}
public void setN(Double n) {
this.n = n;
}
@Override
public String toString() {
return "RoundC{" +
"id=" + id +
", radius=" + radius +
", perimeter=" + perimeter +
", pi=" + pi +
", n=" + n +
'}';
}
}
2.控制层包rest
创建控制层类 RoundCResource
package com.mycompany.myapp.web.rest;
import com.codahale.metrics.annotation.Timed;
import com.mycompany.myapp.domain.Round;
import com.mycompany.myapp.domain.RoundC;
import com.mycompany.myapp.service.RoundCService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Create by wys on 2018/7/22
*/
@RestController
@RequestMapping("/api")
public class RoundCResource {
private final Logger log = LoggerFactory.getLogger(RoundResource.class);
@Autowired
private RoundCService roundCService;
@PostMapping("/calculatePiC")
@Timed
public ResponseEntity<RoundC> calculatePi(@RequestParam double radius, @RequestParam double n) {
//double radius = 2;
log.debug("calculatePi to radius : {}",radius);
RoundC roundC;
roundC = roundCService.calculatePi(radius,n);
return ResponseEntity.ok()
.body(roundC);
}
}
- repository层包
创建类 RoundCRepository
package com.mycompany.myapp.repository;
import com.mycompany.myapp.domain.RoundC;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Create by wys on 2018/7/22
*/
@Repository
public interface RoundCRepository extends JpaRepository<RoundC,Long> {
}
- service层包
RoundCService
package com.mycompany.myapp.service;
import com.mycompany.myapp.domain.Round;
import com.mycompany.myapp.domain.RoundC;
import com.mycompany.myapp.repository.RoundCRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Create by wys on 2018/7/22
*/
@Service
public class RoundCService {
@Autowired
private RoundCRepository roundCRepository;
public RoundC calculatePi(double radius, double n) {
RoundC roundC = new RoundC(1d,2d,3d,4d);
roundCRepository.save(roundC);
return roundC;
}
}
- 找到配置文件添加一个xml配置文件
config CacheConfiguration cm.createCache(com.mycompany.myapp.domain.RoundC.class.getName(), jcacheConfiguration);
复制一个xml配置文件修改为实体的xml配置文件
20180722013637_added_entity_RoundC.xml
最后,注解,配置文件 写好,就可以自己手动创建