美文网首页
idea + kotlin + springboot + myb

idea + kotlin + springboot + myb

作者: Suncy | 来源:发表于2019-10-14 11:05 被阅读0次

1.项目结构

图片.png

2.配置

#数据库配置
spring.datasource.url=jdbc:mysql://localhost/my_shop?characterEncoding=utf-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root

mybatis.type-aliases-package=com.huaiwang.myshop.entity
mybatis.mapper-locations=classpath:mappers/**/*.xml
server.port=8088
图片.png
sql配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
       PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
       "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huaiwang.myshop.dao.UserDao">

   <!--id对应接口中的方法,名字要一样,parameterType是方法的参数类型,
   resultType是查询返回的类型,需要注意的是,这里的SQL语句后面不能加分号,变量不能加引号-->
<!--    <select id="getById" parameterType="int" resultType="com.example.springboot.demo.entity.User">-->
<!--        select * from user where id = #{id}-->
<!--    </select>-->

   <insert id="insert" parameterType="com.huaiwang.myshop.entity.User">
       insert into
       user(
           id,username,password
           )
       values(
           #{id},#{username},#{password}
       )
   </insert>

<!--   -->

<!--    <update id="updateUser" parameterType="com.example.springboot.demo.entity.User">-->
<!--        update user set name=#{name} where id = #{id}-->
<!--    </update>-->
<!--    <delete id="deleteAllUsers">-->
<!--        delete from user-->
<!--    </delete>-->
<!--    <delete id="deleteUser" parameterType="int">-->
<!--        delete from user where id = #{id}-->
<!--    </delete>-->
</mapper>

图片.png

pom文件,会自动生成的,后续需要什么再添加即可

项目启动配置:

@MapperScan("com.huaiwang.myshop.dao")
图片.png

3.各层级代码:

Dao:

图片.png

Service:

图片.png
图片.png

controller:

图片.png

4.启动项目:

图片.png

5.成功访问:

图片.png 图片.png

相关文章

网友评论

      本文标题:idea + kotlin + springboot + myb

      本文链接:https://www.haomeiwen.com/subject/rqolmctx.html