贴代码:
<context:component-scan base-package="com.demo.controller,com.demo.dao,com.demo.domain,com.demo.service" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/software"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
<property name="maxActive" value="30"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="500000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="/WEB-INF/config/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
java代码:
@Service("customerService")
@Transactional
public class CustomerServiceImpl implements CustomerService{
@Autowired
private CustomerDao customerDao;
@Override
public Integer addCustomer(Customer customer){
int i =0;
try{
Integer maxId = customerDao.findMaxID();
if(null == maxId){
maxId=0;
}
customer.setCustomernum("KHBH-"+(maxId+1));
i=customerDao.addCustomer(customer);
}catch(Exception e){
throw new RuntimeException();
}
return i;
}
求指点。。。。。。。。。。。。。。。
}
<context:component-scan base-package="com.demo.controller,com.demo.dao,com.demo.domain,com.demo.service" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/software"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
<property name="maxActive" value="30"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="500000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="/WEB-INF/config/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
java代码:
@Service("customerService")
@Transactional
public class CustomerServiceImpl implements CustomerService{
@Autowired
private CustomerDao customerDao;
@Override
public Integer addCustomer(Customer customer){
int i =0;
try{
Integer maxId = customerDao.findMaxID();
if(null == maxId){
maxId=0;
}
customer.setCustomernum("KHBH-"+(maxId+1));
i=customerDao.addCustomer(customer);
}catch(Exception e){
throw new RuntimeException();
}
return i;
}
求指点。。。。。。。。。。。。。。。
}