We have to use PropertyPlaceholderConfigurer bean for this.
1).properties file location -
- src/main/resource @ maven managed project
- OR at classpath
(Ganesh Tiwari) gt_ebuddy's Blog - Code snippets, technical articles, tips on computing and programming...
@MappedSuperclass
public abstract class BaseTable {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "dflag")
private int dFlag;
@Column(name = "lastmodifieddate")
private Date lastModifiedDate;
//other required columns
....
}
@Entity
@Table(name = "LoginUser")
public class LoginUser extends BaseTable implements Serializable{
private static final long serialVersionUID = -1920053571118011085L;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "invalidCount")
private int invalidCount;
//other required tables
...
}
CREATE TABLE YOUR_DB_NAME
CHARACTER SET "UTF8"
COLLATE "utf8_general_ci";
NOTE : You Need to do "ALTER TABLE" instead of "CREATE TABLE",
if you are going to modify existing DB.
jdbc.url=jdbc:mysql://localhost:3306/YOUR_DB_NAME?useUnicode=true&characterEncoding=UTF-8
<hibernate-configuration>
<session-factory>
...
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
...
</session-factory>
</hibernate-configuration>
URL url= new URL("http://gt-tests.appspot.com/ip");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String ip = in.readLine();
System.out.println("IP : "+ip);
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
// Get client's IP address
String addr = req.getRemoteAddr();
out.println(addr);
...
@RequestMapping(value = "/download", method = RequestMethod.GET)
public @ResponseBody
void downloadFile(HttpServletResponse resp) {
String downloadFileName= "download.txt";
String downloadStringContent="Download text \n This is working.";
try {
OutputStream out = resp.getOutputStream();
resp.setContentType("text/plain; charset=utf-8");
resp.addHeader("Content-Disposition","attachment; filename=\"" + downloadFileName + "\"");
out.write(downloadStringContent.getBytes(Charset.forName("UTF-8")));
out.flush();
out.close();
} catch (IOException e) {
}
}
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
hibernate.show_sql=true, the second prints the bound parameters among other things.<property name="show_sql">true</property>
TO Show Formatted SQL :<property name="format_sql">true</property>
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
// ...
String source = "The less than sign (<) and ampersand (&) must be escaped before using them in HTML";
String escaped = escapeHtml(source);
HtmlUtils.htmlEscape(String input) method.