表结构快速生成java_对象创建,表结构就会自动生成

1.目录

4c1a3833d88506f8574b6635eb015c6e.png

2.user.java

f12d4a9165be0c481992f693fe5165bc.png

45d4990ca000170a06f9b53d87e16a39.png

1 package com.itheima.domain;

2

3 public class user {

4

5 private integer id;

6 private string name;

7 private integer age;

8 public integer getid() {

9 return id;

10 }

11 public void setid(integer id) {

12 this.id = id;

13 }

14 public string getname() {

15 return name;

16 }

17 public void setname(string name) {

18 this.name = name;

19 }

20 public integer getage() {

21 return age;

22 }

23 public void setage(integer age) {

24 this.age = age;

25 }

26

27 }

view code

3.user.hbm.xml

f12d4a9165be0c481992f693fe5165bc.png

45d4990ca000170a06f9b53d87e16a39.png

1 <?xml version="1.0" encoding="utf-8"?>

2 /p>

3 "-//hibernate/hibernate mapping dtd 3.0//en"

4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

5

6

7

8

11

12

13

14

15

16

view code

4.hibernate.cfg.xml配置文件

f12d4a9165be0c481992f693fe5165bc.png

45d4990ca000170a06f9b53d87e16a39.png

1 <?xml version="1.0" encoding="utf-8"?>

2 /p>

3 "-//hibernate/hibernate configuration dtd 3.0//en"

4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

5

6

7

8

9

10

11

12 com.mysql.jdbc.driver

13 jdbc:mysql:///hibernate_day02

14 root

15 123456

16

17

18 org.hibernate.dialect.mysqldialect

19

20

21 true

22

23 true

24

27 update

28

29

32

33

34 thread

35

36

37

38

39

40

41

view code

5.运行hibernateutils.java的主方法,就可以直接通过对象在数据库中简历数据表

f12d4a9165be0c481992f693fe5165bc.png

45d4990ca000170a06f9b53d87e16a39.png

1 package com.itheima.utils;

2

3 import javax.servlet.jsp.jstl.core.config;

4

5 import org.hibernate.session;

6 import org.hibernate.sessionfactory;

7 import org.hibernate.cfg.configuration;

8

9 /*

10 * hibernate框架的工具

11 * @author chenyanlong

12 */

13 public class hibernateutils {

14

15 //curl+shift+x

16 private static final configuration config;

17 private static final sessionfactory factory;

18

19 //编写静态代码

20 static {

21 //加载配置文件

22 config =new configuration().configure();

23 //构造工厂

24 factory=config.buildsessionfactory();

25 }

26

27 /*

28 * 从工厂获取session对象

29 * @return

30 */

31 public static session getsession() {

32 return factory.opensession();

33

34 }

35

36

37 /**

38 * // 从threadlocal类中获取到session的对象

39 * @return

40 */

41 public static session getcurrentsession(){

42 return factory.getcurrentsession();

43 }

44 public static void main(string[] args) {

45 //调用获取session的方法

46 getsession();

47 }

48 }

view code

6.显示效果

b3581ace2461eedfaf01583354f62c10.png

希望与广大网友互动??

点此进行留言吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值