springmvc + hibernate + jpa 事务提交问题,无法insert,但是可以查询。

Allen_Chao 2015-02-04 10:42:29
最近在学习 springmvc hibernate jpa 的配置,但是配置好之后在进行数据提交的时候总是无法插入到数据库,事务也都配置好了,service类中也有添加@Transactional标注,数据可以查询,求大侠帮忙指教,在此拜谢
spring 相关配置: application-context.xml

<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"
default-lazy-init="true">

<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
<context:component-scan base-package="com.skynet.cdw" />

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}" />
<property name="initialPoolSize" value="${cpool.minPoolSize}" />
<property name="minPoolSize" value="${cpool.minPoolSize}" />
<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
</bean>

<!-- Jpa Entity Manager 配置 -->
<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="packagesToScan" value="com.skynet.cdw.**.entity"/> -->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="generateDdl" value="false" />
</bean>
</property>
</bean>


<!-- 事务管理器配置, Jpa单数据源事务 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<!-- 使用annotation定义事务 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="*" propagation="REQUIRED" isolation="READ_COMMITTED" read-only="true"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="serviceMethod" expression="execution(* com.skynet.cdw..service..*.*(..))"/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
</aop:config>

<!-- 整个平台的安全框架考虑使用 spring security框架来做 ,基础框架阶段暂时不需要启用-->
<!-- <import resource="spring-security.xml"/> -->
</beans>



jpa相关配置:persistence.xml
<?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 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="cdwPersistence"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.skynet.cdw.platform.entity.Resource</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.jdbc.fetch_size" value="50" />
<property name="hibernate.jdbc.batch_size" value="50" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>



底层dao代码:BaseDaoImpl.java

package com.skynet.cdw.common.dao;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;

import org.springframework.util.Assert;

/**
* 底层数据持久层公共实现类
* @param <T> 实体类型
* @param <ID> 主键类型
*/
public class BaseDaoImpl<T, ID extends Serializable> implements BaseDao<T, ID>
{
private Class<T> persistentClass;

@PersistenceContext(type = PersistenceContextType.TRANSACTION)
private EntityManager em;

@SuppressWarnings({"unchecked", "rawtypes"})
public BaseDaoImpl()
{
this.persistentClass =
(Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}

public Class<T> getPersistentClass()
{
return persistentClass;
}

/**
* 对象实体 持久化操作
*/
public T save(T entity)
{
Assert.notNull(entity, "entity 不能为 null");
em.persist(entity);
return (T)entity;
}

/**
* 对象实体 持久化更新
*/
public T update(T entity)
{
Assert.notNull(entity, "entity 不能为 null");
em.merge(entity);
return (T)entity;
}

/**
* 删除操作
*/
public void delete(T entity)
{
Assert.notNull(entity, "entity 不能为 null");
em.remove(entity);
}

/**
* 根据ID主键进行查询
*/
public T findById(ID id)
{
Assert.notNull(id, "id 不能为空");
return (T)em.find(getPersistentClass(), id);
}

/**
* 根据id数组进行查询
* idName : ids 对应的属性名称
*/
@SuppressWarnings("unchecked")
public List<T> findByIds(String idName, ID[] ids)
{
Assert.notEmpty(ids, "ids 不能为空");
String hql = "from " + getPersistentClass().getName() + " as model where model." + idName + " in(:ids)";
return em.createQuery(hql).setParameter("ids", ids).getResultList();
}
/**
* 进行原始sql查询
*
* @param sql
* @return
*/
@SuppressWarnings("unchecked")
public List<T> createQuery(String sql)
{
Assert.notNull(sql, "sql 不能为 null");
Query query = em.createQuery(sql);
if (query != null)
{
return query.getResultList();
}
return new ArrayList<T>();
}

/**
* 查询所有数据
*/
@SuppressWarnings("unchecked")
public List<T> findAll()
{
StringBuffer sql = new StringBuffer("from ");
sql.append(getPersistentClass().getName());
sql.append(" obj");
return em.createQuery(sql.toString()).getResultList();
}

/**
* 获取总记录数
*/
public int findRowCount()
{
StringBuffer sql = new StringBuffer("select count(*) from ");
sql.append(getPersistentClass().getName());
sql.append(" obj");
Object object = em.createQuery(sql.toString()).getResultList().get(0);
if (object != null)
{
return Integer.parseInt(object.toString());
}
return 0;
}

/**
* 根据传入的sql进行更新操作
*/
@SuppressWarnings("rawtypes")
public Integer updateBySql(String sql, Class cls)
{
Assert.notNull(sql, "sql 不能为 null");
Assert.notNull(cls, "cls 不能为 null");
Query query = em.createNativeQuery(sql, cls);
return query.executeUpdate();
}

}


业务DAO实现类:ResourceDaoImpl.java

package com.skynet.cdw.platform.dao.impl;

import org.springframework.stereotype.Repository;

import com.skynet.cdw.common.dao.BaseDaoImpl;
import com.skynet.cdw.platform.dao.ResourceDao;
import com.skynet.cdw.platform.entity.Resource;

@Repository
public class ResourceDaoImpl extends BaseDaoImpl<Resource, Integer> implements ResourceDao
{

}



...全文
708 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
iker11 2017-10-24
  • 打赏
  • 举报
回复
楼主解决了么,同求
boybaozi 2015-02-05
  • 打赏
  • 举报
回复
没报错只是数据插不到数据库?
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
哪位 大哥 给解答一下
轩辕敬城 2015-02-05
  • 打赏
  • 举报
回复
这个别人也没法去测试,就是事物不起作用导致的,你可以自己写个测试类,测试看看你的事物配置,可以分别用注解和配置文件的方式来测试。
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
引用 10 楼 z_yes163 的回复:
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd " default-lazy-init="false"> <description>Spring公共配置</description> <!-- 定义受环境影响易变的变量 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 数据库配置--> <value>classpath*:jdbc.properties</value> <!-- 系统配置 --> <!-- <value>classpath*:config.properties</value> --> </list> </property> </bean> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <context:component-scan base-package="com.evo.bpc" annotation-config="true"/> <!--自动扫描定时任务 --> <task:annotation-driven/> <!-- 数据源配置,使用应用内的DBCP数据库连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!--Connection Info--> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!--Connection Pooling Info to C3p0--> <property name="acquireIncrement" value="${c3p0.acquireIncrement}" /> <property name="initialPoolSize" value="${c3p0.initialPoolSize}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}" /> <property name="minPoolSize" value="${c3p0.minPoolSize}" /> <property name="maxIdleTime" value="${c3p0.maxIdleTime}" /> <property name="maxStatements" value="${c3p0.maxStatements}" /> <property name="maxStatementsPerConnection" value="${c3p0.maxStatementsPerConnection}" /> <property name="statementCacheNumDeferredCloseThreads" value="${c3p0.statementCacheNumDeferredCloseThreads}" /><!-- set to 1 --> <property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}" /> </bean> <!-- Hibernate配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> ${hibernate.dialect} </prop> <prop key="hibernate.show_sql"> ${hibernate.show_sql} </prop> <prop key="hibernate.format_sql"> ${hibernate.format_sql} </prop> <prop key="hibernate.jdbc.fetch_size"> ${hibernate.jdbc.fetch_size} </prop> <prop key="hibernate.jdbc.batch_size"> ${hibernate.jdbc.batch_size} </prop> <prop key="hibernate.current._session_context_class"> thread </prop> <!--hibernate 是否使用二级缓存 预留在此 --> <!-- <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop> --> </props> </property> <property name="packagesToScan" value="com.evo.bpc.entity" /> //扫描实体javabean </bean> <!-- 事务管理器配置,单数据源事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:aspectj-autoproxy /> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans> 以上 是 现在项目使用的 @Entity 扫描支持jpa @Table(name = "admire") public class Admire implements java.io.Serializable @Service @Transactional 事务管理 public class AdmireServiceImpl implements AdmireService @Controll AdmireAction 很简单 请把 xml配置 和 自动扫描 分清楚
嗯嗯 您的意思我明白,当时发帖的时候换了一种方式测试的,所以service类里的事务标注就没有删除,不好意思。
z_yes163 2015-02-05
  • 打赏
  • 举报
