Java web ssh框架实现点击数这个功能
这个点击数要存到数据库,然后从数据库中拿?还是直接可以在jsp页面可以直接得到。
我用的是el表达式 展开
一个简单的用户登录。创建好一个web工程后,添加为Spring工程添加hibernate工程是会将hibernate.cfg.xml集成到applicationContext中既然是用户登录首先需要一个实体类。
[html] view plain copy
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<span style="white-space:pre"> </span><!--连接数据库-->
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/demo"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean>
<span style="white-space:pre"> </span><!-- 配置会话工厂 <span style="font-family: Arial, Helvetica, sans-serif;">LocalSessionFactoryBean 不能使用注解</span><span style="font-family: Arial, Helvetica, sans-serif;"> --></span>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<span style="white-space:pre"> </span><!--将<span style="font-family: Arial, Helvetica, sans-serif;">dataSource注入到sessionFactory中</span>-->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
<prop key="hibernate.format_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<span style="white-space:pre"> </span><!--hibernate中的maping映射位置-->
<value>com/entity/User.hbm.xml</value>
</list>
</property>
</bean>
package com.entity;
/**
* User entity. @author MyEclipse Persistence Tools
*/
public class User implements java.io.Serializable {
// Fields
/**
*
*/
private static final long serialVersionUID = 4585221013478533506L;
private Integer id;
private String username;
private String password;
// Constructors
/** default constructor */
public User() {
}
/** full constructor */
public User(String username, String password) {
this.username = username;
this.password = password;
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
- 与数据库建立关系映射User.hbm.xml
<hibernate-mapping>
<class name="com.entity.User" table="user" catalog="demo">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="20" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="20" />
</property>
</class>
</hibernate-mapping>
[html] view plain copy
[html] view plain copy
[html] view plain copy
[html] view plain copy
建立实体类User.java
[html] view plain copy
[html] view plain copy