Converting Java program to Spring Framework -
i have short program takes string console prompt, in format:
1=harry_2=male_3=54_4=blonde_5=french_6=teacher
and prints so:
1 name harry
2 gender male
3 age 54
4 hair blonde
5 nationality french
6 occupation teacher
however, next aim take , recreate program operates web browser. i've read documentation spring framework , got demo program running, i'm @ loss how begin taking script , fitting framework.
ideally, i'd have single page input box prints results underneath.
any advice on how begin process great.
oh, code:
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.util.hashmap; import java.util.map; public class maptest { public static void main(string args[]) throws ioexception { map<string, string> tagmap = new hashmap<string, string>(); tagmap.put("1","name"); tagmap.put("2","gender"); tagmap.put("3","age"); tagmap.put("4","hair"); tagmap.put("5","nationality"); tagmap.put("6","occupation"); string input; bufferedreader reader; reader = new bufferedreader(new inputstreamreader(system.in)); system.out.println("insert raw data: "); input = reader.readline(); string msg = input; string[] params = msg.split("_"); (string p : params) { string[] nv = p.split("="); string name = nv[0]; string value = nv[1]; system.out.println(nv[0] + " " + tagmap.get(nv[0]) + " " + nv[1]);} } }
to mimic in spring webapp, you'll want create controller class takes input html form , transforms output like. see implementing controllers in reference documentation.
Comments
Post a Comment