मैं चाहते हैं अगर मैं इन कक्षाओं में सही ढंग से व्याख्या कर रहा हूँ पता करने के लिए, के बाद से मैं एनोटेशन के लिए नया हूँ:SpringMvc एनोटेशन
Country.java
@Component
public class Country {
private int countryId;
private String countryName;
private String countryCode;
/**
* No args constructor
*/
public Country() {
}
/**
* @param countryId
* @param countryName
* @param countryCode
*/
public Country(int countryId, String countryName, String countryCode) {
this.countryId = countryId;
this.countryName = countryName;
this.countryCode = countryCode;
}
//getters and setters
}
CountryDAO जावा
@Repository
public interface CountryDAO {
public List<Country> getCountryList();
public void saveCountry(Country country);
public void updateCountry(Country country);
}
JdbcCountryDAO.java
@Component
public class JdbcCountryDAO extends JdbcDaoSupport implements CountryDAO{
private final Logger logger = Logger.getLogger(getClass());
@Autowired
public List<Country> getCountryList() {
int countryId = 6;
String countryCode = "AI";
logger.debug("In getCountryList()");
String sql = "SELECT * FROM TBLCOUNTRY WHERE countryId = ? AND countryCode = ?";
logger.debug("Executing getCountryList String "+sql);
Object[] parameters = new Object[] {countryId, countryCode};
logger.info(sql);
//List<Country> countryList = getJdbcTemplate().query(sql,new CountryMapper());
List<Country> countryList = getJdbcTemplate().query(sql, parameters,new CountryMapper());
return countryList;
}
CountryManagerIFace.java
@Repository
public interface CountryManagerIFace extends Serializable{
public void saveCountry(Country country);
public List<Country> getCountries();
}
CountryManager.java
@Component
public class CountryManager implements CountryManagerIFace{
@Autowired
private CountryDAO countryDao;
public void saveCountry(Country country) {
countryDao.saveCountry(country);
}
public List<Country> getCountries() {
return countryDao.getCountryList();
}
public void setCountryDao(CountryDAO countryDao){
this.countryDao = countryDao;
}
}
ऑटोवायर गेटर निश्चित रूप से सही नहीं दिखता –
देश को एक घटक या वीओ के रूप में घटक के रूप में एनोटेट नहीं किया जाना चाहिए। आप इसे एक साधारण unannotated बीन के रूप में छोड़ सकते हैं। –
आपको कार्यान्वयन कक्षाओं की व्याख्या करनी चाहिए और आपको इंटरफेस के बारे में चिंता करने की ज़रूरत नहीं है। घटक से बचें जब तक कि कोई बेहतर, अधिक अर्थपूर्ण विकल्प न हो। एक नज़र में ऐसा लगता है जैसे CountryManager अधिक @Service की संभावना है। –