java - Generic DAO in Spring Web Development -


how can set these codes in dao layer generic in order me avoid code redundancy , efficiently use simple set of codes in multiple circumstances using spring web development?

iteminfodao.xml

<select id = "getitem1" resultmap="resultitem1">     select item_id, name, area item1 </select>  <insert id="insertitem1">     insert item1 (item_id, name, area)           values (#{itemid}, #{itemname}, #{itemarea}) </insert> <select id = "getitem2" resultmap="resultitem2">     select item_id, name, area item2 </select> <insert id="insertitem2">     insert item2 (item_id, name, area)           values (#{itemid}, #{itemname}, #{itemarea}) </insert> 

iteminfodao.java

list<package> getitem1(package package);  void insertitem1(package package );  list<box> getitem2(box box);  void insertitem2(box box); 

use spring-data-jpa avoid boilerplate code simple db crud operations.

you can define generic interface:

@norepositorybean public interface itemdao<t> extends jparepository<t, long> {     t getitem(t input);      void insertitem(t input); } 

concrete implementation package be:

public interface packagedao extends itemdao<package> {  } 

concrete implementation box be:

public interface boxdao extends itemdao<box> {  } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -