林 '語言' 一得到follwoing錯誤:java.lang.NoSuchMethodException:未知屬性的類 '類java.lang.Class'
java.lang.NoSuchMethodException: Unknown property 'language' on class 'class java.lang.Class'
REST調用中使用:/測試/ REST /語言/ INSERTOBJ /日文/瑞典文%206
我正在使用:org.apache.commons.beanutils.PropertyUtils;
我在我的Languages類中有指定的屬性'語言',所以我不知道爲什麼它會拋出錯誤。它適用於當我宣佈其如此:
語言lanobj = new Lanaguages();
//語言類
public class Languages implements java.io.Serializable {
private String language;
private String displayName;
public Languages() {
this.language = null;
this.displayName = null;
}
public Languages(String language, String displayName) {
this.language = language;
this.displayName = displayName;
}
public void setLanguageId(Long languageId) {
this.languageId = languageId;
}
@Column(name = "language", nullable = false, length = 50)
public String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
this.language = language;
}
@Column(name = "displayName", nullable = false, length = 50)
public String getDisplayName() {
return this.displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
}
///資源管理器代碼
@Path("{subResources}/insertobj/{language-id}/{displayname-id}")
//@POST
@GET // Using get for the sake of making rest call with browser
@Produces(MediaType.TEXT_HTML)
public String getLanguageById(@PathParam("subResources") String id,
@PathParam("language-id") String language_id,
@PathParam("displayname-id") String displayname_id)
{
try{
Class<?> c = Class.forName("com.test."+id);
PropertyUtils.setProperty(c, "language",language_id);
PropertyUtils.setProperty(c, "displayName",displayname_id);
TransactionManager.createObject(c);
}catch (Exception exc){
exc.printStackTrace();
}
}
//事務管理段:
public static void createObject(Object entityObject) {
Transaction tx = null;
//SessionFactoryUtil.getInstance().openSession();
Session session = SessionFactoryUtil.openSession();
try {
tx = session.beginTransaction();
session.save(entityObject);
tx.commit();
}
catch (RuntimeException e)
{
if (tx != null && tx.isActive())
{
try
{
// Second try catch as the rollback could fail as well
tx.rollback();
}
catch (HibernateException e1) {
//logger.debug(「Error rolling back transaction」);
}
// throw again the first exception
throw e;
}
}
finally
{
session.close();
}
}
downvoter care to comment – mprabhat
我沒有投票給你,但你的原始答案是三行代碼,沒有任何解釋。您稍後將文字轉換爲實際答案。有些人認爲這種風格不好。 –
謝謝你的工作。 – Fabii