Realized by mybatis+springmvc3.0, it draws on the design idea of hibernate, adopts the designing idea of encapsulation, abstraction and inheritance, achieves the high cohesion and low coupling of data and corresponding operation.

Source: Internet
Author: User
Tags getmessage email account

qq:1138789752

Email.java class:

Package Com.lmc.ink.entity.seo;import com.lmc.ink.entity.ientity;/** * Promotional email form (S_EMAIL) entity class * @author LMC * */public class E Mail extends IEntity {/** * uniquely identifies * */public static final Long Serialversionuid = 537132705l;/** * PRIMARY key * Length 20 bit * not empty * remark: self-increment Long * */private Long id;/** * Mailbox Account * Length 40 bit * not empty * Remarks: Unique constraint * */private String accout;/** * Promotion Status * length 1 bit * not empty * Remarks: Valid | invalid | Used (1 |2|3), default is 1 * */private Integer state;/** * Construction method * */public Email () {Super ("S_email");} /** * Get PRIMARY key * Length 20 bit * not empty * Note: self-growth * @return Long PRIMARY key * */public long getId () {return ID;} /** * Set PRIMARY key * Length 20 bit * not empty * Note: self-growth * @param ID PRIMARY KEY * @return String ID * */public string setId (Long ID) {if (id!=null) {this.i d = ID;} return "id";} /** * Get Email account * Length 40 bit * not empty * Remarks: Unique constraint * @return string mailbox Account * */public string getaccout () {return accout;} /** * Set Mailbox account * Length 40 bit * not empty * Remarks: Unique constraint * @param accout Mailbox Account * @return String accout * */public string setaccout (String Accou T) {if (!super.xcheck (accout)) {this.accout = accout;} return "Accout";} /** * Get Promotion status * length 1 bit *Not empty * Remarks: Valid | invalid | used (1|2|3), default is 1 * @return integer promotion status * */public integer getState () {return state;} /** * Set Promotion status * length 1 bit * not empty * Remarks: Valid | invalid | used (1|2|3), default is 1 * @param state Promotion Status * @return string, */public string SetState ( Integer state) {if (state!=null) {this.state = state;} return "state";}}


Iservice.java Interface:

Package Com.lmc.ink.service;import Java.util.list;import com.lmc.ink.entity.ientity;/** * Business logic Class Parent Interface * @author LMC * @ Version 2015-04-08 16:47:41 * */public interface Iservice<t extends ientity> {/** * Debug flag * */public static final Boo  Lean debug = true;/** * Input debug information * @param en entity Object * @param error message * */public void debug (T en, String error);/** * Save Record *  @param en entity Object * @return Boolean operation result * */public Boolean save (T en);/** * Delete Record by primary key * @param en entity Object * @return Boolean operation result * */public boolean drop (t en);/** * routinely delete record * @param en entity object * @return int operation result * */public int recycle (t en);/** * Update record (overall * @param en entity Object * @return Boolean operation result * */public boolean replace (T en);/** * Update record (local) * @param en entity object * @return Boole  An operation result * */public Boolean modify (t en);/** * Key load record * @param en entity object * @return T entity object * */public t get (t en);/** * routinely query record  * @param en entity Object * @return List Object collection * */public list<t> list (T en);/** * routinely statistical record * @param en entity Object * @return Long statistics * */public long sum (T en);}

Emailservice Interface:

Package Com.lmc.ink.service.seo;import Com.lmc.ink.service.iservice;import com.lmc.ink.entity.seo.email;/** * Promotional email form (s_email) Business Logic class interface * @author LMC * @version 2015-04-18 10:51:05 * */public interface Emailservice extends iservice<email& Gt {}

Emailservice Interface Implementation:

Package Com.lmc.ink.service.seo.impl;import Java.util.list;import Com.lmc.ink.dao.seo.emaildao;import Com.lmc.ink.data.laws;import com.lmc.ink.entity.seo.email;import com.lmc.ink.service.seo.emailservice;/** * Promotion Email table ( S_email) Business Logic class interface * @author LMC * @version 2015-04-18 10:51:05 * */public class Emailserviceimpl implements Emailservice {PR Ivate Emaildao emaildao;public void Setemaildao (Emaildao emaildao) {This.emaildao = Emaildao;} public void debug (Email en, String error) {if (en!=null) {en.setxerror (error);} if (Debug) {System.err.println ("" "+this.getclass (). GetName () +" "" +error);}} Public boolean save (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return false;} if (En.getaccout () ==null) {this.debug (En,en.setaccout (NULL) + "EMPTY"); return false;} if (En.getstate ()!=null) {if (! Laws.legal (Laws.seo,en.getstate ())) {This.debug (en,en.setstate (NULL) + "illegal"); return false;}} Else{en.setstate (1);} return Emaildao.insert (en) >0;} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return false;}public boolean drop (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return false;} if (En.getid () ==null) {this.debug (En,en.setid (NULL) + "EMPTY"); return false;} return Emaildao.delete (en) >0;} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return false;} public int recycle (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return 0;} return Emaildao.remove (en);} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return 0;} public boolean replace (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return false;} if (En.getid () ==null) {this.debug (En,en.setid (NULL) + "EMPTY"); return false;} if (En.getstate () ==null| |! Laws.legal (Laws.seo,en.getstate ())) {This.debug (en,en.setstate (NULL) + "illegal"); return false;} return Emaildao.merge (en) >0;} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return false;} Public boolean modify (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return false;} if (En.getid () ==null) {this.debug (En,en.setid (NULL) + "EMPTY"); return false;} if (En.getstate ()!=null&&! Laws.legal (Laws.seo,en.getstate ())) {This.debug (en,en.setstate (NULL) + "illegal"); return false;} return Emaildao.update (en) >0;} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return false;} Public email get (email en) {try{if (en==null) {this.debug (null, "parameter is null"); return null;} if (En.getid () ==null) {this.debug (En,en.setid (NULL) + "null"); return null;} return Emaildao.load (en);} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return null;} Public list<email> List (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return null;} return Emaildao.find (en);} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return null;} Public long sum (Email en) {try{if (en==null) {this.debug (null, "parameter is null"); return 0;} return Emaildao.count (en);} catch (Exception e) {this.debug (En,e.getmessage ()); E.printstacktrace ();} return 0;}}

