firstname

Converting Java Object to Json using Marshaller

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Its quite easy to convert a java object to XML by using Marshaller. But I need to convert a java object to JSON by using marshaller alone. I know its good to use gson or Xstream like things., but I need to do using Marshaller.How to achieve it? Thanks in advance. 回答1: Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group, Below is how this can be done if you are using MOXy as your JAXB provider. http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html JAVA MODEL Customer import java.util.*

string.Format in Data Annotation Validation Attributes

匿名 (未验证) 提交于 2019-12-03 01:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there any way to set Data Annotation messages using formatted string instead of direct constant, I need to set required field ErrorMessage like in following code, but it gives me an error. [Required(ErrorMessage = string.Format(SystemMessages.Required, "First Name"))] public string FirstName { get; set; } SystemMessages is a constant file and it has following code, public const string Required = "{0} is required."; Is there any way to set attributes like this? 回答1: string.Format result is not a compile time constant and can't bee

How did I get this NullReferenceException error here right after the constructor?

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've had an asp.net website running live on our intranet for a couple of weeks now. I just got an email from my application_error emailer method with an unhandled exception. Here it is (ive cleaned up some of the paths to make it better displayed) Exception : Object reference not set to an instance of an object. Stack Trace : at System.Collections.Generic.Dictionary 2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary 2.Add(TKey key, TValue value) at TimesheetDomain.DataMappers.StaffMemberData.ReadStaff

Use @NodeEntity on interface/abstract class

匿名 (未验证) 提交于 2019-12-03 01:00:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to add @NodeEntity (or even @RelationshipEntity ) annotation from SpringData Neo4j on an interface or abstact class or their fields? If not, how do you manage these situations? 回答1: Definitely you can do that on Abstract classes , and I think it's a good practice in some common cases. Let me give you an example that I'm using in my graph model: @NodeEntity public abstract class BasicNodeEntity implements Serializable { @GraphId private Long nodeId; public Long getNodeId() { return nodeId; } @Override public abstract boolean

docx4j replace variable with html

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i got this sample code to replace variables with text and it works perfect. WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File("c:/template.docx")); VariablePrepare.prepare(wordMLPackage); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); HashMap<String, String> mappings = new HashMap<String, String>(); mappings.put("firstname", "Name"); //${firstname} mappings.put("lastname", "Name"); //${lastname} documentPart.variableReplace(mappings); wordMLPackage.save(new java.io.File("c:/replace

How do I update an entity using spring-data-jpa?

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Well the question pretty much says everything. Using JPARepository how do I update an entity? JPARepository has only a save method, which does not tell me if it's create or update actually. For example, I insert a simple Object to the database User, which has three fields: firstname and lastname and age: @Entity public class User { private String firstname; private String lastname; //Setters and getters for age omitted, but they are the same as with firstname and lastname. private int age; @Column public String getFirstname() { return

Load Spring-Boot Database with Test Data

匿名 (未验证) 提交于 2019-12-03 00:54:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Goal: Leverage spring-boot Data Initialize features to create a simple database and load it with data. Problem: Receiving an error during spring-boot start up. org . hibernate . tool . hbm2ddl . SchemaExport : Column "FIRSTNAME" not found ; SQL statement More of the spring-boot start-up output: 2015 - 03 - 06 17 : 32 : 30.919 INFO 3688 --- [ main ] o . s . jdbc . datasource . init . ScriptUtils : Executing SQL script from URL [ file : /E:/ spring - workspace / TestApp / target / classes / schema . sql ] 2015 - 03 - 06 17 : 32 : 30

BeansBinding a JTable in NetBeans

匿名 (未验证) 提交于 2019-12-03 00:53:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want map a List of beans to a JTable. The idea is that each column will be a preselected field in the bean and each row will be a bean in the List. Slide #32 here looks very promising: http://swinglabs.org/docs/presentations/2007/DesktopMatters/beans-binding-talk.pdf However, NetBeans is not very friendly in letting me assign a bean field to a column. I can right-click the JTable and click Bind->Elements and bind it to my List of beans. However, it will not let me specify what goes in each column. The only option is to create the binding

Jackson, deserialize class with private fields and arg-constructor without annotations

匿名 (未验证) 提交于 2019-12-03 00:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: It is possible to deserialize to a class with private fields and a custom argument constructor without using annotations and without modifying the class, using Jackson? I know it's possible in Jackson when using this combination: 1) Java 8, 2) compile with "-parameters" option, and 3) the parameters names match JSON. But it's also possible in GSON by default without all these restrictions. For example: public class Person { private final String firstName; private final String lastName; private final int age; public Person(String firstName,

org.hibernate.QueryParameterException: could not locate named parameter

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My project setting are Spring MVC, Hibernate 3.2.x, on MySQL DB Getting the following error: org.hibernate.QueryParameterException: could not locate named parameter email Approach #1: @Override public Boolean isExist(String email) { boolean flag = false; String hql = "from com.cmgr.beans.UserAccount u where u.email = :email"; List<UserAccount> result = currentSession().createQuery(hql) .setParameter("email", email) .list(); UserAccount userAccount = (UserAccount)result.get(0); if (userAccount!=null && userAccount.getEmail().equalsIgnoreCase