Java SPRINGMVC + Mybatis A set of foreground to background full data acquisition steps

Source: Internet
Author: User

"Reprint" 76045368

1. In the foreground JSP page generally uses the Ajax method to obtain the background data for the front-end use.
$.ajax ({
URL: "<c:url value= '/strategy/deletecelue '/>",//the URL of the request is also the address of the controller you need to jump to (only with reference, the actual as the subject!) )
async:true,//request is asynchronous, default is async, which is also an important feature of Ajax
Data: {
Data:data
},//parameter values
Type: "POST",//Request method
Success:function (data) {
Processing when a request succeeds
}
});

Note: A point in the SPRINGMVC core is a transaction! One of the database additions and deletions are to be based on transactions to operate!


@Controller
@RequestMapping (value = "/strategy")
@RequestMapping (value= "/deletecelue", Method=requestmethod.post)
Public @ResponseBody Integer Deletecelue (strategyentity strategyentity,string getId) {
Integer i=0;
try {
if (null! = GetId && ""! = getId) {
Strategyentity.setuserid (getId);//used to get the accepted ID and assign a value to modle inside to service!
i = Strategyservice.deletecelue (strategyentity);
}
} catch (Exception e) {
Todo:handle exception
}
return i;
}
Methods in 3.Service:
Public Integer Deletecelue (strategyentity strategyentity);//model! for Reception
The 4.StrategyServiceImpl class is primarily used to implement the methods in the service!
@Autowired
Private Strategymapper strategymapper;//used to implement the method inside the Mapper interface
@Override
Public Integer Deletecelue (strategyentity strategyentity) {
TODO auto-generated Method Stub
Return Strategymapper.deletecelue (strategyentity),//???
}
5. There is also a need to create a mpper interface placed under the DAO backpack for sending requests to XML to perform the appropriate operations the following is a partial project structure:

Continue to see the method in the Mapper interface: public Integer deletecelue (strategyentity strategyentity), or the previous method implemented in the return type 6.mapper xml:
<delete id= "Deletecelue" parametertype= "com.pushtime.ferry.model.StrategyEntity" >
DELETE from file_strategy WHERE user_id = #{userid};
</delete>

ID: Is the method name that needs to be implemented in the Mapper interface
ParameterType: The model class that needs to be brought in!
#{userid}: The userId in the model class is obtained with #{}!
Delete successfully returned 1 failed to-1!


Then you can determine if the deletion was successful! Please advise us of any mistakes!

Java SPRINGMVC + Mybatis A set of foreground to background full data acquisition steps

Related Article

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.