回复
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd " default-lazy-init="false"> <description>Spring公共配置</description> <!-- 定义受环境影响易变的变量 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 数据库配置--> <value>classpath*:jdbc.properties</value> <!-- 系统配置 --> <!-- <value>classpath*:config.properties</value> --> </list> </property> </bean> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <context:component-scan base-package="com.evo.bpc" annotation-config="true"/> <!--自动扫描定时任务 --> <task:annotation-driven/> <!-- 数据源配置,使用应用内的DBCP数据库连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!--Connection Info--> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!--Connection Pooling Info to C3p0--> <property name="acquireIncrement" value="${c3p0.acquireIncrement}" /> <property name="initialPoolSize" value="${c3p0.initialPoolSize}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}" /> <property name="minPoolSize" value="${c3p0.minPoolSize}" /> <property name="maxIdleTime" value="${c3p0.maxIdleTime}" /> <property name="maxStatements" value="${c3p0.maxStatements}" /> <property name="maxStatementsPerConnection" value="${c3p0.maxStatementsPerConnection}" /> <property name="statementCacheNumDeferredCloseThreads" value="${c3p0.statementCacheNumDeferredCloseThreads}" /><!-- set to 1 --> <property name="autoCommitOnClose" value="${c3p0.autoCommitOnClose}" /> </bean> <!-- Hibernate配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> ${hibernate.dialect} </prop> <prop key="hibernate.show_sql"> ${hibernate.show_sql} </prop> <prop key="hibernate.format_sql"> ${hibernate.format_sql} </prop> <prop key="hibernate.jdbc.fetch_size"> ${hibernate.jdbc.fetch_size} </prop> <prop key="hibernate.jdbc.batch_size"> ${hibernate.jdbc.batch_size} </prop> <prop key="hibernate.current._session_context_class"> thread </prop> <!--hibernate 是否使用二级缓存 预留在此 --> <!-- <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop> --> </props> </property> <property name="packagesToScan" value="com.evo.bpc.entity" /> //扫描实体javabean </bean> <!-- 事务管理器配置,单数据源事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:aspectj-autoproxy /> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans> 以上 是 现在项目使用的 @Entity 扫描支持jpa @Table(name = "admire") public class Admire implements java.io.Serializable @Service @Transactional 事务管理 public class AdmireServiceImpl implements AdmireService @Controll AdmireAction 很简单 请把 xml配置 和 自动扫描 分清楚
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
引用 8 楼 kky2010_110 的回复:
事务冲突了吧,一会儿注解,一会儿事务拦截,把注解去掉试一试@Transactional
对于采用哪一种方式 我在测试过程中一直是使用一种方式的,代码中也是,所以应该不会是这个问题吧
kky2010_110 2015-02-05
  • 打赏
  • 举报
