SpringBoot实战(SpringBoot中使用Java)读书笔记

本文介绍了一个基于SpringBoot和MyBatis的数据持久化案例,详细展示了实体类、持久层接口、Mapper配置文件及依赖配置,同时提供了服务层启动类和portal层的Controller实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

服务层的springboot应用

数据持久化
@Data
public class BConfWriteATO implements Serializable {
    private static final long serialVersionUID = -945748418279243242L;
    /**
     * 主键
     */
    private Long id;

    /**
     * 展示图片URL
     */
    private String linkImageUrl;
}

持久层接口
@Mapper
@Repository
public interface bConfMapper {
    /**
     * 删除
     * @param id
     * @return
     */
    int deleteByPrimaryKey(Long id);

    /**
     * 插入
     * @param record
     * @return
     */
    int insert(bConfDO record);

}
mybatis-config.xml配置扫描的mapper.xml文件配置的路径和别名

Mapper文件配置
  <insert id="insert" parameterType="com.dao.dbo.bConfDO" useGeneratedKeys="true" keyProperty="id">
    insert into b_conf (gmt_create, gmt_modified, related_knowledge_point_id,
      link_image_url, sort_no, version, 
      is_delete)
    values (now(), now(), #{relatedKnowledgePointId,jdbcType=BIGINT},
      #{linkImageUrl,jdbcType=VARCHAR}, #{sortNo,jdbcType=INTEGER}, 0,
      0)
  </insert>


数据持久层依赖
    <dependency>
		<groupId>com.aliexpress.boot</groupId>
		<artifactId>spring-boot-starter-mybatis</artifactId>
	</dependency>
	<dependency>
		<groupId>com.alibaba.boot</groupId>
		<artifactId>tddl-spring-boot-starter</artifactId>
	</dependency>
属性文件配置自定义配置
spring.mybatis.config=classpath:/mybatis-config.xml
spring.mybatis.scan-base-package=com.taotao.hui.na.ir.dao

服务层启动类
@SpringBootApplication
@EnableHSF
@EnableDiscoveryClient
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

portal层web SpringBoot应用
@Controller
public class KnowledgeManagerController extends WukongController {

  @ResponseBody
    @PostMapping("/knowledgemanager/saveBConf")
    public ResponseBaseBean<Object> saveBConf(HttpServletRequest request,
        @RequestBody BConfVO bConfVO) {
        ResponseBaseBean<Object> response = new ResponseBaseBean<>();
        try {
            BATO bato = BConfConvert.voToAto(bConfVO);
            BucSSOUser user = SimpleUserUtil.getBucSSOUser(request);
            beforeSave(user, bato);
            ResponseWrapper<Long> bannerResult = bConfFacade.save(bato);
            if (!bannerResult.isSucceeded()) {
                logger.error(
                    "call saveBConf bConfFacade.save error,"
                        + "result:{};writeATO:{}",
                    FastJsonTool.serialize(bannerResult), FastJsonTool.serialize(writeATO));
                throw new RuntimeException("saveBConf failed!");
            }
            return response;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            response.setSuccess(false);
            response.setMessage(e.getMessage());
            return response;
        }
    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

icool_ali

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值