Basedao injection problem during General Service authoring

Source: Internet
Author: User

Spring 4.0 supports generic dependency injection, which is implemented as follows

Public abstract class Genericservice<t extends Basebean, PK extends serializable> implements Baseservice<t, PK & Gt {//@SuppressWarnings ("unchecked")//Private class<t> Gettclass () {//Return ((class<t>) ((Parame Terizedtype) GetClass (). Getgenericsuperclass ()). Getactualtypearguments () [0]);////}/** * spring4.0 support for generic injection *  Since autowired is a dependency type * 4.0 previously considered to be of the same type, subclasses inherit Genericservice and will be considered to have multiple identical Genericdao instances so that the error */@Autowired public genericdao<t,    Pk> DAO;        public void Save (T t) {if (t = = null) {return;    } this.dao.insert (t);        public void Saveorupdate (T-t) {if (t = = null) {return;        } if (t.id== null) {This.save (t);        } else {this.update (t);    }}/** * Modify record * According to param condition * @param param used to generate SQL parameter values, including where condition, Target field and new value, etc. * @throws Exception */ @Transactional public void Update (map<string, object> param) {if(param = = null| |        Param.size () ==0) {return;    } this.dao.update (param);        }/** * Modify entity */@Transactional public void update (T t) {if (t = = null) {return;    } this.dao.update (t);        }/** * Delete entity * * @param ID * @throws Exception */@Transactional public void Delete (PK id) {        if (id = = null) {return;    } this.dao.delete (ID); /** * Delete entity * According to param condition * @param param used to generate the parameter value of SQL, including the Where condition, Target field and new value, etc. * @throws Exception */@Tr ansactional public void Delete (map<string, object> param) {if (param = = null| |        Param.size () ==0) {return;    } this.dao.delete (param);            /** * Get entity by ID */@SuppressWarnings ("unchecked") public T get (PK ID) {if (id = = NULL) {        return null;        } t = This.dao.get (ID);    return t; }/** * Query entity * based on param condition * @pAram param used to generate SQL parameter values, including where condition, Target field and new value, etc. * @throws Exception */Public T get (map<string, object> param) {if (param = = null| |        Param.size () ==0) {return null;        } t = This.dao.get (param);    return t;    }/** * Take all records * @return all record entity Objects list */public list<t> list () {return this.dao.select ();  /** * Query records by criteria * @param param query condition parameters, including where condition, page condition, sort condition * @return List */public for entity objects that match the condition record    List<t> Select (map<string, object> param) {return this.dao.select (param);    }/** * Query the total number of records for the whole table */public int count () {return this.dao.count (); /** * Query the number of records that meet the criteria * @param param query condition parameters, including the Where condition (the contents of other parameters do not work). This parameter is set to NULL, which is equivalent to count () * @return */public int count (map<string, object> param) {if (param = = null| |        Param.size () ==0) {return 0;    } return This.dao.count (param); }}


Basedao injection problem during General Service authoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.