1.SPRINGMVC configuring transactions, first configuring transactions in APPLICATION.XM
<!--configuration transaction manager-->
<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<!--<tx:method name= "get*" read-only= "true" rollback-for= "Java.lang.Exception"/>-->
<tx:method name= "query*" read-only= "true"/>
<tx:method name= "select*" read-only= "true"/>
<tx:method name= "insert*" propagation= "REQUIRED" rollback-for= "Java.lang.Exception"/>
<!--<tx:method name= "*" rollback-for= "java.lang.Exception"/>--><!--default rollback mechanism is RuntimeException-->
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id= "service" expression= "Execution" (* com.oracle.sx.businessData.service. *serviceimpl.* (..)) " /><!--Declare all methods of the class that contain the service to use the transaction-->
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "service"/>
</aop:config>
2. In the corresponding*serviceimpl (Service implementation Class) The corresponding method adds an exception mechanism, as follows:
@Override
Public String adddept (Jsonobject obj) throws Exception {
Departmentinfo departmentinfo = new Departmentinfo ();
String RetCode = "";
String retmsg = "";
String objstr = "";
map<string, object> params = new hashmap<string, object> ();
Jsonobject jsonobject = new Jsonobject ();
try{
Business Block
}catch (Exception e) {
RetCode = Get_message_code. Unknown_error;
Retmsg = "Unknown error";
Log.info ("Interface exception information:" + e);
throw new Exception ();
}
Jsonobject.put ("response", retCode);
Jsonobject.put ("message", retmsg);
Convert JSON
Jsonarray Jsonarray = new Jsonarray ();
Jsonarray.add (Jsonobject);
Objstr = Jsonarray.tojsonstring ();
return objstr;
}