Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:57:07+00:00 2026-06-10T17:57:07+00:00

I am using spring mvc3 now,and I found that most of my controller own

  • 0

I am using spring mvc3 now,and I found that most of my controller own the same logic. For exmaple:

PostController:

package com.king.controller;

@Controller
@RequestMapping("/posts")
public class PostController {
    @Autowired
    private PostDao postDao;

    // GET /posts /posts.json
    @RequestMapping(value = { "" }, method = RequestMethod.GET)
    public String index(Model model) {
        model.addAttribute("posts", postDao.list());
        return "posts/index";
    }

    // GET /posts/1 GET /posts/1.json
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String show(@PathVariable int id, Model model) {
        Post post = postDao.query(id);
        if (post != null) {
            model.addAttribute("post", post);
            return "posts/show";
        } else
            throw new RuntimeException("not found");

    }

    // GET /posts/new
    @RequestMapping(value = "/new", method = RequestMethod.GET)
    public String newForm(Model model) {
        model.addAttribute(new Post());
        return "posts/new";
    }

    // GET /posts/1/edit
    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    public String edit(@PathVariable int id, Model model) {
        Post post = postDao.query(id);
        if (post != null) {
            model.addAttribute(post);
            return "posts/edit";
        } else
            throw new RuntimeException("not found");
    }

    // POST /posts /posts.json
    @RequestMapping(value = "", method = RequestMethod.POST)
    public String create(@Valid Post post, BindingResult result) {
        if (!result.hasErrors()) {
            postDao.add(post);
            return "redirect:/posts";
        } else {
            return "posts/new";
        }
    }

    // PUT /posts/1 /posts/1.json
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public String update(@PathVariable int id, @Valid Post post, BindingResult result, RedirectAttributes redirectAttrs) {
        if (!result.hasErrors()) {
            post.setId(id);
            postDao.update(post);
            return "redirect:/posts/" + id;
        } else {
            return "posts/edit";
        }
    }

    // DELETE /posts/1 /posts/1.json
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String destroy(@PathVariable int id, RedirectAttributes re) {
        Post p = new Post(id, "", "");
        postDao.delete(p);
        return "redirect:/posts";
    }
}

If I create a new simple model which need the curd operation,I will have to create a new controller,a new dao which is copy-paste manually.

So I wonder if I can find or create a tool which can generate controller and dao and etc accordingly like rails does?

Is there any tool I can use out-of-box? If not,I can create it,however by now,I just thought that if I have to create this kind of tool,I may just do something character replacement,that’s to say,create a public template for controller and dao,then replace something accordingly,but I wonder how to handle the package/import/ problem,and which language is better (java or ruby)?

BTW,please do not recommend play!framework for me. I do not like it. Since I just want to use spring mvc. So the tool will only focus on controller and dao based on spring 3.

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:57:09+00:00Added an answer on June 10, 2026 at 5:57 pm

    Grails certainly provides this type of functionality out of the box, while I believe Spring Roo also does this for you. It’s worth checking both out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring MVC with Hibernate. My page has a button that creates
I am using JSPs for the view, and Spring MVC 3.0 for the controller.
I have a controller POST action that redirects to a GET method using RedirectToAction.
We have a Spring web application created using Spring MVC 3.0 In the same
I am creating a demo application using Spring mvc 3.0.Now i wants to connect
First, let me explain that I'm using Spring MVC 3.1.1, and Hibernate validation 4.2.0.
I have one application using MVC3 w/ Razor that has been working perfectly working
I am using Spring MVC 3.1.x with Tiles 2.2.2 (bootstrapped project with Roo) and
I am using spring MVC 3.0 with the jqgrid plugin. I am building the
I'm validating a form using the Validator interface with Spring MVC 3.0.2 using SimpleFormController

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.