I am currently working on the mongodb-based spring Project architecture. I have a question to share with you, and I will be able to use it later. I will first look at a simple project architecture: in terms of architecture, the only thing that needs to be said is to use the spring annotation: Below is part of the code, part. * ** @ Authorjessonlv * user registration interface * @ Controller @ Request
I am currently working on the mongodb-based spring Project architecture. I have a question to share with you, and I will be able to use it later. I will first look at a simple project architecture: in terms of architecture, the only thing that needs to be said is to use the spring annotation: Below is part of the code, part. /*** @ Author jessonlv * user registration interface */@ Controller @ Request
I am currently working on the mongodb-based spring Project architecture. I have some questions to share with you, so that you can use it later.
First look at a simple project architecture:
In terms of architecture, the only thing that needs to be said is to use spring Annotations:
The following is part of the code.
/*** @ Author jessonlv * user registration interface */@ Controller @ RequestMapping ("/user ")Public class UserInfoController {@ Autowiredprivate UserInfoManager userManager; // interface documentation@ RequestMapping (method = RequestMethod. GET)Public String list (HttpServletRequest request, HttpServletResponse response) {response. setContentType ("text/html; charset = UTF-8"); return "user" ;}// check user information-based on account@ RequestMapping (value = "/check", method = RequestMethod. GET)Public String getUser (HttpServletRequest request, HttpServletResponse response) throws Exception {// set HTTP header response. setContentType ("text/html; charset = UTF-8"); // obtain the String account = StringUtil. formatStringParameter (request. getParameter ("account"), null); String key = StringUtil. formatStringParameter (request. getParameter ("key"), null); // verify the caller // verify the validity of the parameter if (account = null) {throw new ParameterException ();} // TODO: key verification // query object BasicDBObject o = new BasicDBObject ("account", account); try {// retrieve database DBObject doc = userManager. getUserInfo (o); // output result PrintWriter writer = response. getWriter (); writer. write (doc. toString ();} catch (Exception e) {e. printStackTrace (); // output result PrintWriter writer = response. getWriter (); writer. write (new BasicDBObject (). toString ();} // db. find (query ). skip (pos ). limit (pagesize) Paging return null ;}
The bold part is the annotation of spring. The interface we get is called like this: http: // localhost/ucenter/user/check? Account = 11 & pwd = 11111 note that it is a get request.
One of the biggest advantages of using mongodb is that you don't need to write beans, but you only need to do some simple configuration.
Let's look at the configuration of the spring-servlet.xml.
Classpath: appconfig. properties
The above are some general configurations. The most important part is the data source section.
// Data Source Address
// Port number
// Database Name
// Corresponding Representation
In fact, it is still the same as bean, which has been mapped in the early stage of project startup. Every time you write a dao, configure .... There are a lot of things left, and I am not used to it at the beginning. However, the efficiency is quite high and the structure is clear.
The output result of the interface is also very simple: DBObject myDocDbObject = userManager. getUserInfo (repeatAccount );
String str = myDocDbObject. toString (); is a json character.
Make a summary to make it easy to forget.