Posts

Showing posts from July, 2017

Convert Java Object to / from JSON | Code Factory

Image
Download code and jars :  Link. File : EmployeeBean.java package com.codeFactory.bean; public class EmployeeBean {     private int id;     private String name;     private String gender;     private String designation;     // Getters and Setters... } File : Main.java package com.codeFactory.main; import com.codeFactory.bean.EmployeeBean; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static void main(String args[]) { EmployeeBean employeeBean = new EmployeeBean(); employeeBean.setId(1); employeeBean.setName("Employee1"); employeeBean.setGender("Male"); employeeBean.setDesignation("JAVA"); ObjectMapper objectMapper = new ObjectMapper(); try { // this create java object to json string... String jsonStr = objectMapper.writeValueAsString(employeeBean); System.out.println(jsonStr); // this create json string to java object...

Convert Java Object to JSON String | Code Factory

Image
Download code and jars :  Link. File : EmployeeBean.java package com.codeFactory.bean; public class EmployeeBean {     private int id;     private String name;     private String gender;     private String designation;     // Getters and Setters... } File : Main.java package com.codeFactory.main; import java.util.HashMap; import java.util.Map; import com.codeFactory.bean.EmployeeBean; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Main {     public static void main(String args[]) {         EmployeeBean employeeBean = new EmployeeBean();         employeeBean.setId(1);         employeeBean.setName("employee1");         employeeBean.setGender("male");         employeeBean.setDesignation("JAVA");         ObjectMapper objectMapper = new ObjectMapper();         Map<String, String> map = new HashMap&

JasperReports Tutorial | #3 | Crosstab in Jasper Report | Code Factory

Image
Download code and jars :  Link.  &  Link. File : crossTab.jrxml <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --> <!-- 2017-07-15T19:35:56 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="crossTab" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b0537bac-ad5b-45da-b8c2-5dc51e1e6dc3"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defa

JasperReports Tutorial | #2 | Add Dynamic Image in JasperReport | Code Factory

Image
Download code and jars :  Link. File : ImageExample.jrxml <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --> <!-- 2017-07-08T18:55:10 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ImageExample" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a6ee753e-8e87-44d2-86ac-63c43589fc1e">      <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>      <parameter name="Image"

How to Calculate Sum of Particular Column Based on Id in MySQL | Code Factory

Image
MySQL Query : select id, product_name as Product_Name, stock as Stock, sum(istock) as CF_Stock from (     select *     from product_master t1,(         select t.id as iid, t.stock as istock, t.product_name as product         from product_master t     ) t2     where t1.id >= t2.iid     order by t1.id,t1.product_name,t2.product     ) t3 where product_name=product group by id, product_name order by product_name, id; Output : Tags : find cumulative frequency of column How to get cumulative sum calculate cumulative frequency of column in mysql how to calculate sum of particular column based on id in mysql

JasperReports Tutorial | #1 | Create JapserReport with MySQL Datasource | Code Factory

Image
Download code and jars :  Link. File : GetData.jrxml <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --> <!-- 2017-07-01T18:44:07 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="GetData" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="eeb683ed-9e3f-4319-9935-03916b115500"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataada

Include the CSRF Token in Spring Security | Code Factory

Form Submissions To implement spring security you must include the CSRF token in all PATCH, POST, PUT, and DELETE methods. One way to approach this is to use the _csrf request attribute to obtain the current CsrfToken . An example of doing this with a JSP is shown below: <c:url var="logoutUrl" value="/logout"/> <form action="${logoutUrl}" method="post"> <input type="submit" value="Log out" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> </form> *Note : If you are using Spring MVC <form:form> tag or Thymeleaf 2.1+ and are using @EnableWebSecurity , the CsrfToken is automatically included for you (using the CsrfRequestDataValueProcessor ). Ajax and JSON Requests If you are using JSON, then it is not possible to submit the CSRF token within an HTTP parameter. Instead you can submit the token within a H