Test code:

Package Com.test;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;import Com.lmc.ink.entity.seo.email;import Com.lmc.ink.service.seo.emailservice;public class _email {public static void main (string[] args) throws Exception { ApplicationContext act = new Classpathxmlapplicationcontext ("Applicationcontext.xml"); Emailservice service = Act.getbean ("Emailservice", emailservice.class);//"routinely query and routinely statistics example" email en = new email ();// Set the equivalent query parameters, with and connection execution: Id=1en.setid (1L);//Set the fuzzy query parameters,% and _ character matching, with and link execution: accout like '%[email protected] ' en.setaccout ("%[email protected]");//Set fuzzy query parameters,% with _ characters, with and link execution: accout like '%1138789752_ ' En.setaccout ("%1138789752_"); /Set range query parameters, executed with and connection: id = 1en.setxscope (true,en.setid (null), "=", 1L);//Set range query parameters to execute with and connection: id! = 1en.setxscope (True, En.setid (NULL), "! =", 1L);//Set range query parameters to be executed with an OR connection: Accout like '%[email protected] ' En.setxscope (False,en.setaccout ( NULL), "like", "%[email protected]");//Set range query parameters to orConnection execution: Accout like '%1138789752_ ' En.setxscope (false,en.setaccout (null), "like", "%1138789752_");//Set range query parameters to be executed with an OR connection: ID > 2en.setxscope (false,en.setid (null), ">", 2L);//Set range query parameters to execute with or connection: ID >= 2en.setxscope (false,en.setid ( NULL), ">=", 2L);//Set range query parameters, with and connection execution: ID < 2en.setxscope (true,en.setid (NULL), "<", 2L),//Set range query parameters, execute with and connection: ID <= 2en.setxscope (true,en.setid (null), "<=", 2L);//set non-null query parameters to execute with or connection: Accout is Nullen.setxsky (false, En.setaccout (NULL), TRUE);//set in query parameter, executed with and connection: ID in (en.setxchain); True,en.setid (null), New long[]{1l,2l,3l}) ;//Set Group field, execute: Group by State,group by Iden.setxgroup (en.setstate (null)); En.setxgroup (En.setid (null));// Gets the total number of routinely query records long = Service.sum (en);//sets the total number of paging records en.setxtotal (total);//sets the number of paging records en.setxtotal (10000L);//sets the number of pages per page, This is set to each page 100 en.setxsize (100L);//Set Paging current page, here set to take 2nd page En.setxnow (2L);//Execute case query, return value is list<email>service.list (en); /"Key load record" en = new Email (); En.setid (1L); en = Service.get (en); System.out.println (en==null);//"Add record"//Instantiate object and set value en = new Email (); en. Setaccout ("[email protected]"); En.setstate (2);//execute Add record, return value is BooleanSystem.out.println (Service.save (en)); /execute Add record after get object saved to database primary key value (primary key is self-growth) System.err.println (En.getid ());//"Delete Record"//execute by PRIMARY key Delete, return value is Booleanen = new Email (); En.setid (1L); System.out.println (Service.drop (en));//"Routinely delete record"//here Execute delete from S_email where account = ' [email protected] ' and state = 2en = new Email (); En.setaccout ("[email protected]"); En.setstate (2); System.out.println (Service.recycle (en));//There are no parameters here, which is equivalent to emptying the database table, so you should use routinely to delete the record System.out.println (Service.recycle (new Email ()));//"update record" en = new Email (); En.setid (1L); En.setaccout ("123456");//(partial update) performed here: Update s_email Set accout = ' 123456 ' WHERE id = 1system.out.println (service.modify (en)); en.setstate (1);//(overall update) performed here: Update s_email Set accout = ' 123456 ', state = 1 WHERE id = 1system.out.println (service.replace (en));//"Output debug Information"//This is called internally by the service class Service.debug (EN, " Error message ");//above with mybatis+springmvc3.0 realization, borrowed from hibernate design idea,//adopt encapsulation, abstract, inherit design idea, do the data and corresponding operation of high cohesion low coupling realization}}


Realized by mybatis+springmvc3.0, it draws on the design idea of hibernate, adopts the designing idea of encapsulation, abstraction and inheritance, achieves the high cohesion and low coupling of data and corresponding operation.

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.