解决方案 »
- 在线等~~~~怎么在jsp页面新建一个按钮,点击后将页面中的table数据导出到excel中?
- POI问题老是出异常,JAVA高手帮忙!
- Unrecognized Spring element: name
- 大家看看这个!!Javascript ajax!!如何做!!
- 关于JAVA的一个小程序,功能是扫描本地计算机哪些端口正在使用,求解。。
- 求:时间数据的大小比较
- 一个Session的问题,请问
- 那里有JBuilder6.0下载?
- 请教如何处理JSP网页中的路径问题?
- 在jsp中怎样调用Bean
- eclipse修改发布路径到tomcat root目录下遇到一个问题 急!在线等。。
- 关于tomacat服务器的问题
下面是基本的几个项目文件:<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<context:annotation-config/>
<context:component-scan base-package="muyu"/>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="false">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="123"/>
<property name="initialSize" value="1"/>
<property name="maxIdle" value="2"/>
<property name="minIdle" value="1"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans><?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="muyu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>package muyu.service.product.impl;import java.util.UUID;import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import muyu.bean.product.Brand;
import muyu.dao.Daosuppot;
import muyu.service.product.BrandService;@Service
@Transactional
public class BrandServiceBean extends Daosuppot implements BrandService { @Override
public void sava(Object entity) {
((Brand)entity).setCode(UUID.randomUUID().toString());
super.sava(entity);
}
}
package muyu.service.product;import muyu.dao.DAO;public interface BrandService extends DAO{}
package muyu.bean.product;import java.io.Serializable;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;@Entity
public class Brand implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public Brand(String name, String logopath) {
this.name = name;
this.logopath = logopath;
}
public Brand() {
}
@Id @Column(length=36)
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Column(nullable=false,length=40)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(nullable=false)
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
@Column(length=3000)
public String getLogopath() {
return logopath;
}
public void setLogopath(String logopath) {
this.logopath = logopath;
}
private String code;
private String name;
private Boolean visible=true;
private String logopath;
}
注入需要 使用的dao把
@Service
@Transactional
public class BrandServiceBean extends Daosuppot implements BrandService {
@Autowired
Dao dao;
@Override
public void sava(Object entity) {
((Brand)entity).setCode(UUID.randomUUID().toString());
dao.sava(entity);
}
}