SpringBoot 开发笔记:使用SpringBoot 整合 SSM

SpringBoot 开发笔记:使用SpringBoot 整合 SSM


一、搭建过程
1、修改 pom.xml
1)Spring Boot的依赖
2)mybatis starter
	<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<!-- <version>3.5.0-SNAPSHOT</version> -->
			<version>1.3.1</version>
		</dependency>

2、准备 mybatis的 Mapper 和 Mapper.xml(如果使用注解,可以省略)

3、配置 spring 和 mybatis
application.yml

server: 
 port: 8089
 #context-path: /boot

spring: 
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.1.xx:3306/xxx2?useUnicode=true&amp;characterEncoding=UTF-8&amp;useServerPrepStmts=false&amp;rewriteBatchedStatements=true
    username: root
    password: xxx
  mvc: 
    view: 
      prefix: /
      suffix: .html
      
mybatis:
  mapper-locations: classpath*:mapper/*Mapper.xml

二、
1、数据表结构
DROP TABLE IF EXISTS `im_messageboard`;
CREATE TABLE `im_messageboard` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `content` varchar(255) DEFAULT NULL,
  `time` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of im_messageboard
-- ----------------------------
INSERT INTO `im_messageboard` VALUES ('1', '1', null);


1、MyBatis 的sql,写在 注解中好?还是写在xml好?
方式一、写在注解@Insert。。。

/**
 * DAO
 * @author live
 */
@Mapper
public interface MessageBoardMapper {
	
	MessageBoard getById(Integer id);
	
	List<MessageBoard> getAll();
	
    int deleteByPrimaryKey(Integer id);

    @Insert("insert into im_messageboard(id, content, time) values (#{id},#{content},#{time})")
    int save(MessageBoard record);
    
}

方式二、写在xml
<!-- 插入 -->
  <insert id="save2" parameterType="com.live.test.javaee.springboot.messageBoard.po.MessageBoard" useGeneratedKeys="true"	keyProperty="id">
		insert into im_messageboard (id, content, time)
		values (#{id,jdbcType=INTEGER},
		#{content,jdbcType=VARCHAR},
		#{time,jdbcType=VARCHAR})
	</insert>

遇到的问题:
1、Mapped Statements collection already contains value for com.live.test.javaee.springboot.messageBoard.mapper.MessageBoardMapper.save
xml 和 注解同时定义了mapper实现方法,冲突了。

更多请访问:
*我的github源代码地址: 
https://github.com/sunxiaoning90/com_live_test/tree/master/com_live_test_javaee/com_live_test_javaee_springbootSSM

*我的csdn地址:
https://blog.youkuaiyun.com/Sunxn1991/
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值