springboot整合mybatis,druid,thymeleaf,简洁易懂

话不多说,效果如下

简单用了Semantic UI

mapper.xml:sql语句如下,没有太复杂,是简单入门

<mapper namespace="nuc.edu.springboot01.dao.UserDao">
    <select id="findAll" parameterType="nuc.edu.springboot01.pojo.Query" resultType="nuc.edu.springboot01.pojo.Book">
        select *
        from book.book
    </select>
    <select id="findById" parameterType="integer" resultType="nuc.edu.springboot01.pojo.Book">
        select *
        from book.book where bookid =#{bookid}
    </select>
    <select id="findByIdName" resultType="nuc.edu.springboot01.pojo.Book">
        select *
        from book.book where bookid =#{param1} and bookname= #{param2}
    </select>
    <insert id="insertBook" parameterType="nuc.edu.springboot01.pojo.Book">
        Insert
        into book.book(bookid,bookname,bookprice) values (#{bookid},#{bookname},#{bookprice});
    </insert>
    <delete id="deleteById" parameterType="int">
        delete from  book.book where bookid = #{bookid}
    </delete>
</mapper>

表现层

@Controller
@Repository
public class UserController {
    @Autowired
    private Services services;
    @GetMapping("/")
    public String finaAll(Model model,Query query){
        PageInfo<Book>userPageInfo = services.findAll(query);
        model.addAttribute("page",userPageInfo);
        return "index";
    }
    @PostMapping("/findById")
    public String findById(Model model,Integer bookid){
        Book book1 = services.findById(bookid);
        model.addAttribute("book1", book1);
        return "indexId";
    }

    @PostMapping("/findByIdName")
    public String findByIdName(Model model,Integer bookid,String bookname){
        Book book2 = services.findByIdName(bookid,bookname);
        model.addAttribute("book2", book2);
        return "indexIdName";
    }
    @PostMapping("/insert")
    public String insetUser(RedirectAttributes attributes, Book book){
       boolean a = services.insertUser(book);
        if(a) {
            attributes.addFlashAttribute("message","添加图书成功");
            return "redirect:/";
        }else {
            attributes.addFlashAttribute("message","添加图书失败");
            return "redirect:/";
        }
    }

    @GetMapping("/insert1")
    public String toUpdate(Model model){
        Book book = new Book();
        model.addAttribute("book",book);
        return "insertbook";
    }
    @GetMapping("/delete/{bookid}")
    public String deleteById(@PathVariable("bookid") Integer bookid, RedirectAttributes attributes){
        boolean a =services.deleteById(bookid);
        if(a){
            attributes.addFlashAttribute("message","删除图书成功!");
            return "redirect:/";
        }else {
            attributes.addFlashAttribute("message","删除图书成功!");
            return "redirect:/";
        }
    }
}

前端运用了thymeleaf模板,采用了Semantic UI

例:

<tr th:each="book:${page.list}">
            <td th:text="${book.bookid}"></td>
            <td th:text="${book.bookname}"></td>
            <td th:text="${book.bookprice}"></td>
            <td>
                <a class="ui button mini blue" th:href="@{/delete/{bookid}(bookid=${book.bookid})}">删除</a>
                <a class="ui button mini blue">编辑</a>
            </td>
        </tr>

有问题欢迎私信,一起交流

 源码:springboot-01.rar-Java文档类资源-CSDN下载

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值