How to do spring validations with angular js as the front end. How to display the error messages on the angular js form?

  Jul 25, 2016

@Controller public class OrderController extends WebMvcConfigurerAdapter{ @Autowired OrderServive service1; private OrderValidator orderValidator; public OrderController() { super(); System.out.println("inside the system controller"); orderValidator = new OrderValidator();

}
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.setValidator(orderValidator);
}
@RequestMapping(value="/AddOrder",method

= RequestMethod.POST,produces="application/json") public @ResponseBody List AddOrder(@Valid@RequestBody Order order) throws JSONException{ System.out.println("inside add"); Map map = new HashMap(); MapBindingResult err = new MapBindingResult(map,Order.class.getName()); List list = err.getAllErrors(); Gson gson=new Gson(); Order o=new Order(); JSONObject j=new JSONObject(order); o=gson.fromJson(j.toString(), Order.class); System.out.println(o); orderValidator.validate(order,err); String msg=service1.addOrder(order); return service1.getOrders();

}
@RequestMapping(value="/getOrders",method

= RequestMethod.POST,produces="application/json") public @ResponseBody List getOrders() throws JSONException {List ordList=new ArrayList(); ordList=service1.getOrders(); for(Order o:ordList) { System.out.println(o); } return ordList;

}
@RequestMapping(value="/UpdateOrder",method

= RequestMethod.POST,produces="application/json") public @ResponseBody List UpdateOrder(@RequestBody Order order) { Gson gson=new Gson(); Order o=new Order(); JSONObject j=new JSONObject(order); o=gson.fromJson(j.toString(),Order.class); System.out.println("in update"+o); String st=service1.UpdateOrder(o); System.out.println(st); List ordList=service1.getOrders(); return ordList;

}
@RequestMapping(value="/DeleteOrder",method=RequestMethod.POST,produces="application/json")
public @ResponseBody List<Order> DeleteOrder(@RequestBody Order order)
{
    Gson gson=new Gson();
    Order o=new Order();
    JSONObject j=new JSONObject(order);
    o=gson.fromJson(j.toString(),Order.class);
    String st=service1.DeleteOrder(o);
    System.out.println(st);
    List<Order> ordList=service1.getOrders();
    return ordList;
}
@RequestMapping(value="/GloDel",method=RequestMethod.POST,produces="application/json")
public @ResponseBody List<Order> GloDel(@RequestBody String ordList)

throws JSONException {String st; Gson gson=new Gson(); Order o=new Order(); JSONArray j=new JSONArray(ordList); for(int i=0;i

}
@RequestMapping(value="/GloUpd",method=RequestMethod.POST,produces="application/json")
public @ResponseBody List<Order> GloUpd(@RequestBody String ordList)

throws JSONException {String st; Gson gson=new Gson(); Order o=new Order(); JSONArray j=new JSONArray(ordList); for(int i=0;i ordList1=service1.getOrders(); for(Order o3:ordList1) { System.out.println(o3); } return service1.getOrders();

} }

This is my controller in spring mvc. I want to display the spring validation errors on the angular js form. Any suggestions?

In Progress 0
2 years ago 0 Answer 0 views

Answers ( 0 )

Your Answer