IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA 实体类浅谈
一、实体类分析
一般用到的实体类的类型有
String类型、Long类型、Integer类型、Double类型、Date类型、DateTime类型、Text类型、Boolean型等
1、String类型的写法
@Column(nullable = false, length = 50)
public String mainName;
可以给字段设置两种权限,private和public两种,使用private时候要使用getter and setter,而使用public的时候不需要使用。
String类型作为普通字段的设置,可以采用@Column注解,属性可以填充name(字段名称)、length(长度)、nullable(字段是否为空,false不为空)、columnDefinition(拼接的ddl,就是sql语句)
加上这些字段的public完整设置(这些事比较常用的)
@Column(nullable = false, length = 50,name = "mainName",columnDefinition = "COMMENT '名称'")
public String mainName;
注意:
当String作为主键的时候,设置如下:
@Id
@GenericGenerator(strategy = "uuid", name = "mainId")
@GeneratedValue(generator = "mainId")
@Column(length = 40)
public String mainId;
2、Long类型
一般用法跟String基本一样
@Column(name = "id",nullable = false,columnDefinition = "DEFAULT '1'",length = 50)
public Long id;
作为主键用法:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;
3、Integer类型
@Column(columnDefinition = "int(1) DEFAULT '1'",nullable = false,name = "deleted")
public Integer deleted;
作为主键:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer id;
4、double类型
一般情况:
@Column(name = "priceCoefficient", columnDefinition = "decimal(50,4) default 1.0000 COMMENT '价格系数'",nullable = false)
public double priceCoefficient;
5、date类型
一般情况:
@Temporal(TemporalType.DATE)
public Date trueTime;
6、DateTime类型
@Temporal(TemporalType.TIMESTAMP)
public Date createTime;
7、Text类型
@Lob
@Basic(fetch=FetchType.LAZY)
private String words;
8、Boolean型
@org.hibernate.annotations.Type(type="yes_no")
private boolean manageLog = false;
IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA 实体类浅谈的更多相关文章
- IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA环境搭建,JPA实现非字符型设置长度
1.在github上已有配置环境,如下链接,(需要环境JDK1.8及以上版本,Tomcat1.8及以上版本,搭建maven库,使用编译器IntellJ IDEA) https://github.com ...
- IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA sort排序方法使用方式, 添加关联表的 order by
1.sort可以直接添加在命名格式的字段中 List<BomMain> findAllByDeleted(Integer deleted, Sort sort); 2.可以作为pageab ...
- IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA环境搭建,JPA注解@ManyToOne使用详情;JPA外键设置
一.数据库原型 数据库模型如图所示,而现在需要根据数据库模型,建立对应的实体类,这在项目重构老数据库,采用新的框架重构上应该是比较常见的. 数据库脚本如下: CREATE TABLE `bomsub` ...
- Spring Boot2.0以上版本EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替代
在Spring Boot2.0以上配置嵌入式Servlet容器时EmbeddedServletContainerCustomizer类不存在,经网络查询发现被WebServerFactoryCusto ...
- Spring Boot2.0 设置拦截器
所有功能完成 配置登录认证 配置拦截器 在spring boot2.0 之后 通过继承这个WebMvcConfigurer类 就可以完成拦截 新建包com.example.interceptor; 创 ...
- Spring Boot2.0 静态资源被拦截问题
在Spring Boot2.0+的版本中,只要用户自定义了拦截器,则静态资源会被拦截.但是在spring1.0+的版本中,是不会拦截静态资源的. 因此,在使用Spring Boot2.0+时,配置拦截 ...
- Spring Boot2.0使用Spring Security
一.Spring Secutity简介 Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性 ...
- spring boot2.0(一 ) 基础环境搭建
1.基础配置 开发环境:window jdk版本:1.8(spring boot2.0最低要求1.8) 开发工具:eclipse 构建方式:maven3 2.POM配置文件 <project x ...
- Spring Boot2.0 整合 Kafka
Kafka 概述 Apache Kafka 是一个分布式流处理平台,用于构建实时的数据管道和流式的应用.它可以让你发布和订阅流式的记录,可以储存流式的记录,并且有较好的容错性,可以在流式记录产生时就进 ...
随机推荐
- f5 Seldom used
1.负载均衡算法 2)最快响应速度(Fastest) •优先查看7层请求的连接数,然后查看4层连接数 •需要在virtual server上关联7层的profile,否则与最小连接数相同 •后台服务器 ...
- python函数传入参数(默认参数、可变长度参数、关键字参数)
1.python中默认缺省参数----定义默认参数要牢记一点:默认参数必须指向不变对象! 1 def foo(a,b=1): 2 print a,b 3 4 foo(2) #2 1 5 foo(3,1 ...
- how2j网站前端项目——天猫前端(第一次)学习笔记8
其他页面的学习 这些页面有1.查询结果页 2.支付页面 3.支付成功页面 4.确认收货页面上 5.确认收货页面下 6.收获成功页面 7.评价页面上 8.评价页面下 9.登陆页面 10.注册页面 1.查 ...
- Sqlserver的身份验证模式
1.服务器名称: . 在服务器名称这里,我们有以下几种选择来连接到本地: (1)默认的服务器名称:也就是电脑主机的名称 (2)".",“.”就表示主机. (3)localhost ...
- 详解Cookie纪要
参考文档链接:http://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651552892&idx=1&sn=126a1d32 ...
- Python 内置函数 memoryview
转载自:https://www.cnblogs.com/sesshoumaru/p/6035548.html 英文文档: class memoryview(obj) memoryview object ...
- iOS.Animation.CAMediaTiming
CAMediaTiming Protocol CALayre 和 CAAnimation 实现了CAMediaTiming 接口. CAMediaTiming 定义了8个属性. speed属性: Co ...
- The valid characters are defined in RFC 7230 and RFC 3986问题
这个问题困扰了我接近两天了!尼玛!网上搜了很多资料,有的给出了解决方案,然后下面的评论说按照楼主做的,没有成功,我一做也确实没有成功.设置了断点,一步一步跟进去看,还是没有头绪.不过有一点可以确认的是 ...
- 还没有写完准备弡上cpickle 还有字典
#!/usr/bin/python #Filename: cpickle.py import cPickle as p import os shoplistfile="shoplist.da ...
- 201621123008 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...