1. New MAVEN Project
Next
Next
Right-click the new Project Properties->project Facets:
Remove dynamic Web module->apply and then tick to 3.0 and appear below. Further configuration available ...
Modify:
2.springMVC configuration See: Springmvc configuration, Spring on its own Baidu.
3. At this time you should be configured well Pom.xml (various dependencies and plug-ins), Web.xml, Beans.xml.
4. Write out the control layer:
@Controller
@RequestMapping ("mobile") public
class Mobileusercontroller {
@Autowired
private Mobileuserservice mus;
@ResponseBody
@RequestMapping ("login") Public
User Login (String mname,string mpassword) {
User U = Mus.login ("1", "2");//test data should be from the Android side
if (U!= null) {return
u;
}
return null;
}
}
Mus is the business layer that uses spring's dependency injection to retrieve the username and password from the database query and return the data. It is possible to return a Boolean, int, and so on, as long as you can judge. Because the user data will be used later, this will return the user object as JSON to the requesting side.
Use Responsebody need Jackson Rack Package:
<!--https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind-->
<dependency >
<groupId>com.fasterxml.jackson.core</groupId>
<artifactid>jackson-databind</ artifactid>
<version>2.8.3</version>
</dependency>
5. At this point the Android side accesses the LOCALHOST:8080/project name/mobile/login?mname= incoming username &mpassword= incoming password (default tomcat port 8080), If correct, the corresponding JSON data will be returned.
6.Android to get the JSON or NULL to judge it.
Android part