码迷,mamicode.com
首页 > 其他好文 > 详细

毕设日志(2)

时间:2017-04-08 22:14:24      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:nec   close   cto   form   add   show   date   cfg.xml   div   

 

哈哈哈哈,大哥技术还是不错的。厉害厉害。

 

1.单纯前端界面好好的,然而一旦有了前后端的交互,页面出现中文乱码问题。

  解决方案:

  servlet中:

   request.setCharacterEncoding("UTF-8");

   response.setCharacterEncoding("UTF-8");

2.NoClassDefFoundException

  原因:在编译环境中没有问题,但是部署到Web容器中就不行

  解决:在lib中加入jar包,加入buildPath

3.hibernate 5.7版本有些兼容性,新写法的问题!对了,最后不必手动session.close();

http://bbs.csdn.net/topics/391955731

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">xxxxxx</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        
        <mapping class="config.Students"/>
        <mapping resource="config/Students.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

JunitTest

 1 public class TestStudents {
 2 
 3     private SessionFactory sessionFactory;
 4     private Session session;
 5     private Transaction transaction;
 6 
 7     @Before
 8     public void init() {
 9         
10         // 获得 session工厂
11         sessionFactory = new Configuration().configure().buildSessionFactory();
12         // 获得 session
13         session = sessionFactory.getCurrentSession();
14         // 开启事务
15         transaction = session.beginTransaction();
16 
17     }
18 
19     @After
20     public void destory() {
21         transaction.commit(); // 提交事务
22 
23     }
24 
25     @Test
26     public void testSaveStudents() {
27         // 生成学生对象
28         Students students = new Students(2, "黄蓉", "女", new Date(), "桃花岛");
29         System.out.println(students.getSname() + students.getGender() + students.getAddress());
30         session.save(students); // 保存对象进入数据库
31     }
32 }

 

毕设日志(2)

标签:nec   close   cto   form   add   show   date   cfg.xml   div   

原文地址:http://www.cnblogs.com/vector11248/p/6683227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!