"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