Springmvc+easyui CRUD Add Data C

Source: Internet
Author: User

After an article, this morning to achieve the increase in data. Here is the JSP, which is mainly looking at NewUser () and Saveuser (). Notice that the Url,newuser () inside this function takes away the URL attribute. One more thing to keep in mind

<div id= "Toolbar" ><a href= "javascript:void (0);" class= "Easyui-linkbutton" iconcls= "Icon-add" plain= "true" Onclick= "NewUser ()" >new user</a><a href= "#" class= "Easyui-linkbutton" iconcls= "Icon-edit" plain= "true" Onclick= "Edituser ()" >edit user</a><a href= "#" class= "Easyui-linkbutton" iconcls= "Icon-remove" plain= " True "onclick=" Removeuser () ">remove user</a></div>
In this, <a href= "#" > # to be changed to Javvascript:void (0); This does not occur when the page is not found when the new user is created.



<%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Package Com.yang.bishe.controller;import Java.util.list;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.responsebody;import Org.springframework.web.servlet.modelandview;import Com.yang.bishe.entity.json;import Com.yang.bishe.entity.user;import Com.yang.bishe.service.interfaces.IUserService; @Controller @requestmapping ("/user") public class Usercontroller Extends Basecontroller {@Autowiredprivate iuserservice userservice; @RequestMapping ("/list") public Modelandview    Golist () {return new Modelandview ("User/list"); } @RequestMapping ("/listusers") public String Listuser (httpservletrequest request,httpservletresponse response) Throws Exception {//return "/views/index"; String hql= "from User"; List<user>users=userservicE.find (HQL);//string result=userservice.find (HQL); Writejson (users,response); return null; } @RequestMapping ("/adduser") public String addUser (User user,httpservletrequest request,httpservletresponse response ) throws Exception{json JSON = new JSON ();//used to send messages to the front End if (Userservice.getbyid (User.getuserid ())!=null) {json.setmsg (" New user failed, user already exists! ");} Else{userservice.save (user); Json.setmsg ("New user succeeded! "); Json.setsuccess (true);} Writejson (json,response); return null;}}

Writejson (Json,response)
This is to pass the message to the front page, Success:funciont (result) in the function inside the script, and result has the JSON message in the controller.







Springmvc+easyui CRUD Add Data C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.