Use MAVEN to build a simple Android landing based on spring, SPRINGMVC--server-side __android

Source: Internet
Author: User

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

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.