Posts

Spring Boot - @RestController Easy way for creating your REST web service

Image
Building web services with Spring boot is quite simple, you basically have to annotate a java class with @RestController annotation.   @RestController public class ContactService { } Then, some methods of this class can be annotated with @RequestMapping, which indicates this method could be triggered by a HTTP request to the server, once it has match the defined path/URI.   @RequestMapping (value = "/contact" , method=RequestMethod. GET ) String list() {        return "listing all contacts...." ; } Now, it is also possible to set additional parameters to be received by http requests. For this purpose we can use @PathVariable annotation, which may bind a URL parameter with a method parameter. In the value attribute of @RequestMapping annotation, you may use the {variableName} for representing Where the value will be replaced by values in the concreate use case of the REST call. You may see an example of this code below: @R...

Spring Boot – Setting up your first project

Image
Nowadays Spring boot is a framework utilized for many important projects developed using the JAVA programming language. Then know how to use spring boot is a very important skill for any software developer. In this article we are going to see how to setup a spring boot project from zero. Then only requirement is that you have java and an eclipse IDE installed with updated version. First, c reate a new Maven Project:  From the Upper menu, File>New>Project Then, you could chose   to create a simple project: Next step set project group id and the project artifact id: Now the project is created. The next step is to update the pom.xml with the dependencies your project needs. Here is an example of the minimum pom.xml file you have to create. You could just copy and paste this code to you project. This pom.xml just has the following: spring boot core, spring boot for web application, spring JPA, and spring database implementation. We also have a parent tag, it ...

CSS Direct Children Selector

Image
  Selectors is a core feature of CCS technology. It assist us to define the set of elements to affected a CSS attributes.   One important feature is to understand how to filter elements based in its level in the DOM (Document Object Model). The name cascading (from CSS – Cascading Style Sheet) is so, because by default a certain rule is applied   to all its children (no matter the level), it is the example for the selector below:   body table{     display:none; } It will take all tables under body table, no matter if they are direct under body or in some sublevel of the elements tree. However, if the goal is to affect only elements there  are direct children form body, it is possible to use the following syntax (>), indicating it should not cascading, but just the first level elements that match the selector. body > table{     display:none; } A source code of the usage of this selecto...

XML – Serializing and deserializing objects using JAVA

Image
Nowadays systems typically have to interchange data with another systems, and the XML (eXtendable Markup Language) is one common pattern for this purpose.   When we are developing software using Object Oriented Programming languages, the whole program has to handle its datasets based in objects, composed by a set of attributes.   In this context it is very important to know how parsing XML documents, that essentially are plain text documents into objects, to then the program can operate with its data independently from its data source. We are going to see here how to create a XML document based on objects using the JAVA programming language. This example utilizes only native classes, so no external library is necessary.   DocumentBuilderFactory dbFactory = DocumentBuilderFactory . newInstance (); DocumentBuilder dBuilder = dbFactory .newDocumentBuilder(); Document doc = dBuilder .newDocument(); //create root node Element rootTag = doc.createElement( "people" ...