Using Spring-data-mongodb to manipulate MongoDB

Source: Internet
Author: User

Mongodb.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:mongo= "Http://www.springframework.org/schema/data/mongo"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/ Spring-mongo.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd ">    <Context:property-placeholder Location= "Classpath*:mongodb.properties"  />    <!--username= "${mongo.username}" -    <!--password= "${database.password}" -    <mongo:db-factoryID= "Mongodbfactory"Host= "${mongo.host}"Port= "${mongo.port}"dbname= "${mongo.dbname}"    />    <BeanID= "Mongotemplate"class= "Org.springframework.data.mongodb.core.MongoTemplate">        <Constructor-argname= "Mongodbfactory"ref= "Mongodbfactory"/>    </Bean></Beans>

Mongodb.properties

Mongo.host=127.0.0.1mongo.port=27017mongo.dbname=test#mongo.username= #database. password=

Test methods for manipulating MongoDB

@ResourceMongoOperations mongooperations; @Test  Public void Testmongodb () {    new  User ();    User.setname ("Testmongodb");    User.setage ();    " CollectionName ");     = Mongooperations.findone (new Query (Criteria.where ("name"). Is ("Testmongodb")), User.  Class, "CollectionName");    System.out.println (Usergetfrommdb);}

Using Spring-data-mongodb to manipulate MongoDB

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.