回复
事务冲突了吧,一会儿注解,一会儿事务拦截,把注解去掉试一试@Transactional
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
引用 6 楼 ljjlt17 的回复:
第一个你看看spring-servlet.xml这个文件有没有只拦截controller这个注解,如果没有注明,他会拦截service这个注解,导致无法插入,spring-servlet.xml这个负责拦截controller,applicationContext负责拦截service和dao,这个要配置好,还不行的话,你在看看<!-- 使用annotation定义事务 -->这个,去掉注释

    <!-- 自动扫描的包名 -->
    <context:component-scan base-package="com.skynet.cdw.platform.**" ></context:component-scan>
    
    <!-- 默认的注解映射的支持 -->
    <mvc:annotation-driven />
    
    <!-- 视图解释类 -->
	<bean id="freemarkerViewResolver" class="com.skynet.cdw.common.springmvc.SimpleFreeMarkerViewResolver">
		<property name="suffix" value=".html"/>
		<property name="contentType" value="text/html; charset=UTF-8"/>
		<property name="exposeRequestAttributes" value="false"/>
		<property name="exposeSessionAttributes" value="false"/>
		<property name="exposeSpringMacroHelpers" value="true"/>
	</bean>
	
	<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<!-- 将页面模板定义到jar包下,模块化方便管理和扩展 -->
		<property name="templateLoaderPath" value="/WEB-INF/page/admin/"/>
		<property name="freemarkerVariables">
			<map>
				<!-- 将默认的根路径存入到request中  -->
				<entry key="appBase" value="/admin/"/>
			</map>
		</property>
		<property name="freemarkerSettings">
			<props>
				<prop key="template_update_delay">0</prop>
				<prop key="defaultEncoding">UTF-8</prop>
				<prop key="locale">zh_CN</prop>
				<prop key="boolean_format">true,false</prop>
				<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
				<prop key="date_format">yyyy-MM-dd</prop>
				<prop key="time_format">HH:mm:ss</prop>
				<prop key="number_format">0.######</prop>
				<prop key="whitespace_stripping">true</prop>
				<!-- <prop key="auto_import">/ftl/jeecms/index.ftl as p,/ftl/spring.ftl as s</prop> -->
			</props>
		</property>
	</bean>
ljjlt17 2015-02-05
  • 打赏
  • 举报
回复
第一个你看看spring-servlet.xml这个文件有没有只拦截controller这个注解,如果没有注明,他会拦截service这个注解,导致无法插入,spring-servlet.xml这个负责拦截controller,applicationContext负责拦截service和dao,这个要配置好,还不行的话,你在看看<!-- 使用annotation定义事务 -->这个,去掉注释
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
找了好多资料 ,似乎都没有相关的问题
Allen_Chao 2015-02-05
  • 打赏
  • 举报
回复
引用 3 楼 boybaozi 的回复:
没报错只是数据插不到数据库?
是的,没有任何错误,对于数据的只读操作都没有问题,数据都可以查询到,但是按照配置来看,save方法是有写权限的呀
Allen_Chao 2015-02-04
  • 打赏
  • 举报
回复
service层实现类:ResourceService.java


package com.skynet.cdw.platform.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.skynet.cdw.common.service.BaseService;
import com.skynet.cdw.platform.dao.ResourceDao;
import com.skynet.cdw.platform.entity.Resource;

@Service
@Transactional
public class ResourceService implements BaseService<Resource, Integer>
{
    @Autowired
    private ResourceDao resourceDao;

    public List<Resource> findAll()
    {
        return resourceDao.findAll();
    }

    public List<Resource> findById(Integer id)
    {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Transactional
    public void save(Resource entity)
    {
        resourceDao.save(entity);
        Resource res = new Resource();
        res.setName("资源管理");
        resourceDao.save(res);
    }

    public void delete(Resource entity)
    {
        
    }

    public void delete(Integer id)
    {
        // TODO Auto-generated method stub
        
    }

    public void update(Resource entity)
    {
        // TODO Auto-generated method stub
        
    }

    public ResourceDao getResourceDao()
    {
        return resourceDao;
    }

    public void setResourceDao(ResourceDao resourceDao)
    {
        this.resourceDao = resourceDao;
    }
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