jhipster 自己手动创建实体

比如创建实体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);
    }

}

  1. 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> {
}

  1. 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;
    }

}

  1. 找到配置文件添加一个xml配置文件
    config CacheConfiguration cm.createCache(com.mycompany.myapp.domain.RoundC.class.getName(), jcacheConfiguration);

复制一个xml配置文件修改为实体的xml配置文件
20180722013637_added_entity_RoundC.xml

最后,注解,配置文件 写好,就可以自己手动创建

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值