Wednesday, 6 May 2015

How to insert code into blogger

Programmers know that blogger doesn't support code insertion (usefull if you need to demonstrate how to program something by copy/pasting code samples). Thus, you need to swicth  Blogger's editor to HTML and paste HTMLized text.

The nicest solution I found to format your code to HTML is to use this online code formatter : http://hilite.me/


import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

@Controller

public class Home {

 @RequestMapping("/hello")

 public @ResponseBody

 String hello(@RequestParam(value = "name") String name,

   @RequestParam(value = "gender") String gender,

   @RequestParam(value = "email") String email,

   @RequestParam(value = "phone") String phone,

   @RequestParam(value = "city") String city) {

  System.out.println(name);

  System.out.println(gender);

  System.out.println(email);

  System.out.println(phone);

  System.out.println(city);

  String str = "{\"user\": { \"name\": \"" + name + "\",\"gender\": \""

    + gender + "\",\"email\": \"" + email + "\",\"phone\": \""

    + phone + "\",\"city\": \"" + city + "\"}}";

  return str;

 }

}

No comments:

Post a Comment