Get the App
SLTechnology News&Howtos  ›  Database  › 

Springmvc+spring+mybatis+mysql configuration process

Shulou Source: shulou.com Published: 2022-06-01 21:11:07 09月26日 Update

Environment: eclipse

Project catalog:

Jar package:

Web.xml

Archetype Created Web ApplicationcontextConfigLocationclasspath:hanxuanyuan/config/spring-mybatis.xmlencodingFilterorg.springframework.web.filter.CharacterEncodingFiltertrueencodingUTF-8encodingFilter/*org.springframework.web.context.ContextLoaderListenerorg.springframework.web.util.IntrospectorCleanupListenerSpringMVCorg.springframework.web.servlet.DispatcherServletcontextConfigLocationclasspath:hanxuanyuan/config/spring-mvc.xml1trueSpringMVC//index.jsp

Spring-mybatis.xml

Jdbc.properties

Driver=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost/cecusername=rootpassword=root#\ u5B9A\ u4E49\ u521D\ u59CB\ u8FDE\ u63A5\ u6570initialSize=0#\ u5B9A\ u4E49\ u6700\ u5927\ u8FDE\ u63A5\ u6570maxActive=20#\ u5B9A\ u4E49\ u6700\ u5927\ u7A7A\ u95F2maxIdle=20#\ u5B9A\ u4E49\ u6700\ u5C0F\ u7A7A\ u95F2minIdle=1#\ u5B9A\ u4E49\ u6700\ u957F\ u7B49\ u5F85\ u65F6\ u95F4maxWait=60000

Log4j.properties

#\ u5B9A\ u4E49LOG\ u8F93\ u51FA\ u7EA7\ u522Blog4j.rootLoggerInfofoForceConsol File#\ u5B9A\ u4E49\ u65E5\ u5FD7\ u8F93\ u51FA\ u76EE\ u7684\ u5730\ u4E3A\ u63A7\ u5236\ u53F0log4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Target=System.out#\ u53EF\ u4EE5\ u7075\ u6D3B\ u6307\ u5B9A\ u65E5\ u5FD7\ u51FA\ u683C\ u5F0F\ uFF0C\ u4E0B\ u9762\ u4E00\ u884C\ u662F\ u6307\ u5B9A\ u5177\ u4F53\ u7684\ u683C\ u5F0Flog4j.appender.Console.layout = org.apache.log4j.PatternLayoutlog4j.appender.Console.layout. ConversionPattern= [% c] -% m%n#\ u6587\ u4EF6\ u5927\ u5230\ u8FBE\ u6307\ u5B9A\ u5C3A\ u5BF8\ u7684\ u65F6\ u5019\ u4EA7\ u751F\ u4E00\ u4E2A\ u65B0\ u7684\ u4EF6log4j.appender.File = org.apache.log4j.RollingFileAppender#\ u6307\ u5B9A\ u8F93\ u51FA\ u76EE\ u5F55log4j.appender.File.File = logs/ssm.log#\ u5B9A\ u4E49\ u6587\ u4EF6\ u5927\ u5927\ u5C0Flog4j.appender.File.MaxFileSize = 10MB#\ U8F93\ u51FA\ u6240\ u4EE5\ u65E5\ u5FD7\ uFF0C\ u5982\ u679C\ u6362\ u6210DEBUG\ u8868\ u793A\ u8F93\ u4EE5\ u4E0A\ u7EA7\ u522B\ u65E5\ u5FD7log4j.appender.File.Threshold = ALLlog4j.appender.File.layout = org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern = [% p] [% d {yyyy-MM-dd HH\: mm\: ss}] [% c]% m% n

UserController.java

Package hanxuanyuan.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import hanxuanyuan.domain.User;import hanxuanyuan.service.UserService;@Controller@RequestMapping ("/ user") public class UserController {@ Resourceprivate UserService userService;@RequestMapping ("/ showUser") public String showUser (Model model) {User user = userService.selectByPrimaryKey ("1"); model.addAttribute ("user", user); return "welcome";}}

UserService.java

Package hanxuanyuan.service;import hanxuanyuan.domain.User;public interface UserService {void insert (User record); User selectByPrimaryKey (String id);}

UserServiceImpl.java

Package hanxuanyuan.service;import javax.annotation.Resource;import org.springframework.stereotype.Service;import hanxuanyuan.dao.UserMapper;import hanxuanyuan.domain.User;@Service ("userService") public class UserServiceImpl implements UserService {@ Resourceprivate UserMapper userMapper; @ Overridepublic void insert (User record) {userMapper.insert (record);} @ Overridepublic User selectByPrimaryKey (String id) {return userMapper.selectByPrimaryKey (id);}}

UserMapper.java

Package hanxuanyuan.dao;import hanxuanyuan.domain.User;public interface UserMapper {int deleteByPrimaryKey (String id); int insert (User record); int insertSelective (User record); User selectByPrimaryKey (String id); int updateByPrimaryKeySelective (User record); int updateByPrimaryKey (User record);}

UserMapper.xml

Id, username, password, age, role select from user where id = # {id,jdbcType=VARCHAR} delete from user where id = # {id,jdbcType=VARCHAR} insert into user (id, username, password, age, role) values (# {id,jdbcType=VARCHAR}, # {username,jdbcType=VARCHAR}, # {password,jdbcType=VARCHAR}, # {age,jdbcType=VARCHAR}, # {role,jdbcType=VARCHAR}) insert into user id Username, password, age, role, # {id,jdbcType=VARCHAR}, # {username,jdbcType=VARCHAR}, # {password,jdbcType=VARCHAR}, # {age,jdbcType=VARCHAR} # {role,jdbcType=VARCHAR}, update user username = # {username,jdbcType=VARCHAR}, password = # {password,jdbcType=VARCHAR}, age = # {age,jdbcType=VARCHAR}, role = # {role,jdbcType=VARCHAR}, where id = # {id,jdbcType=VARCHAR} update user set username = # {username JdbcType=VARCHAR}, password = # {password,jdbcType=VARCHAR}, age = # {age,jdbcType=VARCHAR}, role = # {role,jdbcType=VARCHAR} where id = # {id,jdbcType=VARCHAR}

UserMapper,User,UserMapper.xml these three files are automatically generated by mybatis-generator, http://pan.baidu.com/s/1cvQWsY

How to use it: (1) Open the dos command window, enter the directory, and after configuring generatorConfig.xml, run the command:

Java-jar mybatis-generator-core-1.3.2.jar-configfile generatorConfig.xml-overwrite

(2) copy the file to the corresponding location of the project

Jar package link: http://down.51cto.com/data/2302826

Project source link: http://pan.baidu.com/s/1o7H6WUu

It is not recommended that you look at the source code directly. Refer to the above code and see if you can build it yourself.

Tags: Project command file source code directory link configuration three code location usage copy method environment automatic generation reference recommendation build run process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Xiaomi Apple Shulou Technology