Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SSM+maven to realize the answer Management system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use SSM+maven to achieve the answer management system", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use SSM+maven to achieve answer management system" bar!

Recently, the project is quite busy, and then I get sick, so I don't have time to write a blog, QAQ. This time I brought an answer management system built by the SSM framework. I used the tp framework to build the answer management system, and this time I reconstructed it with the SSM framework.

# # 1. Pre-preparation of SSM architecture related knowledge (Spring+Springmvc+mybatis) bang assistance of IDEA/eclipse/myeclipse compiler layui documentation: layui development uses document default maven configuration Navicat/mysql workbench and other database visualization management tools

Create a maven project using IDEA

# # 2. Architecture Design (mvc)

First set the resources package to Resource Root and set the webapp package to the Web project directory

Specify the Web directory:

Specify the Spring profile directory:

The model layer uses mybatis for persistence processing and the mybatis generator plug-in for reverse engineering. The following configuration files are described: applicationContext:Springmvc configuration file

ApplicationContext-datasource.xml: database connection pool profile

Classpath:datasource.properties Dialect=mysql

Datasource.properties: database configuration fil

# location of the downloaded driver package db.driverLocation = C:/java/mysql-connector-java-5.1.41.jar# db.driverClassName = oracle.jdbc.driver.OracleDriverdb.driverClassName = com.mysql.jdbc.Driver# db.url=jdbc:mysql:// database IP: database Port/database?characterEncoding=utf-8db.url = jdbc:mysql://xxxx:3306/tp5?characterEncoding=utf-8db.username = XXXdb.password = XXXXXdb.initialSize = 20db.maxActive = 50db.maxIdle = 20db.minIdle = 10db.maxWait = 10db.defaultAutoCommit = truedb.minEvictableIdleTimeMillis = 3600000

Configuration files for generatorConfig.xml:mybatis generator reverse engineering

Then under the controller package, the corresponding controller dao package is the reverse generated DAO data layer pojo package is the reverse generated entity class service is the business layer we wrote util is our tool class

Finally, our database design: since it is an answer management system. # one set of questions (i.e. one template) (model table) corresponds to multiple questions (qsn table) # one question (qsn table) corresponds to multiple answers (detail table)

Then the Navicat table is designed as follows: model table: (tweak _ is the prefix rmkX is an alternate field)

Qsn table: (I didn't set the foreign key here. In fact, the model_id of the qsn table should set the foreign key.)

Detail table: (ibid.)

Now that we have said so much, we are finally ready to officially enter our development.

# # 3. The goal of this chapter is # corresponding to the thinkphp implementation of the answer management system, we still implement the model table first (the implementation of the additional function module of the answer template)

# # 4. View layer implementation (Jquery+layui)

The first step is to add the View layer implementation of the template.

The button that refers to the button group style of layui and id is btn-add is the add template button.

Click add template and we use Jquery to set the pop-up layer id of a layui to set-add-put

/ / pop-up add window $('# btn-add') .click (function () {layer.open ({type: 1, skin: 'layui-layer-rim', / / with a border area: [' 660px, '350px'] / / width and height content: $('# set-add-put'), title: "add template"}) })

As follows

There are three input boxes that correspond to the create_name,time,name of the database.

Creator name creation time template name Add reset now

Then, our data click the add now button, id is add. We use Jquery to make an ajax request for it.

/ / add data $('# add') .click (function () {var create_name = $('input [name = "create_name"]') .val (); / / get the value var name= $('input [name = "name"]') .val (); var time = $('input [name = "time"]') .val () If (create_name! = ='') {/ / Open the eject layer layer.msg ('loading', {icon: 16, shade: 0.01, time: '9999999'}) Var url = "survey/add_model" / / the url here is different from the route of tp5 var data = {create_name: create_name, name: name, time: time} $.post (url, data) Function (data) {/ / use ajax to submit layer.closeAll () If (data.code = = 1) {/ / the code here corresponds to the returned status code layer.msg (data.msg, {icon: 6}); location.reload () } else {layer.msg (data.msg, {icon: 5});}, "json");})

The submitted data is the three values we got in the input box, create_name,name,time. Submit to the Controller layer, if the returned data status code is 1 that represents success, the entire page will be refreshed, otherwise, an error will be prompted.

Then let's look at the code of the Controller layer.

# # 5. Controller layer implementation first I defined an Api class under the util package to store our utility class, which is mainly used to return json data to the front end

Package com.sl.example.util;import java.util.HashMap;import java.util.List;import java.util.Map;//code=1 success 2 fail 3 warningpublic class Api {public Map returnJson (int code,String msg) {Map map=new HashMap (); map.put ("code", code); map.put ("msg", msg); return map;} public Map returnJson (int code,String msg, List data) {Map map=new HashMap () Map.put ("code", code); map.put ("msg", msg); map.put ("data", data); return map;} public Map returnJson (int code, String msg, Map data) {Map map=new HashMap (); map.put ("code", code); map.put ("msg", msg); map.put ("data", data) Return map;}}

The returned data overload is optional. The three are the code status code, msg information, and the data returned by data. The two are code status code and msg information.

Then the corresponding controller layer code

/ / add model @ RequestMapping (value= "Index/survey/add_model") @ ResponseBody public Map addModel (HttpServletRequest req) throws IOException {String name = req.getParameter ("name"); String createName=req.getParameter ("createName"); String strtime=req.getParameter ("time"); / / with comments, convert if (createName==null) {return api.returnJson (3, "warning") by default } UUID uuid=UUID.randomUUID (); String modelId=uuid.toString (); Model model=new Model (); Date time=string2Date.DateChange (strtime); model.setCreateName (createName); model.setName (name); model.setTime (time); model.setModelId (modelId); int is_add=modelService.InsertModel (model) If (isometric addenda success0) {return api.returnJson (1, "add successful");} else {return api.returnJson (2, "add failed");}}

UUID is used to create a relatively unique template ID. Call the InsertModel method of the modelService layer and pass in the model object to add the template.

# # 6. Service layer implementation: ModelService.java

Package com.sl.example.service;import com.sl.example.pojo.Model;import java.util.List;public interface ModelService {public List findAllModel (); public int deleteModelById (String modelId); public int deleteModelByIds (String [] arr); public int InsertModel (Model model); public Model selectModelById (String modelId);}

ModelService.Impl:

Package com.sl.example.service;import com.sl.example.pojo.Model;import java.util.List;public interface ModelService {public List findAllModel (); public int deleteModelById (String modelId); public int deleteModelByIds (String [] arr); public int InsertModel (Model model); public Model selectModelById (String modelId);}

# # 7. A list of functions, and then let's check to see if our functions have been implemented.

Thank you for reading, the above is the content of "how to use SSM+maven to achieve the answer management system". After the study of this article, I believe you have a deeper understanding of how to use SSM+maven to achieve the answer management system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report